xataio / pgroll

PostgreSQL zero-downtime migrations made easy
https://www.xata.io
Apache License 2.0
2.99k stars 54 forks source link

Add testcase to ensure new columns can't be used as the the identity column in a backfill. #298

Closed andrew-farries closed 6 months ago

andrew-farries commented 6 months ago

Add a test to ensure that new columns can't be used as the identity for a backfill, even if they satisfy the conditions for an identity column.

A newly added NOT NULL and UNIQUE column could in theory be used as the identity column for a backfill. However, it shouldn't be used as the identity column fora backfill because it's a newly added column whose temporary column will be full of NULLs for any existing rows in the table.

Currently the column won't be selected as an identity for backfills because the nullability and uniqueness for new column are not populated when adding it to the virtual schema in the add_column operation:

https://github.com/xataio/pgroll/blob/c08ef7065cdbce965110e64f58e66eddf605eaee/pkg/migrations/op_add_column.go#L61-L63

Following on from the discussion here: https://github.com/xataio/pgroll/pull/289#discussion_r1505832826