Files
tiku-backend.net/Tiku.DbMigrator/DesignTimeTikuDbContextFactory.cs
xiong c497a3ca8d
Some checks failed
ci / release-gate (push) Has been cancelled
清理代码
2026-08-03 12:31:39 +08:00

25 lines
942 B
C#

using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Design;
using Tiku.Application.Security;
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;
var tenantContext = new TenantContext();
tenantContext.InitializeSystem(null, "EF Core design-time model generation");
return new TikuDbContext(options, tenantContext);
}
}