updates
This commit is contained in:
+378
-494
File diff suppressed because it is too large
Load Diff
@@ -158,6 +158,7 @@ using (var scope = app.Services.CreateScope())
|
|||||||
{
|
{
|
||||||
var factory = scope.ServiceProvider.GetRequiredService<IDbContextFactory<TimetrackerDbContext>>();
|
var factory = scope.ServiceProvider.GetRequiredService<IDbContextFactory<TimetrackerDbContext>>();
|
||||||
await using var db = await factory.CreateDbContextAsync();
|
await using var db = await factory.CreateDbContextAsync();
|
||||||
|
var databaseCreatedFromModel = false;
|
||||||
|
|
||||||
if (dbProvider.Equals("PostgreSQL", StringComparison.OrdinalIgnoreCase))
|
if (dbProvider.Equals("PostgreSQL", StringComparison.OrdinalIgnoreCase))
|
||||||
{
|
{
|
||||||
@@ -169,6 +170,24 @@ using (var scope = app.Services.CreateScope())
|
|||||||
await conn.OpenAsync();
|
await conn.OpenAsync();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
using (var cmdCheckTables = conn.CreateCommand())
|
||||||
|
{
|
||||||
|
cmdCheckTables.CommandText = @"
|
||||||
|
SELECT COUNT(*)
|
||||||
|
FROM information_schema.tables
|
||||||
|
WHERE table_schema = 'public'
|
||||||
|
AND table_name <> '__EFMigrationsHistory';";
|
||||||
|
var existingTableCount = Convert.ToInt32(await cmdCheckTables.ExecuteScalarAsync() ?? 0);
|
||||||
|
if (existingTableCount == 0)
|
||||||
|
{
|
||||||
|
await db.Database.EnsureCreatedAsync();
|
||||||
|
databaseCreatedFromModel = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!databaseCreatedFromModel)
|
||||||
|
{
|
||||||
|
|
||||||
// Check if AppSettings table already exists
|
// Check if AppSettings table already exists
|
||||||
using (var cmdCheck = conn.CreateCommand())
|
using (var cmdCheck = conn.CreateCommand())
|
||||||
{
|
{
|
||||||
@@ -213,15 +232,19 @@ using (var scope = app.Services.CreateScope())
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
Console.WriteLine($"Fehler beim Vorbereiten der PostgreSQL Migrationshistorie: {ex.Message}");
|
Console.WriteLine($"Fehler beim Vorbereiten der PostgreSQL Migrationshistorie: {ex.Message}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!databaseCreatedFromModel)
|
||||||
|
{
|
||||||
await db.Database.MigrateAsync();
|
await db.Database.MigrateAsync();
|
||||||
|
}
|
||||||
|
|
||||||
if (dbProvider.Equals("PostgreSQL", StringComparison.OrdinalIgnoreCase))
|
if (dbProvider.Equals("PostgreSQL", StringComparison.OrdinalIgnoreCase) && !databaseCreatedFromModel)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user