Skip to content

Domain Operations ​

Operation: createDomain ​

pgm.createDomain( domain_name, type, options ) ​

IMPORTANT

Create a new domain - postgres docs

Arguments ​

NameTypeDescription
domain_nameNameName of the new domain
typestringType of the new domain
optionsobjectCheck below for available options

Options ​

OptionTypeDescription
defaultValueDefault value of domain. See Default values
collationstringCollation of data type
notNullbooleanSets NOT NULL if true (not recommended)
checkstringSQL for a check constraint for this column
constraintNamestringName for constraint

Reverse Operation: dropDomain ​

pgm.dropDomain( domain_name, drop_options ) ​

IMPORTANT

Drop a domain - postgres docs

Arguments ​

NameTypeDescription
domain_nameNameName of the domain to drop
drop_optionsobjectCheck below for available options

Options ​

OptionTypeDescription
ifExistsbooleanDrops domain only if it exists
cascadebooleanDrops also dependent objects

Operation: alterDomain ​

pgm.alterDomain( domain_name, type, options ) ​

IMPORTANT

Alter a domain - postgres docs

Arguments ​

NameTypeDescription
domain_nameNameName of the new domain
optionsobjectCheck below for available options

Options ​

OptionTypeDescription
defaultValueSets the default. null drops it, omitting it keeps it. See Default values
collationstringCollation of data type
notNullbooleanSets NOT NULL if true; drops it if false
allowNullbooleanDrops NOT NULL if true; false is ignored and warns unless notNull: true
checkstringsql for a check constraint for this column
constraintNamestringname for constraint

Use notNull: true to disallow null values, and notNull: false or allowNull: true to allow them. Omitting both options leaves nullability unchanged. allowNull: false does not set NOT NULL and emits a warning unless notNull: true is also supplied. If both options are true or both are false, a warning explains that notNull takes precedence: true sets NOT NULL, and false drops it.

Operation: renameDomain ​

pgm.renameDomain( old_domain_name, new_domain_name ) ​

IMPORTANT

Rename a domain - postgres docs

Arguments ​

NameTypeDescription
old_domain_nameNameOld name of the domain
new_domain_nameNameNew name of the domain

Renaming preserves the source schema, including during automatic reversal. See Renaming and schemas for destination-schema validation and supported PgLiteral identifiers.

To move a domain between schemas, use SQL explicitly, for example pgm.sql('ALTER DOMAIN "old_schema"."my_domain" SET SCHEMA "new_schema"'). Provide the corresponding SQL in your down migration to reverse that move.