Skip to content

Preserve primary key constraint on altered columns #888

@kvch

Description

@kvch

If a column with a primary key constraint on it is altered by pgroll, the primary key constraint is lost after completing the operation.

Migration to reproduce the issue:

operations:
- alter_column:
    column: myid
    down: "CAST(\"myid\" AS bigint)"
    table: my_table
    type: uuid
    up: "gen_random_uuid"

Broken schema:

# \d my_table;
                    Table "public.my_table"
  Column   |           Type           | Collation | Nullable | Default
-----------+--------------------------+-----------+----------+---------
 myid      | uuid                     |           | not null |
Indexes:
    "my_table_pkey" UNIQUE, btree ("myid")

The primary key constraint is missing.

Workaround

Run a second migration to apply primary key constraint again:

operations:
- create_constraint:
    name: my_table_pk
    columns: [myid]
    table: my_table
    up:
      myid: myid
    down:
      myid: myid

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions