Skip to content

[BUG] Plan fails when altering an INCLUDE column of a referenced primary key #301

Description

@dilame

Reproduction

Source schema:

CREATE TABLE parent (
  id integer,
  payload integer,
  PRIMARY KEY (id) INCLUDE (payload)
);
CREATE TABLE child (
  parent_id integer REFERENCES parent (id)
);

Target schema changes only parent.payload from integer to bigint.

Actual

The generated plan contains:

ALTER TABLE "parent" ALTER COLUMN "payload" SET DATA TYPE bigint USING "payload"::bigint;

It does not drop/recreate the dependent foreign key or the primary key/index. PostgreSQL then fails because changing an included index column requires rebuilding the primary-key constraint/index:

ERROR: cannot drop constraint parent_pkey on table parent because other objects depend on it
DETAIL: constraint child_parent_id_fkey on table child depends on index parent_pkey

The plan emitted only the access-exclusive-lock hazard for the ALTER COLUMN TYPE; it did not warn that the plan is non-executable due to the dependency.

Expected

Generate an executable migration: drop the child FK, rebuild the PK/index with payload bigint, then recreate the FK (with safe ordering), or detect this unsupported dependency and emit a blocking hazard instead of a plan that PostgreSQL cannot execute.

Version

pg-schema-diff version reports version=(devel). The CLI was built from the integration/open-pr-stack branch of dilame/pg-schema-diff (a fork of this repository). The exact build commit was not embedded in the binary.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions