refactor:Disable-sample-data-seeding-and-rename-database-to-teleshop
This commit is contained in:
@@ -431,52 +431,29 @@ app.MapGet("/api/version", () =>
|
||||
});
|
||||
});
|
||||
|
||||
// Apply database migrations and seed data
|
||||
// Apply database migrations
|
||||
using (var scope = app.Services.CreateScope())
|
||||
{
|
||||
var context = scope.ServiceProvider.GetRequiredService<LittleShopContext>();
|
||||
|
||||
// Use proper migrations in production, EnsureCreated only for development/testing
|
||||
if (app.Environment.IsProduction())
|
||||
// Always use migrations for consistent database initialization
|
||||
Log.Information("Applying database migrations...");
|
||||
try
|
||||
{
|
||||
Log.Information("Production environment: Applying database migrations...");
|
||||
try
|
||||
{
|
||||
context.Database.Migrate();
|
||||
Log.Information("Database migrations applied successfully");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log.Fatal(ex, "Database migration failed. Application cannot start.");
|
||||
throw;
|
||||
}
|
||||
context.Database.Migrate();
|
||||
Log.Information("Database migrations applied successfully");
|
||||
}
|
||||
else
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log.Information("Development/Testing environment: Using EnsureCreated");
|
||||
context.Database.EnsureCreated();
|
||||
Log.Fatal(ex, "Database migration failed. Application cannot start.");
|
||||
throw;
|
||||
}
|
||||
|
||||
// Seed default admin user
|
||||
|
||||
// Seed default admin user only
|
||||
var authService = scope.ServiceProvider.GetRequiredService<IAuthService>();
|
||||
await authService.SeedDefaultUserAsync();
|
||||
|
||||
// Seed sample data - only in development
|
||||
if (app.Environment.IsDevelopment())
|
||||
{
|
||||
Log.Information("Development environment: Seeding sample data");
|
||||
var dataSeeder = scope.ServiceProvider.GetRequiredService<IDataSeederService>();
|
||||
await dataSeeder.SeedSampleDataAsync();
|
||||
}
|
||||
|
||||
// Seed system settings - enable test currencies only in development
|
||||
if (app.Environment.IsDevelopment())
|
||||
{
|
||||
Log.Information("Development environment: Enabling test currencies");
|
||||
var systemSettings = scope.ServiceProvider.GetRequiredService<ISystemSettingsService>();
|
||||
await systemSettings.SetTestCurrencyEnabledAsync("TBTC", true);
|
||||
await systemSettings.SetTestCurrencyEnabledAsync("TLTC", true);
|
||||
}
|
||||
Log.Information("Database initialization complete - fresh install ready");
|
||||
}
|
||||
|
||||
Log.Information("LittleShop API starting up...");
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"ConnectionStrings": {
|
||||
"DefaultConnection": "Data Source=littleshop-dev.db"
|
||||
"DefaultConnection": "Data Source=teleshop-dev.db"
|
||||
},
|
||||
"Jwt": {
|
||||
"Key": "DEVELOPMENT_USE_DOTNET_USER_SECRETS_OR_ENV_VAR",
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"ConnectionStrings": {
|
||||
"DefaultConnection": "Data Source=/app/data/littleshop.db"
|
||||
"DefaultConnection": "Data Source=/app/data/teleshop.db"
|
||||
},
|
||||
"Jwt": {
|
||||
"Key": "YourSuperSecretKeyThatIsAtLeast32CharactersLong!",
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
}
|
||||
},
|
||||
"ConnectionStrings": {
|
||||
"DefaultConnection": "Data Source=littleshop-production.db"
|
||||
"DefaultConnection": "Data Source=teleshop-production.db"
|
||||
},
|
||||
"Jwt": {
|
||||
"Key": "${JWT_SECRET_KEY}",
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"ConnectionStrings": {
|
||||
"DefaultConnection": "Data Source=littleshop.db"
|
||||
"DefaultConnection": "Data Source=teleshop.db"
|
||||
},
|
||||
"Jwt": {
|
||||
"Key": "",
|
||||
|
||||
Reference in New Issue
Block a user