Skip to content

Table Operations ​

Operation: createTable ​

pgm.createTable( tablename, columns, options ) ​

IMPORTANT

Create a new table - postgres docs

Arguments ​

NameTypeDescription
tablenameNamename for the new table
columnsobjectcolumn names / options -- see column definitions section
optionsobjecttable options (optional)

Options ​

OptionTypeDescription
temporarybooleandefault false
ifNotExistsbooleandefault false
inheritsNametable(s) to inherit from
constraintsobjecttable constraints see expression of add constraint
likeName or objecttable(s) to inherit from or object with table and options keys
commentstringadds comment on table
unloggedbooleandefault false

like options ​

OptionTypeDescription
includingstring or array[string]'COMMENTS', 'CONSTRAINTS', 'DEFAULTS', 'IDENTITY', 'INDEXES', 'STATISTICS', 'STORAGE', 'ALL'
excludingstring or array[string]'COMMENTS', 'CONSTRAINTS', 'DEFAULTS', 'IDENTITY', 'INDEXES', 'STATISTICS', 'STORAGE', 'ALL'

Reverse Operation: dropTable ​

pgm.dropTable( tablename, options ) ​

IMPORTANT

Drop existing table - postgres docs

Arguments ​

NameTypeDescription
tablenameNamename of the table to drop
optionsobjectCheck below for available options

Options ​

OptionTypeDescription
ifExistsbooleandrops table only if it exists
cascadebooleandrops also dependent objects

Operation: renameTable ​

pgm.renameTable( tablename, new_tablename ) ​

IMPORTANT

Rename a table - postgres docs

Reverse Operation: same operation in opposite direction

Arguments ​

NameTypeDescription
tablenameNamename of the table to rename
new_tablenameNamenew name of the table

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

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

Operation: alterTable ​

pgm.alterTable( tablename, options ) ​

IMPORTANT

Alter existing table - postgres docs

Arguments ​

NameTypeDescription
tablenameNamename of the table to alter
optionsobjectCheck below for available options

Options ​

OptionTypeDescription
levelSecuritystringDISABLE, ENABLE, FORCE, or NO FORCE
unloggedbooleanSets UNLOGGED if true