refactor:Disable-sample-data-seeding-and-rename-database-to-teleshop

This commit is contained in:
sysadmin
2025-11-18 22:15:53 +00:00
parent 1aed286fac
commit 14d254b2d1
8 changed files with 87 additions and 461 deletions

View File

@@ -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...");

View File

@@ -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",

View File

@@ -1,6 +1,6 @@
{
"ConnectionStrings": {
"DefaultConnection": "Data Source=/app/data/littleshop.db"
"DefaultConnection": "Data Source=/app/data/teleshop.db"
},
"Jwt": {
"Key": "YourSuperSecretKeyThatIsAtLeast32CharactersLong!",

View File

@@ -7,7 +7,7 @@
}
},
"ConnectionStrings": {
"DefaultConnection": "Data Source=littleshop-production.db"
"DefaultConnection": "Data Source=teleshop-production.db"
},
"Jwt": {
"Key": "${JWT_SECRET_KEY}",

View File

@@ -1,6 +1,6 @@
{
"ConnectionStrings": {
"DefaultConnection": "Data Source=littleshop.db"
"DefaultConnection": "Data Source=teleshop.db"
},
"Jwt": {
"Key": "",