Skip to content

AddColumn with inline checkConstraint on an existing table double-applies the constraint (42710) #103

Description

@MelbourneDeveloper

What happened

DataProviderMigrate (postgres, additive phase) over a declarative schema where an existing table gains one new column that carries a checkConstraint:

      - name: workspace_size
        type: Text
        checkConstraint: "workspace_size IS NULL OR workspace_size IN ('small','medium','large')"

Plan and outcome:

Phase: all — applying 2 of 2 operation(s):
  AddColumnOperation
  AddCheckConstraintOperation
Error: migration apply failed: 42710: constraint "agent_configs_workspace_size_chk" for relation "agent_configs" already exists

The whole apply rolls back, so the column never lands: information_schema.columns and pg_constraint both show nothing afterwards, and every re-run fails the same way.

Diagnosis

AddColumnOperation already emits the column-level CHECK (named <table>_<column>_chk), and the planner also schedules a separate AddCheckConstraintOperation for the same declaration with the same name. On a fresh CREATE TABLE this does not happen, which is why the same YAML pattern works for columns declared at table-creation time.

Expected

One of:

  • the planner emits only AddColumnOperation (with the inline check) when the column is new, or
  • AddColumnOperation emits the bare column and leaves the check to AddCheckConstraintOperation.

Environment

  • Postgres 17 (Supabase)
  • Provider: postgres
  • Consumer: Nimblesite/NimblesiteAgenticPlatform migrations/schema.yaml, table agent_configs

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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