Fix DbContext configuration nightmares.
Thanks to julian figuring out IDesignTimeDbContextFactory exists in #6327. All this DbContext configuration and options setup stuff is insane. Microsoft should be absolutely ashamed for coming up with this load of garbage.
This commit is contained in:
25
Content.Server.Database/DesignTimeContextFactories.cs
Normal file
25
Content.Server.Database/DesignTimeContextFactories.cs
Normal file
@@ -0,0 +1,25 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Design;
|
||||
// ReSharper disable UnusedType.Global
|
||||
|
||||
namespace Content.Server.Database;
|
||||
|
||||
public sealed class DesignTimeContextFactoryPostgres : IDesignTimeDbContextFactory<PostgresServerDbContext>
|
||||
{
|
||||
public PostgresServerDbContext CreateDbContext(string[] args)
|
||||
{
|
||||
var optionsBuilder = new DbContextOptionsBuilder<PostgresServerDbContext>();
|
||||
optionsBuilder.UseNpgsql(args[0]);
|
||||
return new PostgresServerDbContext(optionsBuilder.Options);
|
||||
}
|
||||
}
|
||||
|
||||
public sealed class DesignTimeContextFactorySqlite : IDesignTimeDbContextFactory<SqliteServerDbContext>
|
||||
{
|
||||
public SqliteServerDbContext CreateDbContext(string[] args)
|
||||
{
|
||||
var optionsBuilder = new DbContextOptionsBuilder<SqliteServerDbContext>();
|
||||
optionsBuilder.UseSqlite(args[0]);
|
||||
return new SqliteServerDbContext(optionsBuilder.Options);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user