chore(backend): add explicit test data seed command
This commit is contained in:
@@ -6,7 +6,7 @@ using Socialize;
|
||||
using Socialize.Api.Infrastructure.BlobStorage.Configuration;
|
||||
using Socialize.Api.Infrastructure.BlobStorage.Services;
|
||||
using Socialize.Api.Infrastructure;
|
||||
using Socialize.Api.Infrastructure.Development;
|
||||
using Socialize.Api.Infrastructure.TestData;
|
||||
using Socialize.Api.Modules.Approvals;
|
||||
using Socialize.Api.Modules.Assets;
|
||||
using Socialize.Api.Modules.Channels;
|
||||
@@ -23,6 +23,7 @@ using Socialize.Api.Modules.Workspaces;
|
||||
|
||||
|
||||
var builder = WebApplication.CreateBuilder(args);
|
||||
bool seedTestData = args.Any(arg => string.Equals(arg, "seed-testdata", StringComparison.OrdinalIgnoreCase));
|
||||
|
||||
string? vaultUri = Environment.GetEnvironmentVariable("VaultUri");
|
||||
if (!string.IsNullOrWhiteSpace(vaultUri))
|
||||
@@ -78,6 +79,25 @@ builder.AddCalendarIntegrationsModule();
|
||||
|
||||
var app = builder.Build();
|
||||
|
||||
if (seedTestData)
|
||||
{
|
||||
if (app.Environment.IsProduction()
|
||||
&& !string.Equals(
|
||||
Environment.GetEnvironmentVariable("CONFIRM_PRODUCTION_SEED"),
|
||||
"true",
|
||||
StringComparison.Ordinal))
|
||||
{
|
||||
throw new InvalidOperationException(
|
||||
"Refusing to seed test data in Production without CONFIRM_PRODUCTION_SEED=true.");
|
||||
}
|
||||
|
||||
await app.UseAppDataAsync();
|
||||
await app.UseIdentityModuleAsync();
|
||||
await app.Services.SeedTestDataAsync();
|
||||
Console.WriteLine("Seeded test data.");
|
||||
return;
|
||||
}
|
||||
|
||||
app.UseForwardedHeaders(
|
||||
new ForwardedHeadersOptions { ForwardedHeaders = ForwardedHeaders.XForwardedProto }
|
||||
);
|
||||
@@ -90,7 +110,6 @@ app.UseAuthorization();
|
||||
// Initialize and seed the db.
|
||||
await app.UseAppDataAsync();
|
||||
await app.UseIdentityModuleAsync();
|
||||
await app.UseDevelopmentSeedAsync();
|
||||
|
||||
// Configure the HTTP request pipeline.
|
||||
if (!app.Environment.IsDevelopment())
|
||||
|
||||
Reference in New Issue
Block a user