Skip to content

Commit

Permalink
Merge pull request #26 from Team-Wilhelm/main
Browse files Browse the repository at this point in the history
Deploy DB init changes
  • Loading branch information
juuwel authored May 27, 2024
2 parents e305f64 + ef385d2 commit cef20cc
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions api/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ public static async Task Main(string[] args)

public static async Task<WebApplication> StartApi(string[] args)
{
if (args.Contains("--prod"))
{
Environment.SetEnvironmentVariable("ASPNETCORE_ENVIRONMENT", "Production");
}

Log.Logger = new LoggerConfiguration()
.WriteTo
.Console(outputTemplate: "\n{Timestamp:yyyy-MM-dd HH:mm:ss} [{Level}] {Message}{NewLine}{Exception}\n")
Expand Down Expand Up @@ -106,10 +111,19 @@ public static async Task<WebApplication> StartApi(string[] args)
{
var scope = app.Services.CreateScope();
var db = await app.Services.GetRequiredService<IDbContextFactory<ApplicationDbContext>>().CreateDbContextAsync();
await db.Database.EnsureDeletedAsync();

if (Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT") == "Development")
{
await db.Database.EnsureDeletedAsync();
}

await db.Database.EnsureCreatedAsync();
await db.Database.MigrateAsync();
await db.SeedDevelopmentDataAsync(scope, app.Configuration["AzureBlob:DefaultPlantImageUrl"] ?? "https://example.com");

if (Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT") == "Development")
{
await db.SeedDevelopmentDataAsync(scope, app.Configuration["AzureBlob:DefaultPlantImageUrl"] ?? "https://example.com");
}
}

builder.WebHost.UseUrls("http://*:9999");
Expand Down

0 comments on commit cef20cc

Please sign in to comment.