Conversation
…ch file in a tx golang-migrate executes every up.sql inside a single transaction unless explicitly told otherwise. CREATE INDEX CONCURRENTLY refuses to run inside a transaction, so 000165's third statement aborted the migration: error: migration failed: CREATE INDEX CONCURRENTLY cannot run inside a transaction block in line 0 Symptoms: API container failed migrate-up on startup; prod deploy of main would have left schema_migrations stuck at 165 dirty=true with no index. Local was already in this state — we cleared the dirty flag manually and re-applied the fixed migration. Fix: regular CREATE INDEX inside the same BEGIN/COMMIT block as the ALTER TABLE statements. The assets table is small enough at launch that a brief AccessExclusiveLock during index build is acceptable. If/when scale grows past ~10M rows, ship a follow-up migration that drops this index and recreates it CONCURRENTLY out of band (run via psql, never through migrate-up). Reference comment in 000099_asset_performance_indexes.up.sql documented the same constraint two years ago — this one slipped through review because the file was structured with the intent of splitting transactions internally, which the runner does not honour.
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.
…ch file in a tx
golang-migrate executes every up.sql inside a single transaction unless explicitly told otherwise. CREATE INDEX CONCURRENTLY refuses to run inside a transaction, so 000165's third statement aborted the migration:
error: migration failed: CREATE INDEX CONCURRENTLY cannot run
inside a transaction block in line 0
Symptoms: API container failed migrate-up on startup; prod deploy of main would have left schema_migrations stuck at 165 dirty=true with no index. Local was already in this state — we cleared the dirty flag manually and re-applied the fixed migration.
Fix: regular CREATE INDEX inside the same BEGIN/COMMIT block as the ALTER TABLE statements. The assets table is small enough at launch that a brief AccessExclusiveLock during index build is acceptable. If/when scale grows past ~10M rows, ship a follow-up migration that drops this index and recreates it CONCURRENTLY out of band (run via psql, never through migrate-up).
Reference comment in 000099_asset_performance_indexes.up.sql documented the same constraint two years ago — this one slipped through review because the file was structured with the intent of splitting transactions internally, which the runner does not honour.