Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions BervProject.WebApi.Boilerplate/Data/DesignTimeDbContextFactory.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using BervProject.WebApi.Boilerplate.EntityFramework;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Design;
using Microsoft.Extensions.Configuration;
using System;
using System.IO;

namespace BervProject.WebApi.Boilerplate.Data;

public class DesignTimeDbContextFactory : IDesignTimeDbContextFactory<BoilerplateDbContext>
{
public BoilerplateDbContext CreateDbContext(string[] args)
{
var configuration = new ConfigurationBuilder()
.SetBasePath(Directory.GetCurrentDirectory())
.AddJsonFile("appsettings.json")
.Build();

var optionsBuilder = new DbContextOptionsBuilder<BoilerplateDbContext>();
optionsBuilder.UseNpgsql(configuration.GetConnectionString("BoilerplateConnectionString"));

return new BoilerplateDbContext(optionsBuilder.Options);
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using BervProject.WebApi.Boilerplate.Entities;
using System;
using BervProject.WebApi.Boilerplate.Entities;
using Microsoft.EntityFrameworkCore;

namespace BervProject.WebApi.Boilerplate.EntityFramework
Expand Down Expand Up @@ -34,6 +35,22 @@

}

/// <summary>
/// Configure DbContext for migrations
/// </summary>
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
if (!optionsBuilder.IsConfigured)
{
var connectionString = Environment.GetEnvironmentVariable("ConnectionStrings__BoilerplateConnectionString");
if (string.IsNullOrEmpty(connectionString))
{
connectionString = "Host=localhost;Database=testdb;Username=postgres;Password=postgres";

Check warning on line 48 in BervProject.WebApi.Boilerplate/EntityFramework/BoilerplateDbContext.cs

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

"password" detected here, make sure this is not a hard-coded credential.

See more on https://sonarcloud.io/project/issues?id=bervProject_NET-Core-API-Boilerplate&issues=AZ29QvsBGlqvaGIkpUnb&open=AZ29QvsBGlqvaGIkpUnb&pullRequest=3179

Check warning

Code scanning / SonarCloud

Credentials should not be hard-coded Medium

"password" detected here, make sure this is not a hard-coded credential. See more on SonarQube Cloud
}
optionsBuilder.UseNpgsql(connectionString);
}
}

/// <summary>
/// Adding relationship
/// </summary>
Expand Down
Loading