Spaces:
Sleeping
Sleeping
Commit ·
26471a0
1
Parent(s): b9c7f0e
fix
Browse files- FlowAPI/Program.cs +21 -0
- FlowAPI/appsettings.Production.json +1 -1
FlowAPI/Program.cs
CHANGED
|
@@ -89,6 +89,27 @@ namespace FlowAPI
|
|
| 89 |
using (var scope = app.Services.CreateScope())
|
| 90 |
{
|
| 91 |
var db = scope.ServiceProvider.GetRequiredService<AppDbContext>();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 92 |
db.Database.Migrate();
|
| 93 |
|
| 94 |
// Auto-seed achievements
|
|
|
|
| 89 |
using (var scope = app.Services.CreateScope())
|
| 90 |
{
|
| 91 |
var db = scope.ServiceProvider.GetRequiredService<AppDbContext>();
|
| 92 |
+
|
| 93 |
+
// Ensure the database directory exists before running migrations
|
| 94 |
+
var connStr = builder.Configuration.GetConnectionString("DefaultConnection");
|
| 95 |
+
if (!string.IsNullOrEmpty(connStr) && connStr.Contains("Data Source=", StringComparison.OrdinalIgnoreCase))
|
| 96 |
+
{
|
| 97 |
+
var parts = connStr.Split(';');
|
| 98 |
+
foreach (var part in parts)
|
| 99 |
+
{
|
| 100 |
+
if (part.Trim().StartsWith("Data Source=", StringComparison.OrdinalIgnoreCase))
|
| 101 |
+
{
|
| 102 |
+
var dbPath = part.Substring("Data Source=".Length).Trim();
|
| 103 |
+
var dbDir = Path.GetDirectoryName(dbPath);
|
| 104 |
+
if (!string.IsNullOrEmpty(dbDir) && !Directory.Exists(dbDir))
|
| 105 |
+
{
|
| 106 |
+
Directory.CreateDirectory(dbDir);
|
| 107 |
+
}
|
| 108 |
+
break;
|
| 109 |
+
}
|
| 110 |
+
}
|
| 111 |
+
}
|
| 112 |
+
|
| 113 |
db.Database.Migrate();
|
| 114 |
|
| 115 |
// Auto-seed achievements
|
FlowAPI/appsettings.Production.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
| 1 |
{
|
| 2 |
"ConnectionStrings": {
|
| 3 |
-
"DefaultConnection": "Data Source=/
|
| 4 |
}
|
| 5 |
}
|
|
|
|
| 1 |
{
|
| 2 |
"ConnectionStrings": {
|
| 3 |
+
"DefaultConnection": "Data Source=/data/data/taskflow.db"
|
| 4 |
}
|
| 5 |
}
|