Files
tiku-backend.net/Tiku.DbMigrator/DesignTimeTikuDbContextFactory.cs

23 lines
760 B
C#

using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Design;
using Tiku.Infrastructure.Persistence;
namespace Tiku.DbMigrator;
public sealed class DesignTimeTikuDbContextFactory : IDesignTimeDbContextFactory<TikuDbContext>
{
public TikuDbContext CreateDbContext(string[] args)
{
var connectionString =
Environment.GetEnvironmentVariable("DATABASE_URL") ??
$"Host=localhost;Database=tiku;Username={Environment.UserName}";
var options = new DbContextOptionsBuilder<TikuDbContext>()
.UseNpgsql(connectionString, npgsql =>
npgsql.MigrationsAssembly(typeof(TikuDbContext).Assembly.FullName))
.Options;
return new TikuDbContext(options);
}
}