Skip to main content

Migrations

Schema changes are EF Core migrations in src/Integrations.Infrastructure/Persistence/Migrations, reviewed in the same PR as the code. Nobody hand-edits the production schema, and there are no .sql files kept just for documentation: the migration is the record.

Add a migration​

dotnet tool restore
# 1. change the domain class and its configuration in Persistence/Configurations
# 2. generate the migration
dotnet ef migrations add AddVendorChargedTax \
--project src/Integrations.Infrastructure --startup-project src/Integrations.Api
# 3. read the generated Up()/Down(): is anything dropped or rewritten? Is a backfill needed?
# 4. run the integration tests (they apply every migration to a real Postgres)
dotnet test --project tests/Integrations.IntegrationTests

Name migrations after what they do (CreditsAndTaxOverrides, CertificateRequestLink), not after a ticket.

Review the SQL​

The PR reviewer should see the SQL as well as the C#:

dotnet ef migrations script --idempotent \
--project src/Integrations.Infrastructure --startup-project src/Integrations.Api -o migrate.sql

When a migration does something non-obvious to data (a backfill, a type change, a constraint on existing rows), add a comment in the migration explaining it. Raw SQL in a migration (migrationBuilder.Sql(...)) must start with a -- comment saying what it does to the data and why.

Apply​

EnvironmentHow
KubernetesThe integrations-migrate Job (deploy/k8s/migrate-job.yaml, image arg migrate) runs before the rollout
Demo / localDatabase__MigrateOnStartup=true applies migrations at startup
TestsTestcontainers Postgres; every test run applies all migrations from scratch

Migrations must be backward compatible with the previous release (expand, then contract), because the old pods keep running during a rollout.

History​

MigrationWhat it did
20260929223802_InitialCreateEntities, tax documents/lines/jurisdictions, mappings, rates, locks, parties, certificates, audit, outbox
20260929230020_CreditsAndTaxOverridesCredits (original document link, credited amounts) and line tax-code overrides
20260930135341_CertificateRequestLinkCertExpress request link stored on certificate requests