Skip to content

Commit

Permalink
Fix startup migration
Browse files Browse the repository at this point in the history
  • Loading branch information
patrickklaeren committed Nov 11, 2023
1 parent 31d1252 commit 70e933e
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 11 deletions.
1 change: 1 addition & 0 deletions src/Accord.Domain/Accord.Domain.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="7.0.13" />
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="7.0.11" />
</ItemGroup>

Expand Down
8 changes: 7 additions & 1 deletion src/Accord.Domain/AccordContextExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Microsoft.EntityFrameworkCore;
using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection;

namespace Accord.Domain;
Expand All @@ -9,4 +10,9 @@ public static IServiceCollection AddDatabase(this IServiceCollection collection,
{
return collection.AddDbContext<AccordContext>(x => x.UseNpgsql(connectionString));
}

public static async Task Migrate(AccordContext context)
{
await context.Database.MigrateAsync();
}
}
1 change: 0 additions & 1 deletion src/Accord.Web/Accord.Web.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
<PackageReference Include="MediatR" Version="11.1.0" />
<PackageReference Include="MediatR.Extensions.Microsoft.DependencyInjection" Version="11.0.0" />
<PackageReference Include="MudBlazor" Version="6.1.2" />
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="7.0.11" />
<PackageReference Include="Sentry.Serilog" Version="3.23.1" />
<PackageReference Include="Serilog" Version="2.12.1-dev-01587" />
<PackageReference Include="Serilog.AspNetCore" Version="6.0.1" />
Expand Down
10 changes: 1 addition & 9 deletions src/Accord.Web/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -101,15 +101,7 @@
using (var scope = app.Services.CreateScope())
{
Log.Information("Scope created...");

var services = scope.ServiceProvider;

await using var db = services.GetRequiredService<AccordContext>();

Log.Information("Got Db context");

await db.Database.MigrateAsync();

await AccordContextExtensions.Migrate(scope.ServiceProvider.GetRequiredService<AccordContext>());
Log.Information("Migrated!");
}

Expand Down

0 comments on commit 70e933e

Please sign in to comment.