Spaces:
Sleeping
Sleeping
Commit ·
fbe6cd9
1
Parent(s): d8ea1e0
fix: auto-create DB directory on startup to prevent crash on HF Space
Browse files- FlowAPI/Program.cs +15 -1
FlowAPI/Program.cs
CHANGED
|
@@ -179,7 +179,21 @@ namespace FlowAPI
|
|
| 179 |
|
| 180 |
// Ensure the database directory exists
|
| 181 |
var connStr = builder.Configuration.GetConnectionString("DefaultConnection");
|
| 182 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 183 |
// Emergency Cleanup & Optimization before Migration
|
| 184 |
try
|
| 185 |
{
|
|
|
|
| 179 |
|
| 180 |
// Ensure the database directory exists
|
| 181 |
var connStr = builder.Configuration.GetConnectionString("DefaultConnection");
|
| 182 |
+
if (!string.IsNullOrEmpty(connStr))
|
| 183 |
+
{
|
| 184 |
+
// Extract path from "Data Source=/some/path/file.db"
|
| 185 |
+
var match = System.Text.RegularExpressions.Regex.Match(connStr, @"Data Source=(.+?)(?:;|$)", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
|
| 186 |
+
if (match.Success)
|
| 187 |
+
{
|
| 188 |
+
var dbDir = System.IO.Path.GetDirectoryName(match.Groups[1].Value.Trim());
|
| 189 |
+
if (!string.IsNullOrEmpty(dbDir) && !System.IO.Directory.Exists(dbDir))
|
| 190 |
+
{
|
| 191 |
+
System.IO.Directory.CreateDirectory(dbDir);
|
| 192 |
+
Console.WriteLine($"[Startup] Created database directory: {dbDir}");
|
| 193 |
+
}
|
| 194 |
+
}
|
| 195 |
+
}
|
| 196 |
+
|
| 197 |
// Emergency Cleanup & Optimization before Migration
|
| 198 |
try
|
| 199 |
{
|