pgschema icon indicating copy to clipboard operation
pgschema copied to clipboard

Bug: Can't track defaults properly and double the work is being applied

Open sam-mosleh opened this issue 10 months ago • 1 comments

Step 1

Create a table

CREATE TABLE people (
    id bigint PRIMARY KEY GENERATED ALWAYS AS IDENTITY,
    created_at timestamptz
);

Step 2

Add a default

CREATE TABLE people (
    id bigint PRIMARY KEY GENERATED ALWAYS AS IDENTITY,
    created_at timestamptz DEFAULT NOW() NOT NULL
);

Expected behavior: To add default NOW() Actual behavior: The default is not tracked in the plan below

Plan: 1 to modify.

Summary by type:
  tables: 1 to modify

Tables:
  ~ people
    ~ created_at (column)

DDL to be executed:
--------------------------------------------------

ALTER TABLE people ADD CONSTRAINT created_at_not_null CHECK (created_at IS NOT NULL) NOT VALID;

ALTER TABLE people VALIDATE CONSTRAINT created_at_not_null;

ALTER TABLE people ALTER COLUMN created_at SET NOT NULL;

ALTER TABLE people DROP CONSTRAINT created_at_not_null;

ALTER TABLE people ADD CONSTRAINT created_at_not_null CHECK (created_at IS NOT NULL) NOT VALID;

ALTER TABLE people VALIDATE CONSTRAINT created_at_not_null;

ALTER TABLE people ALTER COLUMN created_at SET NOT NULL;

ALTER TABLE people DROP CONSTRAINT created_at_not_null;

Do you want to apply these changes? (yes/no):

Context

Tested version 1.6.2@ca0a203 darwin/arm64

@tianzhou Willing to do a PR if you feel comfortable.

sam-mosleh avatar Jan 31 '26 22:01 sam-mosleh

@sam-mosleh happy to review the PR

tianzhou avatar Feb 01 '26 02:02 tianzhou