Table Operations
Operation: createTable
pgm.createTable( tablename, columns, options )
IMPORTANT
Create a new table - postgres docs
Arguments
| Name | Type | Description |
|---|---|---|
tablename | Name | name for the new table |
columns | object | column names / options -- see column definitions section |
options | object | table options (optional) |
Options
| Option | Type | Description |
|---|---|---|
temporary | boolean | default false |
ifNotExists | boolean | default false |
inherits | Name | table(s) to inherit from |
constraints | object | table constraints see expression of add constraint |
like | Name or object | table(s) to inherit from or object with table and options keys |
comment | string | adds comment on table |
unlogged | boolean | default false |
like options
| Option | Type | Description |
|---|---|---|
including | string or array[string] | 'COMMENTS', 'CONSTRAINTS', 'DEFAULTS', 'IDENTITY', 'INDEXES', 'STATISTICS', 'STORAGE', 'ALL' |
excluding | string 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
| Name | Type | Description |
|---|---|---|
tablename | Name | name of the table to drop |
options | object | Check below for available options |
Options
| Option | Type | Description |
|---|---|---|
ifExists | boolean | drops table only if it exists |
cascade | boolean | drops also dependent objects |
Operation: renameTable
pgm.renameTable( tablename, new_tablename )
Arguments
| Name | Type | Description |
|---|---|---|
tablename | Name | name of the table to rename |
new_tablename | Name | new name of the table |
Renaming preserves the table’s schema, including during automatic reversal. If new_tablename specifies a schema, it must match the schema in tablename. When specifying a destination schema, use the object form for tablename too; the schema cannot be inferred from a string table name or the database search path.
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
| Name | Type | Description |
|---|---|---|
tablename | Name | name of the table to alter |
options | object | Check below for available options |
Options
| Option | Type | Description |
|---|---|---|
levelSecurity | string | DISABLE, ENABLE, FORCE, or NO FORCE |
unlogged | boolean | Sets UNLOGGED if true |