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 lines114115116117117118119119120121122121122123124125124126127128129130131132133134126127128129130131132135136137138139140141142143144145136137138139140146147142143144148149150151152153154155156157113 unmodified lines { var db = scope.ServiceProvider.GetRequiredService<AppDbContext>();
// Ensure the database directory exists before running migrations // Ensure the database directory exists var connStr = builder.Configuration.GetConnectionString("DefaultConnection"); if (!string.IsNullOrEmpty(connStr) && connStr.Contains("Data Source=", StringComparison.OrdinalIgnoreCase)) // Emergency Cleanup & Optimization before Migration try { var parts = connStr.Split(';'); foreach (var part in parts) db.Database.OpenConnection(); using (var command = db.Database.GetDbConnection().CreateCommand()) { if (part.Trim().StartsWith("Data Source=", StringComparison.OrdinalIgnoreCase)) // 1. Basic settings for stability command.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) { var dbPath = part.Substring("Data Source=".Length).Trim(); var dbDir = Path.GetDirectoryName(dbPath); if (!string.IsNullOrEmpty(dbDir) && !Directory.Exists(dbDir)) { Directory.CreateDirectory(dbDir); } break; // Delete any nodes where Data (image) is larger than 2MB to unblock the DB command.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 database command.CommandText = "VACUUM;"; command.ExecuteNonQuery(); } } }
db.Database.Migrate();
// Set journal mode to TRUNCATE for stability on Docker/Cloud filesystems using (var command = db.Database.GetDbConnection().CreateCommand()) catch (Exception ex) { db.Database.OpenConnection(); command.CommandText = "PRAGMA journal_mode=TRUNCATE; PRAGMA synchronous=NORMAL; PRAGMA locking_mode=NORMAL; PRAGMA temp_store=MEMORY;"; command.ExecuteNonQuery(); Console.WriteLine($"[Warning] Emergency cleanup failed: {ex.Message}"); }
// Run Migrations with a reasonable timeout db.Database.SetCommandTimeout(120); // 2 minutes db.Database.Migrate();
// Auto-seed achievements var achievementService = scope.ServiceProvider.GetRequiredService<IAchievementService>(); achievementService.SeedAchievementsAsync().Wait();FlowAPI/Program.cs+28-20