Add migrations and startup scripts
This commit is contained in:
@@ -7,7 +7,11 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="9.0.0"/>
|
||||
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="9.0.0" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="9.0.4">
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
</PackageReference>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
@@ -7,7 +7,7 @@ using Printbase.Infrastructure.Repositories;
|
||||
|
||||
namespace Printbase.WebApi;
|
||||
|
||||
public class Startup
|
||||
public static class Startup
|
||||
{
|
||||
public static void ConfigureServices(WebApplicationBuilder builder)
|
||||
{
|
||||
@@ -32,6 +32,22 @@ public class Startup
|
||||
|
||||
public static void Configure(IApplicationBuilder app, IWebHostEnvironment env)
|
||||
{
|
||||
if (app is WebApplication application)
|
||||
{
|
||||
using var scope = application.Services.CreateScope();
|
||||
var dbContext = scope.ServiceProvider.GetRequiredService<ApplicationDbContext>();
|
||||
try
|
||||
{
|
||||
dbContext.Database.Migrate();
|
||||
Console.WriteLine("Database migrations applied successfully");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine($"An error occurred while applying migrations: {ex.Message}");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (env.IsDevelopment())
|
||||
{
|
||||
app.UseDeveloperExceptionPage();
|
||||
|
||||
@@ -4,5 +4,11 @@
|
||||
"Default": "Information",
|
||||
"Microsoft.AspNetCore": "Warning"
|
||||
}
|
||||
},
|
||||
"ConnectionStrings": {
|
||||
"DefaultConnection": "Server=localhost,${SQL_PORT};Database=PrintbaseDb;User Id=sa;Password=${SA_PASSWORD};TrustServerCertificate=True;"
|
||||
},
|
||||
"DatabaseOptions": {
|
||||
"ApplyMigrationsAtStartup": true
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -5,5 +5,10 @@
|
||||
"Microsoft.AspNetCore": "Warning"
|
||||
}
|
||||
},
|
||||
"AllowedHosts": "*"
|
||||
}
|
||||
"ConnectionStrings": {
|
||||
"DefaultConnection": "Server=localhost,${SQL_PORT};Database=PrintbaseDb;User Id=sa;Password=${SA_PASSWORD};TrustServerCertificate=True;"
|
||||
},
|
||||
"DatabaseOptions": {
|
||||
"ApplyMigrationsAtStartup": true
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user