xataio / pgroll

PostgreSQL zero-downtime migrations made easy

Home Page:https://www.xata.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Dropping columns results in duplicate `inferred` migrations

andrew-farries opened this issue · comments

Dropping columns outside of a pgroll migration results in a duplicate inferred migration in the pgroll.migrations table.

To reproduce:

In a fresh Postgres instance:

  • initialize pgroll:
pgroll init
  • create a table
create table foo(a serial primary key, b text)
  • drop a column:
alter table foo drop column b
  • view the pgroll.migrations table:
select * from pgroll.migrations order by created_at desc

Actual behaviour:

The pgroll.migrations table contains two entries for the inferred column drop:

+--------+--------------------+-------------------------------------------------------------------------------------------------------------------+----------------------------+----------------------------+--------------------+------+-------------------------------------------------------------------------------------->
| schema | name               | migration                                                                                                         | created_at                 | updated_at                 | parent             | done | resulting_schema                                                                     >
|--------+--------------------+-------------------------------------------------------------------------------------------------------------------+----------------------------+----------------------------+--------------------+------+-------------------------------------------------------------------------------------->
| public | sql_0adcbadf878e88 | {"name": "sql_0adcbadf878e88", "operations": [{"sql": {"up": "alter table foo drop column b"}}]}                  | 2024-03-05 10:49:56.732626 | 2024-03-05 10:49:56.732626 | sql_a75d0c69f0cfe2 | True | {"name": "public", "tables": {"foo": {"oid": "16415", "name": "foo", "columns": {"a":>
| public | sql_ba9fefdb42a66c | {"name": "sql_ba9fefdb42a66c", "operations": [{"sql": {"up": "alter table foo drop column b"}}]}                  | 2024-03-05 10:49:56.732626 | 2024-03-05 10:49:56.732626 | sql_0adcbadf878e88 | True | {"name": "public", "tables": {"foo": {"oid": "16415", "name": "foo", "columns": {"a":>
| public | sql_a75d0c69f0cfe2 | {"name": "sql_a75d0c69f0cfe2", "operations": [{"sql": {"up": "create table foo(a serial primary key, b text)"}}]} | 2024-03-05 10:49:48.964148 | 2024-03-05 10:49:48.964148 | <null>             | True | {"name": "public", "tables": {"foo": {"oid": "16415", "name": "foo", "columns": {"a":>
+--------+--------------------+-------------------------------------------------------------------------------------------------------------------+

Expected behaviour:

There is exacly one inferred migration corresponding to the column drop.