pgroll/pkg/state
Andrew Farries 162bd06f9f
Fix duplicate inferred migrations when dropping columns outside of a migration (#305)
Ensure that only one `inferred` migration is created in the
`pgroll.migrations` table when a column is dropped outside of a
migration.

From the Postgres
[docs](https://www.postgresql.org/docs/current/event-trigger-definition.html):
> The sql_drop event occurs just before the ddl_command_end event
trigger for any operation that drops database objects

This means that when the `raw_migration` function is run in response to
`sql_drop` and `ddl_command_end`, duplicate entries will be created in
`pgroll.migrations`; once as the function is run for `sql_drop` and
again when it's run for `ddl_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 the
`pg_roll_handle_ddl` trigger runs for the same change. `DROP TABLE` and
`DROP VIEW` won't result in duplicate migrations because their schema
can't be inferred by the `ddl_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
2024-03-06 09:56:52 +00:00
..
errors.go License check in github actions (#123) 2023-09-22 10:31:49 +00:00
state_test.go Fix duplicate inferred migrations when dropping columns outside of a migration (#305) 2024-03-06 09:56:52 +00:00
state.go Fix duplicate inferred migrations when dropping columns outside of a migration (#305) 2024-03-06 09:56:52 +00:00
status.go Move logic for the status command into the state and migrations packages (#205) 2023-11-22 12:36:54 +00:00