`UNIQUE` constraints are dropped by migrations in non-`public` schemas
andrew-farries opened this issue · comments
When duplicating columns for backfilling, UNIQUE
constraints are dropped when the migration is applied in a schema other than public
.
To reproduce:
Run the series of migrations in this gist in a schema other than public
, eg:
go run . start --complete --schema foo 01_create_table.json
go run . start --complete --schema foo 02_add_column.json
go run . start --complete --schema foo 03_drop_not_null.json
go run . start --complete --schema foo 04_set_not_null.json
The final schema lacks the unique constraint on the two
column:
+----------------+--------------------------+-------------------------+----------+--------------+-------------+
| Column | Type | Modifiers | Storage | Stats target | Description |
|----------------+--------------------------+-------------------------+----------+--------------+-------------|
| xata_id | text | not null | extended | <null> | <null> |
| xata_version | integer | not null default 0 | plain | <null> | <null> |
| xata_createdat | timestamp with time zone | not null default now() | plain | <null> | <null> |
| xata_updatedat | timestamp with time zone | not null default now() | plain | <null> | <null> |
| two | integer | not null | plain | <null> | <null> |
+----------------+--------------------------+-------------------------+----------+--------------+-------------+
Indexes:
"_pgroll_new_tester_pkey" PRIMARY KEY, btree (xata_id)
Preservation of UNIQUE
constraints was implemented as part of #227, but missed this specific case of UNIQUE
constraints in migrations in non-public schema.