Skip to content

ateapi: squash PostgreSQL migrations and lock them once merged - #2991

Merged
Eitan Yarmush (EItanya) merged 7 commits into
agent-substrate:mainfrom
iplay88keys:iplay88keys/compact-pg-migrations
Oct 23, 2026
Merged

Eitan Yarmush (EItanya) merged 7 commits into
agent-substrate:mainfrom
iplay88keys:iplay88keys/compact-pg-migrations

Conversation

@iplay88keys

@iplay88keys Jeremy Alvis (iplay88keys) commented Oct 20, 2026 •

Copy link
Copy Markdown
Collaborator

For #1399.

Important

Recreate every existing Substrate PostgreSQL database after this merges, including dev databases built from main. ateapi can't upgrade a database created before the squash.

verify-migrations fails on this PR because the squash changes migrations already on main. It isn't a required check yet, so it doesn't block the merge. After this merges, a maintainer should add it to the required checks in the main ruleset.

New clusters run every migration at startup. Squashing 000001 to 000003 into 000001_initial.sql cuts that to one. I applied the three original files and the squashed file to empty databases, and their pg_dump --schema-only output matched.

Nothing detects an old database. A v0.6.0 database still starts, because its schema matches and schema_migrations already records versions 1 to 3. Goose would then treat the next 000002 and 000003 as applied and skip them. A v0.2.0 or v0.3.0 database lacks the access policy tables and also starts, because the store accepts a ledger that is ahead of the binary.

hack/verify/postgresql-migrations.sh now compares against the merge base with the target branch, instead of the latest v1+ tag. Clusters built from main also record migration versions, so an edit to a merged but unreleased migration was skipped there too. The check moves out of run-tests into its own verify-migrations job, so a failure no longer stops the unit tests and verifiers. The job runs on pull requests and merge groups, not on pushes to main. hack/verify-all.sh runs the script without a base ref, which checks only the file rules.

I can move the migration check to a follow-up PR if that's easier to review. If the squash merges first, neither PR fails verify-migrations.

AI disclosure: Claude Code made the changes and this description.

New databases now run one migration instead of three. Databases created
by v0.5.0 or earlier cannot be upgraded and must be recreated.

The migration verifier now treats migrations in any vX.Y.Z tag after
v0.5.x as released and immutable.
The verifier now compares against the merge base with the target branch
instead of the latest release tag. Databases built from main also record
migration versions, so an edit to a merged migration was skipped there.
A failed check no longer stops the unit tests and verifiers in run-tests.
verify-all.sh passes no arguments, so the check now skips the merge-base
comparison when no base ref is given.
if-no-files-found: error
- name: verify
run: hack/verify-all.sh
verify-migrations:

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We're having trouble with runner availability. Can we keep this check where it was for now

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's fine with me. It'll just need an admin override to merge this since it'll be failing a required check. I believe it will also fail that check in the merge queue, so I'm not sure what that'll look like to get this in.

@EItanya

Copy link
Copy Markdown
Collaborator

Note Benjamin Elder (@BenTheElder) we're adding a new job here to separate out the SQL immutability so we can control the blockingness of it.

@EItanya
Eitan Yarmush (EItanya) added this pull request to the merge queue Oct 23, 2026
Merged via the queue into agent-substrate:main with commit 85e475f Oct 23, 2026
15 of 16 checks passed
@iplay88keys
Jeremy Alvis (iplay88keys) deleted the iplay88keys/compact-pg-migrations branch October 23, 2026 18:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants