Table-level CHECK constraints omitted from schema dump
When dumping a schema containing tables with CHECK constraints, the constraints are silently dropped from the output.
Repro SQL code
CREATE SCHEMA test;
CREATE TABLE test.test_table (
id int PRIMARY KEY,
status text NOT NULL,
reason text,
actor_id uuid,
CONSTRAINT test_table_status_check CHECK (
(status = 'active')
OR (status = 'cancelled' AND reason IS NOT NULL)
OR (status = 'revoked' AND actor_id IS NOT NULL)
)
);
Dump schema
pgschema dump --schema test ...
Expected output
CREATE TABLE IF NOT EXISTS test_table (
id integer NOT NULL,
status text NOT NULL,
reason text,
actor_id uuid,
CONSTRAINT test_table_pkey PRIMARY KEY (id),
CONSTRAINT test_table_status_check CHECK (status = 'active' OR status = 'cancelled' AND reason IS NOT NULL OR status = 'revoked' AND actor_id IS NOT NULL)
);
Database state
postgres=# \d test.test_table
Table "test.test_table"
Column | Type | Collation | Nullable | Default
----------+---------+-----------+----------+---------
id | integer | | not null |
status | text | | not null |
reason | text | | |
actor_id | uuid | | |
Indexes:
"test_table_pkey" PRIMARY KEY, btree (id)
Check constraints:
"test_table_status_check" CHECK (status = 'active'::text OR status = 'cancelled'::text AND reason IS NOT NULL OR status = 'revoked'::text AND actor_id IS NOT NULL)
Actual output
CREATE TABLE IF NOT EXISTS test_table (
id integer,
status text NOT NULL,
reason text,
actor_id uuid,
CONSTRAINT test_table_pkey PRIMARY KEY (id)
);
The CHECK constraint is silently omitted. Note that domain-level CHECK constraints (e.g., CREATE DOMAIN ... CHECK (...)) are included correctly — only table-level CHECK constraints are affected.
Environment
- PostgreSQL 18.1
- pgschema v1.9.0
Table-level CHECK constraints omitted from schema dump
When dumping a schema containing tables with
CHECKconstraints, the constraints are silently dropped from the output.Repro SQL code
Dump schema
pgschema dump --schema test ...Expected output
Database state
Actual output
The
CHECKconstraint is silently omitted. Note that domain-levelCHECKconstraints (e.g.,CREATE DOMAIN ... CHECK (...)) are included correctly — only table-levelCHECKconstraints are affected.Environment