<aside> 🔁 Synced from GitHub #9febf8e47c63. Edit in the paidhr-system-docs repository, not here: changes made in Notion are overwritten.

</aside>

Database migrations

All schema changes, for every service that touches SQL Server, ship as core-backend EF Core migrations.

The checklist (from core-backend-service/CLAUDE.md and doc/Migration_Guide.md)

  1. Add or update the entity in Core.Backend.Domain/Entities/Tenant.
  2. Add an IEntityTypeConfiguration in Core.Backend.Infrastructure/Configurations/Tenant.
  3. Register it in TenantDbContext.OnModelCreating with ApplyConfiguration(...).
  4. Add the DbSet if needed.
  5. Generate the migration with the repo's EF Core CLI version: dotnet ef migrations add --context TenantDbContext --project src/Core.Backend.Infrastructure … Do not hand-write it.
  6. Put it in Migrations/TenantDb. Never in Migrations/Archive: the migrator skips that folder.
  7. The PR must contain the migration, its .Designer.cs and the updated TenantDbContextModelSnapshot.cs.
  8. Read Up and Down; Down must reverse Up.
  9. Build Infrastructure, Application and Api in Release mode.

SQL-only migrations (stored procedures, functions) put their script under Migrations/TenantDb/Scripts with a copy-to-output entry in the csproj.

Running locally

Environment=LOCAL ASPNETCORE_ENVIRONMENT=Development \
  dotnet run --project src/Core.Backend.Migrator

The migrator decrypts the real connection strings and walks membership, analytics and every tenant. Locally that reaches dev only. Don't use dotnet ef database update: the design-time factory points at a different database on purpose.

Rules learned the hard way

🛑 One migration per change

Thirteen small migrations on one feature stalled the develop deploy build. Collapse them before pushing.