Fix duplicate inferred migrations when dropping columns outside of a migration #305
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.
Ensure that only one
inferred
migration is created in thepgroll.migrations
table when a column is dropped outside of a migration.From the Postgres docs:
This means that when the
raw_migration
function is run in response tosql_drop
andddl_command_end
, duplicate entries will be created inpgroll.migrations
; once as the function is run forsql_drop
and again when it's run forddl_command_end
.Change the definition of the
pg_roll_handle_drop
event trigger to only run on those kinds of drops that won't result in duplicates when thepg_roll_handle_ddl
trigger runs for the same change.DROP TABLE
andDROP VIEW
won't result in duplicate migrations because their schema can't be inferred by theddl_command_event
trigger because the object has already been dropped when the trigger runs.Update the inferred migration tests with two new testcases covering dropping tables and columns.
Fixes #304