Skip to content

Track table LOGGED/UNLOGGED persistence#288

Draft
dilame wants to merge 1 commit into
stripe:mainfrom
dilame:fix/table-persistence
Draft

Track table LOGGED/UNLOGGED persistence#288
dilame wants to merge 1 commit into
stripe:mainfrom
dilame:fix/table-persistence

Conversation

@dilame
Copy link
Copy Markdown

@dilame dilame commented May 25, 2026

Summary

  • track table persistence from pg_class.relpersistence in schema extraction
  • emit CREATE UNLOGGED TABLE for new unlogged tables
  • emit ALTER TABLE ... SET LOGGED/UNLOGGED when an existing table changes persistence

Root Cause

pg-schema-diff did not include table persistence in its table model, so a declarative CREATE UNLOGGED TABLE target could differ from an existing logged table while the generated migration plan stayed empty.

Tests

  • PATH="/Applications/Postgres.app/Contents/Versions/16/bin:$PATH" go test ./internal/schema -run TestSchemaTestCases/'Simple schema|Partition test' -count=1
  • PATH="/Applications/Postgres.app/Contents/Versions/16/bin:$PATH" go test ./internal/migration_acceptance_tests -run TestTableTestCases/'Set table' -count=1
  • PATH="/Applications/Postgres.app/Contents/Versions/16/bin:$PATH" go test ./...

Constraint: PostgreSQL stores LOGGED/UNLOGGED table persistence in pg_class.relpersistence.\nRejected: Recreate tables for persistence-only changes | ALTER TABLE SET LOGGED/UNLOGGED is the direct PostgreSQL operation and keeps the diff narrow.\nConfidence: high\nScope-risk: narrow\nDirective: Preserve table persistence in both schema extraction and create/alter DDL generation.\nTested: PATH="/Applications/Postgres.app/Contents/Versions/16/bin:/opt/local/bin:/opt/local/sbin:/opt/homebrew/bin:/opt/homebrew/sbin:/usr/local/bin:/System/Cryptexes/App/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/local/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/appleinternal/bin:/Library/Apple/usr/bin:/usr/local/go/bin:/Users/bowzee/.volta/bin:/Users/bowzee/.codex/tmp/arg0/codex-arg0ugL248:/opt/homebrew/share/google-cloud-sdk/bin:/Users/bowzee/perl5/bin:/Users/bowzee/.antigravity/antigravity/bin:/opt/homebrew/opt/libpq/bin:/Users/bowzee/.local/bin:/opt/local/bin:/opt/local/sbin:/Users/bowzee/.cargo/bin:/Users/bowzee/Library/Application Support/JetBrains/Toolbox/scripts:/Applications/Codex.app/Contents/Resources" go test ./...\nNot-tested: Production migration run
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.

1 participant