This runbook documents the manual database safety procedure for FinanceManager production releases.
Scope:
Before applying a production release or a manual migration:
PowerShell example:
$env:SUPABASE_DB_URL="postgresql://postgres.[PROJECT-REF]:[PASSWORD]@aws-0-[REGION].pooler.supabase.com:5432/postgres"
New-Item -ItemType Directory -Force -Path .\backups | Out-Null
$timestamp = Get-Date -Format "yyyyMMdd-HHmmss"
Connection string note:
Connect value for the production project.List migrations known to the application:
dotnet ef migrations list `
--project code/FinanceManager.Api/FinanceManager.Api.csproj `
--startup-project code/FinanceManager.Api/FinanceManager.Api.csproj
Check which migration is currently applied in Supabase:
select "MigrationId", "ProductVersion"
from "__EFMigrationsHistory"
order by "MigrationId";
Run that query in the Supabase SQL Editor before the release. The last row is the current production migration.
Supabase offers two backup paths. Use both when possible:
In the Supabase Dashboard:
Database -> Backups.Notes:
Supabase recommends logical exports with the CLI db dump command for manual backups. For this repository, keep a schema backup and a data backup.
Schema backup:
supabase db dump --db-url "$env:SUPABASE_DB_URL" `
-f ".\backups\fm-schema-$timestamp.sql"
Data backup:
supabase db dump --db-url "$env:SUPABASE_DB_URL" `
--data-only `
--use-copy `
-x "storage.buckets_vectors" `
-x "storage.vector_indexes" `
-f ".\backups\fm-data-$timestamp.sql"
If you use custom database roles and need them recreated separately:
supabase db dump --db-url "$env:SUPABASE_DB_URL" `
--role-only `
-f ".\backups\fm-roles-$timestamp.sql"
After the files are generated:
This application applies pending EF Core migrations on startup through DatabaseInitializer, which calls MigrateAsync() for relational databases.
If you need to apply the migrations manually first, run:
dotnet ef database update `
--project code/FinanceManager.Api/FinanceManager.Api.csproj `
--startup-project code/FinanceManager.Api/FinanceManager.Api.csproj `
--connection "$env:SUPABASE_DB_URL"
Use this path when:
Do not use this as the primary recovery path after data corruption or destructive data backfills. In those cases, restore from backup instead.
Find the migration immediately before the bad one:
dotnet ef migrations list `
--project code/FinanceManager.Api/FinanceManager.Api.csproj `
--startup-project code/FinanceManager.Api/FinanceManager.Api.csproj
Example:
20260604114844_AddPasswordResetTokens
20260605232611_AddExternalServiceConfigurations
If 20260605232611_AddExternalServiceConfigurations is the bad release, the rollback target is 20260604114844_AddPasswordResetTokens.
dotnet ef database update 20260604114844_AddPasswordResetTokens `
--project code/FinanceManager.Api/FinanceManager.Api.csproj `
--startup-project code/FinanceManager.Api/FinanceManager.Api.csproj `
--connection "$env:SUPABASE_DB_URL"
Important:
Down() methods between the current migration and the target migration.__EFMigrationsHistory again and confirm the bad migration is gone.Use this path when:
dotnet ef database update <PreviousMigration> is not sufficient.Choose one of the following restore paths.
Preferred for production incidents when available.
Database -> Backups.Notes:
Use this when you need to restore into a fresh environment, or when managed backups are unavailable.
Recommended target:
Restore schema:
psql `
--single-transaction `
--variable ON_ERROR_STOP=1 `
--file ".\backups\fm-schema-YYYYMMDD-HHMMSS.sql" `
--dbname "$env:SUPABASE_DB_URL"
Restore data:
psql `
--single-transaction `
--variable ON_ERROR_STOP=1 `
--command "SET session_replication_role = replica" `
--file ".\backups\fm-data-YYYYMMDD-HHMMSS.sql" `
--dbname "$env:SUPABASE_DB_URL"
If roles were exported and need restoring:
psql `
--single-transaction `
--variable ON_ERROR_STOP=1 `
--file ".\backups\fm-roles-YYYYMMDD-HHMMSS.sql" `
--dbname "$env:SUPABASE_DB_URL"
Recommended validation after restore:
__EFMigrationsHistory matches the backup point.Use EF migration rollback when:
Down() methods.Use Supabase backup restore when:
Common commands for this repository:
dotnet tool update --global dotnet-ef
dotnet ef migrations list `
--project code/FinanceManager.Api/FinanceManager.Api.csproj `
--startup-project code/FinanceManager.Api/FinanceManager.Api.csproj
dotnet ef database update `
--project code/FinanceManager.Api/FinanceManager.Api.csproj `
--startup-project code/FinanceManager.Api/FinanceManager.Api.csproj `
--connection "$env:SUPABASE_DB_URL"
This runbook was verified against: