27 lines
1.0 KiB
C#
27 lines
1.0 KiB
C#
using Microsoft.EntityFrameworkCore;
|
|
using ControlCenter.Api.Entities;
|
|
|
|
namespace ControlCenter.Api.Data;
|
|
|
|
/// <summary>
|
|
/// Design-time factory for AppDbContext, used by EF Core tools (dotnet ef)
|
|
/// to create migrations without requiring a running application.
|
|
/// </summary>
|
|
public class AppDbContextFactory : Microsoft.EntityFrameworkCore.Design.IDesignTimeDbContextFactory<AppDbContext>
|
|
{
|
|
public AppDbContext CreateDbContext(string[] args)
|
|
{
|
|
var optionsBuilder = new DbContextOptionsBuilder<AppDbContext>();
|
|
|
|
// Connection string for design-time operations (migrations).
|
|
// In production, this comes from appsettings / environment variables.
|
|
var connectionString = "Host=localhost;Database=control_center;Username=postgres;Password=postgres";
|
|
|
|
optionsBuilder.UseNpgsql(connectionString, npgsqlOptions =>
|
|
{
|
|
npgsqlOptions.MigrationsAssembly(typeof(AppDbContext).Assembly.FullName);
|
|
});
|
|
|
|
return new AppDbContext(optionsBuilder.Options);
|
|
}
|
|
} |