Spaces:
Running
Running
Commit ·
f00923d
1
Parent(s): 977fb40
fix: restore database filename and add emergency cleanup logic to resolve migration hangs
Browse files113 unmodified lines114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149113 unmodified lines{var db = scope.ServiceProvider.GetRequiredService<AppDbContext>();// Ensure the database directory exists before running migrationsvar connStr = builder.Configuration.GetConnectionString("DefaultConnection");if (!string.IsNullOrEmpty(connStr) && connStr.Contains("Data Source=", StringComparison.OrdinalIgnoreCase)){var parts = connStr.Split(';');foreach (var part in parts){if (part.Trim().StartsWith("Data Source=", StringComparison.OrdinalIgnoreCase)){var dbPath = part.Substring("Data Source=".Length).Trim();var dbDir = Path.GetDirectoryName(dbPath);if (!string.IsNullOrEmpty(dbDir) && !Directory.Exists(dbDir)){Directory.CreateDirectory(dbDir);}break;}}}db.Database.Migrate();// Set journal mode to TRUNCATE for stability on Docker/Cloud filesystemsusing (var command = db.Database.GetDbConnection().CreateCommand()){db.Database.OpenConnection();command.CommandText = "PRAGMA journal_mode=TRUNCATE; PRAGMA synchronous=NORMAL; PRAGMA locking_mode=NORMAL; PRAGMA temp_store=MEMORY;";command.ExecuteNonQuery();}// Auto-seed achievementsvar achievementService = scope.ServiceProvider.GetRequiredService<IAchievementService>();achievementService.SeedAchievementsAsync().Wait();113 unmodified lines114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157113 unmodified lines{var db = scope.ServiceProvider.GetRequiredService<AppDbContext>();// Ensure the database directory existsvar connStr = builder.Configuration.GetConnectionString("DefaultConnection");// Emergency Cleanup & Optimization before Migrationtry{db.Database.OpenConnection();using (var command = db.Database.GetDbConnection().CreateCommand()){// 1. Basic settings for stabilitycommand.CommandText = "PRAGMA journal_mode=TRUNCATE; PRAGMA synchronous=NORMAL; PRAGMA busy_timeout=10000;";command.ExecuteNonQuery();// 2. DELETE OVERSIZED RECORDS (Possible cause of I/O hang)command.CommandText = "SELECT name FROM sqlite_master WHERE type='table' AND name='TaskNodes';";var tableExists = command.ExecuteScalar();if (tableExists != null){// Delete any nodes where Data (image) is larger than 2MB to unblock the DBcommand.CommandText = "DELETE FROM TaskNodes WHERE length(Data) > 2000000;";int deleted = command.ExecuteNonQuery();if (deleted > 0) Console.WriteLine($"[Emergency] Deleted {deleted} oversized nodes to restore stability.");// Compact the databasecommand.CommandText = "VACUUM;";command.ExecuteNonQuery();}}}catch (Exception ex){Console.WriteLine($"[Warning] Emergency cleanup failed: {ex.Message}");}// Run Migrations with a reasonable timeoutdb.Database.SetCommandTimeout(120); // 2 minutesdb.Database.Migrate();// Auto-seed achievementsvar achievementService = scope.ServiceProvider.GetRequiredService<IAchievementService>();achievementService.SeedAchievementsAsync().Wait();
FlowAPI/Program.cs+28-20