Skip to content

[CUBRID] Drop foreign keys before clean#136

Open
Srltas wants to merge 1 commit into
flyway:mainfrom
Srltas:feat/cubrid-fk-safe-clean
Open

[CUBRID] Drop foreign keys before clean#136
Srltas wants to merge 1 commit into
flyway:mainfrom
Srltas:feat/cubrid-fk-safe-clean

Conversation

@Srltas
Copy link
Copy Markdown
Contributor

@Srltas Srltas commented May 14, 2026

Summary

Flyway clean fails on CUBRID schemas containing tables linked by foreign keys. CUBRID prevents dropping a table that is still referenced by a foreign key from another table, so the current CubridSchema.doClean() fails when a parent table is encountered before its referecing children, and cannot resolve circular foreign key references at all.

This PR fixes ths issue by discovering incoming foreign keys via JDBC metadata and dropping those constraints before dropping the tables.

Details

  • CubridSchema.doClean() now calls dropForeignKeys() before iterating over doAllTables().
  • dropForeignKeys() queries DatabaseMetaData.getImportedKeys() for each table in the schema and runs ALTER TABLE ... DROP CONSTRAINT for every incoming foreign key.
  • With the constraints removed first, the subsequent DROP TABLE sequence succeeds regardless of order.
  • Adds cleanTablesWithForeignKeys intergration test that creates parent_table and child_table linked by a foreign key, then verifies flyway.clean() removes both.

Validation

Tested locally with Java 21:

sh ./mvnw -pl flyway-database-cubrid test

Result:

Tests run: 7, Failures: 0, Errors: 0, Skipped: 0
BUILD SUCCESS

CUBRID prevents dropping tables referenced by foreign keys, causing
Flyway clean to fail on schemas with parent/child relationships. This
fix identifies referencing foreign keys via JDBC metadata and drops
them first to ensure successful table deletion.
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