fix: EXPOSED-696 [PostgreSQL] Drop of auto-increment sequence fails after column modified without dropping default #2369
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.
Description
Summary of the change:
Add
ALTER COLUMN ... DROP DEFAULT
string to modified columns that lose their auto-increment status.Detailed description:
When a column is modified to no longer be auto-incrementing,
MigrationUtils.statementsRequiredForDatabaseMigration()
currently generates statements toALTER
the column type andDROP
the associated sequence. If these statements are actually executed using PostgreSQL, they will fail with an exception like:ERROR: cannot drop sequence test_table_id_seq because other objects depend on it Detail: default value for column id of table test_table depends on sequence test_table_id_seq Hint: Use DROP ... CASCADE to drop the dependent objects too.. Statement(s): DROP SEQUENCE IF EXISTS test_table_id_seq
Before dropping the sequence, the default value of the no-longer-auto-incrementing column must also be dropped to ensure that the column no longer depends on it.
Note about Defaults:
Technically, metadata results correctly return a mismatch, with the existing column in the database having a default of something like
nextval('test_table_id_seq'::regclass)
. But this line purposefully ignores the value, resulting in a technically incorrectColumnDiff.defauts == false
, so the necessary string isn't currently appended.That line currently cannot be changed as it leads to failures in many other parts of the source code that depend on it.
PostgreSQLDialect.modifyColumn()
for condition when the existing column in the database is auto-incrementing but the defined column in the new table object is not.ColumnDiff
KDocs to be more clear.Type of Change
Please mark the relevant options with an "X":
Affected databases:
Checklist
Related Issues
EXPOSED-696
EXPOSED-691