fix(spock): replicate DDL across peers in alembic migrations (closes #5) - #6
Merged
Conversation
Closes #5. Migrations 0018 (admin_oauth_sessions) and 0019 (stripe_payment_intents) left billing-jeanluc (US) without the new tables when billing-spock (EU) won the start-up race. Spock 5.x replicates DML on enrolled tables but NOT arbitrary DDL — alembic_version (already in the default repset) advanced on both peers via DML replication, but the CREATE TABLE statements stayed local to whichever peer ran them first. Fixes: 1. New migration 0020 idempotently ensures both tables exist on every peer. Wraps the DDL in spock.replicate_ddl() so it fans out via the existing ddl_sql replication set, then falls back to plain DDL on non-Spock environments (CI, local dev) by detecting the extension. CREATE TABLE/INDEX IF NOT EXISTS makes it a no-op on the EU peer that already has the tables. 2. docs/MIGRATIONS.md documents the convention: future migrations touching public.* schema MUST route DDL through spock.replicate_ddl(), with a copy-paste template. 3. 6 new smoke tests verify the migration's spock-detection + dispatch logic without needing a real Spock cluster. Bridge-side reconciliation in cirisai/cirisbridge remains as defense in depth; this fix closes the cause, not just the symptom. 510 tests pass. ruff + mypy clean. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



Summary
Closes #5 — caused by my migrations
0018(admin_oauth_sessions) and0019(stripe_payment_intents) using rawop.create_table(), which Spock 5.x doesn't replicate. EU won the deploy race today, US silently advancedalembic_versionwithout ever creating the tables.What this PR adds
alembic/versions/2026_05_01_0020-spock_replicate_oauth_and_payment_intent_tables.py— corrective migration. Idempotently ensures both tables exist on every peer:spock.replicate_ddl()so it fans out via the existingddl_sqlreplication setSELECT 1 FROM pg_extension WHERE extname = 'spock') and falls back to plain DDL on non-Spock environments (CI, local dev, single-node deploys)CREATE TABLE IF NOT EXISTS/CREATE INDEX IF NOT EXISTSeverywhere — no-op on the EU peer that already has the tables; creates them on the US peer that doesn'tdocs/MIGRATIONS.md— documents the convention going forward, with a copy-paste template, plus operational checks for verifying alembic_version + table presence + repset enrollment match across peers.tests/test_spock_ddl_migration.py— 6 smoke tests covering: spock-extension detection (present/absent), DDL idempotency markers, dispatch path picksreplicate_ddlwhen present, falls back to plain DDL when absent, and revision-chain identifiers.Why this design
IF NOT EXISTSskips, US creates.ddl_sqlreplication set is already on every subscription's repset list (per the issue body). No new Spock config to deploy.pg_tables LEFT JOIN spock.tablesreconciliation pass remains valuable as defense in depth. This PR closes the cause, the bridge task closes the symptom. Both stay.Operational impact
Once merged + deployed:
:latest--tags billingon bridge pulls new digest, recreates containersspock.replicate_ddl()with the ensure-DDLIF NOT EXISTSmakes it a no-op locally; the replicated DDL on the US peer creates the missing tablesalembic_version = 2026_05_01_0020with both tables presentTest plan
alembic upgrade headon a Spock test cluster, observe table appears on both peers via replication (not via parallel local create)alembic upgrade headon local dev (no Spock), observe plain DDL path is useddocs/MIGRATIONS.mdreturn clean state on prod after deploy🤖 Generated with Claude Code