Repository navigation
Data migrations that reach every deployment: start-up runs retired SQL copies - #2805
peterdrier wants to merge 17 commits into
Conversation
Problem statement and plan. Nothing built. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0186neA54jAb2Cvdb6xgYZmd
|
The preview deployment for humans-qa is ready. 🟢 Open Preview | Open Build Logs | Open Application Logs Last updated at: 2026-11-29 13:55:39 CET |
…ckpoint stamp, nine migrations, simpler alternative) Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0186neA54jAb2Cvdb6xgYZmd
No empty migration per copy: a copy names what it runs after and the drop it runs before. Stops show a page. No date for the first checkpoint. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0186neA54jAb2Cvdb6xgYZmd
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0186neA54jAb2Cvdb6xgYZmd
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0186neA54jAb2Cvdb6xgYZmd
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0186neA54jAb2Cvdb6xgYZmd
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0186neA54jAb2Cvdb6xgYZmd
EF's MigrateAsync(target) reverts every applied migration above the target, so start-up could not stop a section in front of a drop. The runner now applies each pending migration itself, in its own transaction under EF's migration lock, and can stop before a named one. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0186neA54jAb2Cvdb6xgYZmd
… when it cannot A retired SqlCopy names the migrations it runs after and the drop it runs before. Start-up advances sections in order, stops a section in front of such a drop, runs every copy that is ready in one transaction each, audits the rows it moved, and goes on. A copy with nothing pending changes nothing and takes no snapshot. A failing copy, a round that moves nothing, or any failure after the database changed is a StartupHaltException: the app is torn down and a bare one serves a 503 page saying what stopped, with /health/live healthy so it replaces the old version. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0186neA54jAb2Cvdb6xgYZmd
A registered SQL copy appears on /Debug/DataMigrations like any data migration: its pending query fills the preview, Apply runs the same statements start-up will run elsewhere, audits each changed row as the admin and lets the section reload its cache. The agent hook now also blocks raw data SQL outside a repository, so a copy cannot be written as a side door. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0186neA54jAb2Cvdb6xgYZmd
A SQL copy declares the tables it touches. SqlCopyRegistrationTests fails the build when a key is reused, a named migration or copy does not exist, the SQL uses an undeclared table, or a later migration changes a declared table without the copy being moved along. The rule atoms name the two exceptions (start-up runs retired copies; start-up stops when the chain cannot go on), and database-changes.md and Debug.md describe the move, retire, drop steps as built. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0186neA54jAb2Cvdb6xgYZmd
governance.body-links-from-teams, teams.retire-governance-bodies and teams.remove-governance-body-roles keep their keys and stay on the data migrations page, but are now SQL copies, so start-up can run them on other deployments once they retire. Their service methods go; Governance no longer calls ITeamService. A copy statement may return target_type and target_id for its audit entry. Tested against the real tables in GovernanceBodyCopiesTests. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0186neA54jAb2Cvdb6xgYZmd
|
@codex review Generated by Claude Code |
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 2f4d8db0e6
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
|
Reviewed commit 2f4d8db. 5 inline finding(s) posted. |
PR Surface ReportCompared Summary: 43 changed file(s) | EF migrations: 0 added file(s), max 0/1 per context Reforge Surface Score
Section Deltas
Section Size & Complexity Deltas
Rule Deltas
Corpus Size & Complexity
At head: largest class Published Write Surface15 of 57 sections publish write capability, 47 interfaces (0). Interface SurfaceNew interfaces
Diff Size
New Files
|
A section that applied one migration and failed on the next never reported the first, so the failure skipped the halt page. The snapshot hook now marks the database as changing. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0186neA54jAb2Cvdb6xgYZmd
…nner - SqlCopy loses Tables: the build check reads the tables from the SQL. - The chain loop's progress is a copy finishing; AppliedNow and the second and third places that marked the database changed are gone. - The per-migration apply drops the suppressed-transaction branch no shipped migration uses. - The pending read loses its first-row flag. - The role delete statement returns its audit row directly. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0186neA54jAb2Cvdb6xgYZmd
|
Two red checks on earlier commits, neither from this PR's code:
The latest push reruns both. Generated by Claude Code |
|
Closed in favour of #2820, the same branch as a new PR: this PR's preview could not deploy (Coolify held a duplicate preview row for it). Generated by Claude Code |
Requested by Peter · project thread
What
Other groups run Humans. Nobody presses our Apply button on their database, so a retired data migration never ran there and the drop that follows loses their data. This makes a retired copy run by itself, in order, on every deployment.
SectionMigrationRunner,DatabaseMigrationHostedService): applies migrations one at a time with public EF services only, never undoing one; holds a drop that a retired SQL copy names as itsBeforeuntil the copy has run; runs the copy in one transaction with one audit entry per changed row. If the chain fails or cannot move, start-up stops and the app serves only a page saying what is wrong (StartupHaltPage,/health/livestays 200). No retry.ISectionSqlCopies,SqlCopy): pending query, statements, declared tables, audit actions,After,Before,AfterCopy,Retired,Reload. Until retired a copy shows on/Debug/DataMigrationsand Apply runs the same statements.docs/architecture/database-changes.mdandDebug.mddescribe move, retire, drop with SQL copies. Atomsno-data-backfillsandno-startup-guardseach name their one exception;removed-section-migrationsanddata-migration-hook-gotchasupdated. The agent hook blocks raw data SQL outside a repository.SqlCopyRegistrationTestsfails the build when a later migration changes a table a copy uses.governance.body-links-from-teams,teams.retire-governance-bodiesandteams.remove-governance-body-rolesare now SQL copies under the same keys. None is retired. Production reports all three done (read 2026-11-29), so the button shows nothing pending there. Retire the done governance data migrations (PR 5b) #2775 is then redone as "mark retired, delete the fallback".Design:
docs/superpowers/specs/2026-11-29-data-migrations-for-other-deployments-design.md. Not in this PR: code migrations at start-up, checkpoints, the other SQL-shaped copies.Why
Peter, 2026-11-28/29: the manual flow only proves something about our database. He chose SQL copies that start-up runs before the drop; stopping start-up is right when going on would break data; never a background retry.
Existing surface checked
New public surface in
Humans.Base, for Peter's approval:ISectionSqlCopies,SqlCopy,MigrationStep,SectionMigrationsHistory.NameFor.ISectionDataMigrations/DataMigrationcould not carry it: start-up needs statements it can run without the app's services, and the migrations each copy sits between. Removed:ITeamManagementService.RetireGovernanceBodyTeamsAsync,RemoveGovernanceBodyRolesAsync, and Governance's copy-from-Teams code with itsITeamServicedependency.Checklist
tier:thorough(start-up, migrations, cross-section contracts).Humans.Integration.Tests.mainonpeterdrier/Humans, current main merged in.dotnet test Humans.slnx; integrationInfrastructure(start-up chains, stop test, 28 sections from empty) andGovernanceBodyCopiesTestsagainst Postgres 16.Nav coverageno new page. The halt page was looked at on the running app.https://claude.ai/code/session_0186neA54jAb2Cvdb6xgYZmd
Generated by Claude Code