2024-11-26 15:07:18 +05:00
|
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
using Microsoft.EntityFrameworkCore.Design;
|
|
|
|
using Npgsql;
|
2024-12-16 15:38:46 +05:00
|
|
|
using DD.Persistence.Database.Model;
|
2024-11-26 15:07:18 +05:00
|
|
|
|
2024-12-16 15:38:46 +05:00
|
|
|
namespace DD.Persistence.Database.Postgres;
|
2024-11-26 15:07:18 +05:00
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Фабрика контекста для dotnet ef миграций
|
|
|
|
/// </summary>
|
|
|
|
public class DesignTimeDbContextFactory : IDesignTimeDbContextFactory<PersistencePostgresContext>
|
|
|
|
{
|
|
|
|
public PersistencePostgresContext CreateDbContext(string[] args)
|
|
|
|
{
|
2024-12-12 16:56:25 +05:00
|
|
|
var connectionStringBuilder = new NpgsqlConnectionStringBuilder
|
|
|
|
{
|
|
|
|
Host = "localhost",
|
|
|
|
Database = "persistence",
|
|
|
|
Username = "postgres",
|
|
|
|
Password = "q",
|
|
|
|
PersistSecurityInfo = true
|
|
|
|
};
|
2024-11-26 15:07:18 +05:00
|
|
|
var connectionString = connectionStringBuilder.ToString();
|
|
|
|
|
|
|
|
var optionsBuilder = new DbContextOptionsBuilder<PersistencePostgresContext>();
|
|
|
|
optionsBuilder.UseNpgsql(connectionString);
|
|
|
|
var context = new PersistencePostgresContext(optionsBuilder.Options);
|
|
|
|
return context;
|
|
|
|
}
|
|
|
|
}
|