Skip to content

DDL Improvements - #3

Merged
carldaws merged 8 commits into
mainfrom
ddl-coverage
Apr 18, 2026
Merged

carldaws merged 8 commits into
mainfrom
ddl-coverage

Conversation

@carldaws

Copy link
Copy Markdown
Owner
  • Replace DDL allowlist with dynamic interception: Instead of maintaining a hand-curated list of DDL methods to intercept, the adapter now discovers all SchemaStatements methods whose first parameter contains "table" and wraps them automatically. A small skip list (create_join_table, drop_join_table) covers methods where the first argument isn't the target table. New Rails methods are intercepted by default — no list to go stale.
  • Copy constraints during shadow: LIKE ... INCLUDING ALL EXCLUDING INDEXES doesn't copy foreign keys (Postgres design), exclusion constraints, or unique constraints (both index-backed). The shadow now replays these from pg_constraint after the data copy, using pg_get_constraintdef verbatim — no string rewriting needed since the definitions resolve correctly via search_path.
  • Drop table tombstoning: drop_table on a branch previously left the table visible via search_path fallthrough to public, corrupting schema.rb. Now creates a lightweight tombstone (structure-only, no data) in a __dropped schema that blocks fallthrough. The schema dumper excludes tombstoned tables. create_table after drop_table removes the tombstone.
  • Enum DDL shadowing: drop_enum, rename_enum, add_enum_value, and rename_enum_value now copy the enum type from public to the branch schema before applying the change, preventing silent mutation of public enums.
  • Comprehensive DDL test suite: 40+ new tests covering every table DDL method, enum DDL, constraint preservation, drop semantics, and structural equivalence. A meta-test ensures every SchemaStatements method with a table parameter either has a test or is explicitly skipped — new Rails methods cause a test failure, not a silent gap.

Test plan

  • Full suite passes: 124 runs, 274 assertions, 0 failures
  • Existing tests unmodified (except one search_path assertion updated for the dropped schema)
  • Verify drop_table on a branch no longer appears in schema.rb
  • Verify enum DDL on a branch doesn't modify public enums
  • Verify FK, exclusion, and unique constraints survive shadowing

@carldaws
carldaws merged commit 7d77ae3 into main Apr 18, 2026
1 check passed
@carldaws
carldaws deleted the ddl-coverage branch April 18, 2026 18:51
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