When generating migration SQL, pgschema produces domains in the following canonical format:
Copy
-- Simple domain without constraintsCREATE DOMAIN [schema.]domain_name AS data_type;-- Domain with constraints (multi-line format)CREATE DOMAIN [schema.]domain_name AS data_type [ DEFAULT expression ] [ NOT NULL ] [ CONSTRAINT constraint_name CHECK ( expression ) ] [ CHECK ( expression ) ];
Key characteristics of the canonical format:
Uses single-line format for simple domains without constraints
Uses multi-line format with indentation when domain has constraints, defaults, or NOT NULL
DEFAULT clause appears before NOT NULL when both are present
Named constraints use CONSTRAINT constraint_name prefix
Anonymous constraints are listed without the CONSTRAINT keyword
Each constraint is on its own indented line for readability
For DROP operations: DROP DOMAIN IF EXISTS domain_name RESTRICT;
Note: Domain modifications in pgschema currently require dropping and recreating the domain, as PostgreSQL has limited ALTER DOMAIN support and complex dependencies make in-place modifications challenging.