Private
Public Access
1
0

Mark existing bank-synced transactions as Cleared on startup

One-time migration: UPDATE all transactions that have a FitId
(bank-synced) and Status=Uncleared to Status=Cleared. Tracked
in data_migrations table so it only runs once.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Catherine Renelle
2026-02-09 20:56:26 -05:00
parent d52c7b53ce
commit b48cb1c48c
+18 -1
View File
@@ -119,8 +119,25 @@ using (var scope = app.Services.CreateScope())
await db.Database.MigrateAsync(); await db.Database.MigrateAsync();
} }
// One-time data migration: split SimpleFIN connections by institution // One-time data migrations
await SimpleFinConnectionMigration.RunAsync(app.Services, app.Services.GetRequiredService<ILogger<Program>>()); await SimpleFinConnectionMigration.RunAsync(app.Services, app.Services.GetRequiredService<ILogger<Program>>());
using (var scope = app.Services.CreateScope())
{
var db = scope.ServiceProvider.GetRequiredService<PurrseDbContext>();
await db.Database.ExecuteSqlRawAsync(
"CREATE TABLE IF NOT EXISTS data_migrations (name TEXT PRIMARY KEY, applied_at TIMESTAMP NOT NULL)");
var applied = await db.Database.SqlQueryRaw<int>(
"SELECT 1 AS \"Value\" FROM data_migrations WHERE name = 'ClearSyncedTransactions'").AnyAsync();
if (!applied)
{
var count = await db.Database.ExecuteSqlRawAsync(
"UPDATE \"Transactions\" SET \"Status\" = 1 WHERE \"FitId\" IS NOT NULL AND \"Status\" = 0");
if (count > 0)
app.Services.GetRequiredService<ILogger<Program>>().LogInformation("Marked {Count} bank-synced transactions as Cleared", count);
await db.Database.ExecuteSqlRawAsync(
"INSERT INTO data_migrations (name, applied_at) VALUES ('ClearSyncedTransactions', NOW()) ON CONFLICT DO NOTHING");
}
}
// Initialize plugin system // Initialize plugin system
var pluginService = app.Services.GetRequiredService<PluginService>(); var pluginService = app.Services.GetRequiredService<PluginService>();