danylokhodus commited on
Commit
724fc63
·
1 Parent(s): dd679c3

fix: clear WAL locks using actual DB path from connection string

Browse files
Files changed (1) hide show
  1. FlowAPI/Program.cs +11 -4
FlowAPI/Program.cs CHANGED
@@ -233,15 +233,22 @@ namespace FlowAPI
233
  db.Database.SetCommandTimeout(120); // 2 minutes
234
  db.Database.Migrate();
235
 
236
- // Manual lock clearing
237
  try {
238
- string dbPath = "/app/taskflow.db";
 
 
239
  if (File.Exists(dbPath)) {
240
  foreach (var s in new[] { "-wal", "-shm", "-journal" }) {
241
- if (File.Exists(dbPath + s)) File.Delete(dbPath + s);
 
 
 
242
  }
243
  }
244
- } catch {}
 
 
245
 
246
  // Auto-seed achievements
247
  var achievementService = scope.ServiceProvider.GetRequiredService<IAchievementService>();
 
233
  db.Database.SetCommandTimeout(120); // 2 minutes
234
  db.Database.Migrate();
235
 
236
+ // Manual lock clearing — use actual DB path from config
237
  try {
238
+ var connStrForLock = builder.Configuration.GetConnectionString("DefaultConnection") ?? "";
239
+ var lockMatch = System.Text.RegularExpressions.Regex.Match(connStrForLock, @"Data Source=(.+?)(?:;|$)", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
240
+ string dbPath = lockMatch.Success ? lockMatch.Groups[1].Value.Trim() : "/app/taskflow.db";
241
  if (File.Exists(dbPath)) {
242
  foreach (var s in new[] { "-wal", "-shm", "-journal" }) {
243
+ if (File.Exists(dbPath + s)) {
244
+ File.Delete(dbPath + s);
245
+ Console.WriteLine($"[Startup] Cleared stale lock file: {dbPath + s}");
246
+ }
247
  }
248
  }
249
+ } catch (Exception ex) {
250
+ Console.WriteLine($"[Startup] Lock clearing failed: {ex.Message}");
251
+ }
252
 
253
  // Auto-seed achievements
254
  var achievementService = scope.ServiceProvider.GetRequiredService<IAchievementService>();