mirror of
https://github.com/zoriya/Kyoo.git
synced 2025-05-24 02:02:36 -04:00
Fix dotnet ef design time context
This commit is contained in:
parent
f64cf161ab
commit
de2308f319
@ -1,2 +1,2 @@
|
||||
--project
|
||||
src/Kyoo.Core
|
||||
src/Kyoo.Postgresql
|
||||
|
@ -28,7 +28,9 @@ using Kyoo.Postgresql.Utils;
|
||||
using Kyoo.Utils;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Design;
|
||||
using Microsoft.EntityFrameworkCore.Query.SqlExpressions;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Npgsql;
|
||||
|
||||
namespace Kyoo.Postgresql;
|
||||
@ -121,3 +123,15 @@ public class PostgresContext(DbContextOptions options, IHttpContextAccessor acce
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
public class PostgresContextBuilder : IDesignTimeDbContextFactory<PostgresContext>
|
||||
{
|
||||
public PostgresContext CreateDbContext(string[] args)
|
||||
{
|
||||
NpgsqlDataSource dataSource = PostgresModule.CreateDataSource(new ConfigurationManager());
|
||||
DbContextOptionsBuilder builder = new();
|
||||
builder.UseNpgsql(dataSource);
|
||||
|
||||
return new PostgresContext(builder.Options, null!);
|
||||
}
|
||||
}
|
||||
|
@ -30,16 +30,16 @@ namespace Kyoo.Postgresql;
|
||||
|
||||
public static class PostgresModule
|
||||
{
|
||||
public static void ConfigurePostgres(this WebApplicationBuilder builder)
|
||||
public static NpgsqlDataSource CreateDataSource(IConfiguration configuration)
|
||||
{
|
||||
DbConnectionStringBuilder conBuilder =
|
||||
new()
|
||||
{
|
||||
["USER ID"] = builder.Configuration.GetValue("POSTGRES_USER", "KyooUser"),
|
||||
["PASSWORD"] = builder.Configuration.GetValue("POSTGRES_PASSWORD", "KyooPassword"),
|
||||
["SERVER"] = builder.Configuration.GetValue("POSTGRES_SERVER", "db"),
|
||||
["PORT"] = builder.Configuration.GetValue("POSTGRES_PORT", "5432"),
|
||||
["DATABASE"] = builder.Configuration.GetValue("POSTGRES_DB", "kyooDB"),
|
||||
["USER ID"] = configuration.GetValue("POSTGRES_USER", "KyooUser"),
|
||||
["PASSWORD"] = configuration.GetValue("POSTGRES_PASSWORD", "KyooPassword"),
|
||||
["SERVER"] = configuration.GetValue("POSTGRES_SERVER", "db"),
|
||||
["PORT"] = configuration.GetValue("POSTGRES_PORT", "5432"),
|
||||
["DATABASE"] = configuration.GetValue("POSTGRES_DB", "kyooDB"),
|
||||
["POOLING"] = "true",
|
||||
["MAXPOOLSIZE"] = "95",
|
||||
["TIMEOUT"] = "30"
|
||||
@ -49,7 +49,12 @@ public static class PostgresModule
|
||||
dsBuilder.MapEnum<Status>();
|
||||
dsBuilder.MapEnum<Genre>();
|
||||
dsBuilder.MapEnum<WatchStatus>();
|
||||
NpgsqlDataSource dataSource = dsBuilder.Build();
|
||||
return dsBuilder.Build();
|
||||
}
|
||||
|
||||
public static void ConfigurePostgres(this WebApplicationBuilder builder)
|
||||
{
|
||||
NpgsqlDataSource dataSource = CreateDataSource(builder.Configuration);
|
||||
|
||||
builder.Services.AddDbContext<DatabaseContext, PostgresContext>(
|
||||
x =>
|
||||
|
Loading…
x
Reference in New Issue
Block a user