From 5dff71fb422b3cb3bacba321a6001178caec12d2 Mon Sep 17 00:00:00 2001 From: Arttu Manninen Date: Wed, 9 Jul 2025 12:14:28 +0300 Subject: [PATCH 1/8] Added References type to extend Name --- src/operations/generalTypes.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/operations/generalTypes.ts b/src/operations/generalTypes.ts index 41bbdc0ba..56e53f2a5 100644 --- a/src/operations/generalTypes.ts +++ b/src/operations/generalTypes.ts @@ -26,6 +26,10 @@ export type Type = string | { type: string }; export type Name = string | { schema?: string; name: string }; +export type Reference = Name & { + columns?: string | string[]; +}; + export interface IfNotExistsOption { ifNotExists?: boolean; } From 2df9f18003fdaa9791832bcf1d1dffe620406330 Mon Sep 17 00:00:00 2001 From: Arttu Manninen Date: Wed, 9 Jul 2025 12:15:11 +0300 Subject: [PATCH 2/8] Allow Literal to ingest References type --- src/utils/createTransformer.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/utils/createTransformer.ts b/src/utils/createTransformer.ts index 9811feb93..026422d99 100644 --- a/src/utils/createTransformer.ts +++ b/src/utils/createTransformer.ts @@ -1,7 +1,7 @@ import { escapeValue } from '.'; -import type { Name, Value } from '../operations/generalTypes'; +import type { Name, Reference, Value } from '../operations/generalTypes'; -export type Literal = (v: Name) => string; +export type Literal = (v: Name | Reference) => string; export function createTransformer( literal: Literal From e8fd9bbde25b83c04c4391e867d3636a8b52c920 Mon Sep 17 00:00:00 2001 From: Arttu Manninen Date: Wed, 9 Jul 2025 12:15:49 +0300 Subject: [PATCH 3/8] Allow using optional columns for references to define the target column or columns --- src/operations/tables/shared.ts | 20 ++++++- test/operations/tables/createTable.spec.ts | 65 ++++++++++++++++++++++ 2 files changed, 82 insertions(+), 3 deletions(-) diff --git a/src/operations/tables/shared.ts b/src/operations/tables/shared.ts index f6f2a66ee..461f0ac7b 100644 --- a/src/operations/tables/shared.ts +++ b/src/operations/tables/shared.ts @@ -2,7 +2,12 @@ import type { MigrationOptions } from '../../migrationOptions'; import { applyType, escapeValue, makeComment, toArray } from '../../utils'; import type { Literal } from '../../utils/createTransformer'; import type { FunctionParamType } from '../functions'; -import type { IfNotExistsOption, Name, Value } from '../generalTypes'; +import type { + IfNotExistsOption, + Name, + Reference, + Value, +} from '../generalTypes'; import { parseSequenceOptions, type SequenceOptions } from '../sequences'; export type Action = @@ -17,7 +22,7 @@ export interface ReferencesOptions { referencesConstraintComment?: string; - references: Name; + references: Reference; onDelete?: Action; @@ -138,11 +143,20 @@ export function parseReferences( const clauses: string[] = []; + // Optional column references + const columns: string[] = ( + references?.columns == null ? [] : toArray(references.columns) + ) + .filter((column: string) => column && literal) + .map((column: string) => literal(column)); + + const col = columns.length > 0 ? `(${columns.join(', ')})` : ''; + clauses.push( typeof references === 'string' && (references.startsWith('"') || references.endsWith(')')) ? `REFERENCES ${references}` - : `REFERENCES ${literal(references)}` + : `REFERENCES ${literal(references)}${col}` ); if (match) { diff --git a/test/operations/tables/createTable.spec.ts b/test/operations/tables/createTable.spec.ts index 1bdde31af..ed13670a5 100644 --- a/test/operations/tables/createTable.spec.ts +++ b/test/operations/tables/createTable.spec.ts @@ -173,6 +173,44 @@ describe('operations', () => { ], `CREATE TABLE "my_table_name" ( "parent_id" integer REFERENCES "schema_a"."table_b" +);`, + ], + [ + 'should use columns with foreign keys 1', + options1, + [ + 'myTableName', + { + parentId: { + type: 'integer', + references: { name: 'tableB', columns: 'columnC' }, + }, + }, + undefined, + ], + `CREATE TABLE "myTableName" ( + "parentId" integer REFERENCES "tableB"("columnC") +);`, + ], + [ + 'should use columns with foreign keys 2', + options2, + [ + 'myTableName', + { + parentId: { + type: 'integer', + references: { + schema: 'schemaA', + name: 'tableB', + columns: ['columnC'], + }, + }, + }, + undefined, + ], + `CREATE TABLE "my_table_name" ( + "parent_id" integer REFERENCES "schema_a"."table_b"("column_c") );`, ], // should match clause can be used for foreign keys @@ -431,6 +469,33 @@ describe('operations', () => { CONSTRAINT "my_table_name_uniq_col_a_col_b" UNIQUE ("col_a", "col_b"), CONSTRAINT "my_table_name_uniq_col_c" UNIQUE ("col_c") );`, + ], + // should create foreign key references + [ + 'should create comments on foreign keys 1', + options1, + [ + 'myTableName', + { colA: { type: 'integer' } }, + { + constraints: { + foreignKeys: { + columns: ['colA', 'colB'], + references: { + schema: 'otherSchema', + name: 'otherTable', + columns: ['colC', 'colD'], + }, + referencesConstraintComment: 'example comment', + }, + }, + }, + ], + `CREATE TABLE "myTableName" ( + "colA" integer, + CONSTRAINT "myTableName_fk_colA_colB" FOREIGN KEY ("colA", "colB") REFERENCES "otherSchema"."otherTable"("colC", "colD") +); +COMMENT ON CONSTRAINT "myTableName_fk_colA_colB" ON "myTableName" IS $pga$example comment$pga$;`, ], // should create comments on foreign keys [ From f3e21cfb7254f8c01399556f96bd452b8f1cb3b4 Mon Sep 17 00:00:00 2001 From: Arttu Manninen Date: Wed, 9 Jul 2025 12:30:06 +0300 Subject: [PATCH 4/8] Updated documentation for foreign key references --- docs/src/migrations/constraints.md | 18 +++++++++--------- docs/src/migrations/index.md | 1 + 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/docs/src/migrations/constraints.md b/docs/src/migrations/constraints.md index ce2bf37a9..8f42b9767 100644 --- a/docs/src/migrations/constraints.md +++ b/docs/src/migrations/constraints.md @@ -32,15 +32,15 @@ #### Foreign Keys -| Option | Type | Description | -| ----------------------------- | -------------------------- | ---------------------------------------------------------------------------------- | -| `columns` | `Name` or `array of Names` | Names of columns | -| `references` | `Name` | Names of foreign table and column names | -| `referencesConstraintName` | `string` | Name of the created constraint (only necessary when creating multiple constraints) | -| `referencesConstraintComment` | `string` | Comment on the individual foreign key constraint | -| `onDelete` | `string` | Action to perform on delete | -| `onUpdate` | `string` | Action to perform on update | -| `match` | `string` | `FULL` or `SIMPLE` | +| Option | Type | Description | +| ----------------------------- | -------------------------------- | ---------------------------------------------------------------------------------- | +| `columns` | `Name` or `array of Names` | Names of columns | +| `references` | [`Reference`](/migrations/#type) | Names of foreign table and column names | +| `referencesConstraintName` | `string` | Name of the created constraint (only necessary when creating multiple constraints) | +| `referencesConstraintComment` | `string` | Comment on the individual foreign key constraint | +| `onDelete` | `string` | Action to perform on delete | +| `onUpdate` | `string` | Action to perform on update | +| `match` | `string` | `FULL` or `SIMPLE` | ## Reverse Operation: `dropConstraint` diff --git a/docs/src/migrations/index.md b/docs/src/migrations/index.md index 766f80545..a327a8b47 100644 --- a/docs/src/migrations/index.md +++ b/docs/src/migrations/index.md @@ -115,6 +115,7 @@ CREATE TABLE "my_schema"."my_table_name" ( ```ts type Name = string | { schema: string; name: string }; +type Reference = Name & { columns?: string | string[] }; ``` ## Locking From ccc72bb2d754f1c550484b3fe8e3f95fec3b8caa Mon Sep 17 00:00:00 2001 From: Arttu Manninen Date: Wed, 9 Jul 2025 12:36:03 +0300 Subject: [PATCH 5/8] Refined new test descriptions and removed related unnecessary comment testing --- test/operations/tables/createTable.spec.ts | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/test/operations/tables/createTable.spec.ts b/test/operations/tables/createTable.spec.ts index ed13670a5..9ed57fab9 100644 --- a/test/operations/tables/createTable.spec.ts +++ b/test/operations/tables/createTable.spec.ts @@ -470,13 +470,13 @@ describe('operations', () => { CONSTRAINT "my_table_name_uniq_col_c" UNIQUE ("col_c") );`, ], - // should create foreign key references + // should create foreign key references with explicit target column names [ - 'should create comments on foreign keys 1', + 'should explicitly define referred target column names on foreign keys 1', options1, [ 'myTableName', - { colA: { type: 'integer' } }, + { colA: { type: 'integer' }, colB: { type: 'integer' } }, { constraints: { foreignKeys: { @@ -486,16 +486,15 @@ describe('operations', () => { name: 'otherTable', columns: ['colC', 'colD'], }, - referencesConstraintComment: 'example comment', }, }, }, ], `CREATE TABLE "myTableName" ( "colA" integer, + "colB" integer, CONSTRAINT "myTableName_fk_colA_colB" FOREIGN KEY ("colA", "colB") REFERENCES "otherSchema"."otherTable"("colC", "colD") -); -COMMENT ON CONSTRAINT "myTableName_fk_colA_colB" ON "myTableName" IS $pga$example comment$pga$;`, +);`, ], // should create comments on foreign keys [ From 090d5478f0d62a23f709906fa12776f5336cb602 Mon Sep 17 00:00:00 2001 From: Arttu Manninen Date: Wed, 9 Jul 2025 12:37:47 +0300 Subject: [PATCH 6/8] Added Reference to the Type section and renamed Type to Types --- docs/src/migrations/columns.md | 74 +++++++-------- docs/src/migrations/constraints.md | 48 +++++----- docs/src/migrations/domains.md | 34 +++---- docs/src/migrations/functions.md | 8 +- docs/src/migrations/grants.md | 84 ++++++++--------- docs/src/migrations/index.md | 2 +- docs/src/migrations/indexes.md | 4 +- docs/src/migrations/mViews.md | 8 +- docs/src/migrations/operators.md | 144 ++++++++++++++--------------- docs/src/migrations/policies.md | 40 ++++---- docs/src/migrations/roles.md | 30 +++--- docs/src/migrations/sequences.md | 8 +- docs/src/migrations/tables.md | 52 +++++------ docs/src/migrations/triggers.md | 54 +++++------ docs/src/migrations/types.md | 76 +++++++-------- 15 files changed, 333 insertions(+), 333 deletions(-) diff --git a/docs/src/migrations/columns.md b/docs/src/migrations/columns.md index 24122e33a..0a5ead625 100644 --- a/docs/src/migrations/columns.md +++ b/docs/src/migrations/columns.md @@ -6,27 +6,27 @@ The `createTable` and `addColumns` methods both take a `columns` argument that s It is an object (key/value) where each key is the name of the column, and the value is another object that defines the options for the column. -| Option | Type | Description | -| ----------------------------- | ------------------------------------- | -------------------------------------------------------------------------------------------- | -| `type` | `string` | Data type (use normal postgres types) | -| `collation` | `string` | Collation of data type | -| `unique` | `boolean` | Set to true to add a unique constraint on this column | -| `primaryKey` | `boolean` | Set to true to make this column the primary key | -| `notNull` | `boolean` | Set to true to make this column not null | -| `default` | `string` | Adds DEFAULT clause for column. Accepts null, a literal value, or a `pgm.func()` expression. | -| `check` | `string` | SQL for a check constraint for this column | -| `references` | [Name](/migrations/#type) or `string` | A table name that this column is a foreign key to | -| `referencesConstraintName` | `string` | Name of the created constraint | -| `referencesConstraintComment` | `string` | Comment on the created constraint | -| `onDelete` | `string` | Adds ON DELETE constraint for a reference column | -| `onUpdate` | `string` | Adds ON UPDATE constraint for a reference column | -| `match` | `string` | `FULL` or `SIMPLE` | -| `deferrable` | `boolean` | Flag for deferrable column constraint | -| `deferred` | `boolean` | Flag for initially deferred deferrable column constraint | -| `comment` | `string` | Adds comment on column | -| `expressionGenerated` | `string` | Expression to compute column value | -| `sequenceGenerated` | `object` | Creates identity column see [sequence options section](sequences.md#sequence-options) | -| `precedence` | `string` | `ALWAYS` or `BY DEFAULT` | +| Option | Type | Description | +| ----------------------------- | -------------------------------------- | -------------------------------------------------------------------------------------------- | +| `type` | `string` | Data type (use normal postgres types) | +| `collation` | `string` | Collation of data type | +| `unique` | `boolean` | Set to true to add a unique constraint on this column | +| `primaryKey` | `boolean` | Set to true to make this column the primary key | +| `notNull` | `boolean` | Set to true to make this column not null | +| `default` | `string` | Adds DEFAULT clause for column. Accepts null, a literal value, or a `pgm.func()` expression. | +| `check` | `string` | SQL for a check constraint for this column | +| `references` | [Name](/migrations/#types) or `string` | A table name that this column is a foreign key to | +| `referencesConstraintName` | `string` | Name of the created constraint | +| `referencesConstraintComment` | `string` | Comment on the created constraint | +| `onDelete` | `string` | Adds ON DELETE constraint for a reference column | +| `onUpdate` | `string` | Adds ON UPDATE constraint for a reference column | +| `match` | `string` | `FULL` or `SIMPLE` | +| `deferrable` | `boolean` | Flag for deferrable column constraint | +| `deferred` | `boolean` | Flag for initially deferred deferrable column constraint | +| `comment` | `string` | Adds comment on column | +| `expressionGenerated` | `string` | Expression to compute column value | +| `sequenceGenerated` | `object` | Creates identity column see [sequence options section](sequences.md#sequence-options) | +| `precedence` | `string` | `ALWAYS` or `BY DEFAULT` | ## Data types & Convenience Shorthand @@ -72,11 +72,11 @@ pgm.addColumns('myTable', { id: { type: 'serial', primaryKey: true } }); #### Arguments -| Name | Type | Description | -| ------------- | ------------------------- | ------------------------------------------------------------------------------- | -| `tablename` | [Name](/migrations/#type) | Name of the table to alter | -| `new_columns` | `object` | Column names / options -- see [column definitions section](#column-definitions) | -| `options` | `object` | Check below for available options | +| Name | Type | Description | +| ------------- | -------------------------- | ------------------------------------------------------------------------------- | +| `tablename` | [Name](/migrations/#types) | Name of the table to alter | +| `new_columns` | `object` | Column names / options -- see [column definitions section](#column-definitions) | +| `options` | `object` | Check below for available options | ##### Options @@ -97,7 +97,7 @@ pgm.addColumns('myTable', { id: { type: 'serial', primaryKey: true } }); | Name | Type | Description | | ----------- | ------------------------------ | ---------------------------------------- | -| `tablename` | [Name](/migrations/#type) | Name of the table to alter | +| `tablename` | [Name](/migrations/#types) | Name of the table to alter | | `columns` | `array of strings` or `object` | Columns to drop (if objected, uses keys) | | `options` | `object` | Check below for available options | @@ -119,11 +119,11 @@ pgm.addColumns('myTable', { id: { type: 'serial', primaryKey: true } }); #### Arguments -| Name | Type | Description | -| ----------------- | ------------------------- | ------------------- | -| `tablename` | [Name](/migrations/#type) | Name of the table | -| `old_column_name` | `string` | Current column name | -| `new_column_name` | `string` | New column name | +| Name | Type | Description | +| ----------------- | -------------------------- | ------------------- | +| `tablename` | [Name](/migrations/#types) | Name of the table | +| `old_column_name` | `string` | Current column name | +| `new_column_name` | `string` | New column name | ### Operation: `alterColumn` @@ -135,11 +135,11 @@ pgm.addColumns('myTable', { id: { type: 'serial', primaryKey: true } }); #### Arguments -| Name | Type | Description | -| ---------------- | ------------------------- | --------------------------- | -| `tablename` | [Name](/migrations/#type) | Name of the table | -| `column_name` | `string` | Column to alter | -| `column_options` | `object` | Optional new column options | +| Name | Type | Description | +| ---------------- | -------------------------- | --------------------------- | +| `tablename` | [Name](/migrations/#types) | Name of the table | +| `column_name` | `string` | Column to alter | +| `column_options` | `object` | Optional new column options | ##### Column Options diff --git a/docs/src/migrations/constraints.md b/docs/src/migrations/constraints.md index 8f42b9767..65d61f351 100644 --- a/docs/src/migrations/constraints.md +++ b/docs/src/migrations/constraints.md @@ -11,11 +11,11 @@ ### Arguments -| Name | Type | Description | -| ----------------- | ------------------------- | ------------------------------------------------------------------------------------------------------------ | -| `tablename` | [Name](/migrations/#type) | Name of the table to alter | -| `constraint_name` | `string` | Name for the constraint | -| `expression` | `string` or `object` | Constraint expression (raw sql) or definition -- see [constraint definition section](#constraint-definition) | +| Name | Type | Description | +| ----------------- | -------------------------- | ------------------------------------------------------------------------------------------------------------ | +| `tablename` | [Name](/migrations/#types) | Name of the table to alter | +| `constraint_name` | `string` | Name for the constraint | +| `expression` | `string` or `object` | Constraint expression (raw sql) or definition -- see [constraint definition section](#constraint-definition) | #### Constraint Definition @@ -32,15 +32,15 @@ #### Foreign Keys -| Option | Type | Description | -| ----------------------------- | -------------------------------- | ---------------------------------------------------------------------------------- | -| `columns` | `Name` or `array of Names` | Names of columns | -| `references` | [`Reference`](/migrations/#type) | Names of foreign table and column names | -| `referencesConstraintName` | `string` | Name of the created constraint (only necessary when creating multiple constraints) | -| `referencesConstraintComment` | `string` | Comment on the individual foreign key constraint | -| `onDelete` | `string` | Action to perform on delete | -| `onUpdate` | `string` | Action to perform on update | -| `match` | `string` | `FULL` or `SIMPLE` | +| Option | Type | Description | +| ----------------------------- | --------------------------------- | ---------------------------------------------------------------------------------- | +| `columns` | `Name` or `array of Names` | Names of columns | +| `references` | [`Reference`](/migrations/#types) | Names of foreign table and column names | +| `referencesConstraintName` | `string` | Name of the created constraint (only necessary when creating multiple constraints) | +| `referencesConstraintComment` | `string` | Comment on the individual foreign key constraint | +| `onDelete` | `string` | Action to perform on delete | +| `onUpdate` | `string` | Action to perform on update | +| `match` | `string` | `FULL` or `SIMPLE` | ## Reverse Operation: `dropConstraint` @@ -51,11 +51,11 @@ ### Arguments -| Name | Type | Description | -| ----------------- | ------------------------- | --------------------------------- | -| `tablename` | [Name](/migrations/#type) | Name of the table to alter | -| `constraint_name` | `string` | Name of the constraint | -| `options` | `object` | Check below for available options | +| Name | Type | Description | +| ----------------- | -------------------------- | --------------------------------- | +| `tablename` | [Name](/migrations/#types) | Name of the table to alter | +| `constraint_name` | `string` | Name of the constraint | +| `options` | `object` | Check below for available options | #### Options @@ -75,8 +75,8 @@ ### Arguments -| Name | Type | Description | -| --------------------- | ------------------------- | -------------------------- | -| `tablename` | [Name](/migrations/#type) | Name of the table to alter | -| `old_constraint_name` | `string` | Current constraint name | -| `new_constraint_name` | `string` | New constraint name | +| Name | Type | Description | +| --------------------- | -------------------------- | -------------------------- | +| `tablename` | [Name](/migrations/#types) | Name of the table to alter | +| `old_constraint_name` | `string` | Current constraint name | +| `new_constraint_name` | `string` | New constraint name | diff --git a/docs/src/migrations/domains.md b/docs/src/migrations/domains.md index c57efc4f2..92d68540e 100644 --- a/docs/src/migrations/domains.md +++ b/docs/src/migrations/domains.md @@ -9,11 +9,11 @@ ### Arguments -| Name | Type | Description | -| ------------- | ------------------------- | --------------------------------- | -| `domain_name` | [Name](/migrations/#type) | Name of the new domain | -| `type` | `string` | Type of the new domain | -| `options` | `object` | Check below for available options | +| Name | Type | Description | +| ------------- | -------------------------- | --------------------------------- | +| `domain_name` | [Name](/migrations/#types) | Name of the new domain | +| `type` | `string` | Type of the new domain | +| `options` | `object` | Check below for available options | #### Options @@ -34,10 +34,10 @@ ### Arguments -| Name | Type | Description | -| -------------- | ------------------------- | --------------------------------- | -| `domain_name` | [Name](/migrations/#type) | Name of the domain to drop | -| `drop_options` | `object` | Check below for available options | +| Name | Type | Description | +| -------------- | -------------------------- | --------------------------------- | +| `domain_name` | [Name](/migrations/#types) | Name of the domain to drop | +| `drop_options` | `object` | Check below for available options | #### Options @@ -55,10 +55,10 @@ ### Arguments -| Name | Type | Description | -| ------------- | ------------------------- | --------------------------------- | -| `domain_name` | [Name](/migrations/#type) | Name of the new domain | -| `options` | `object` | Check below for available options | +| Name | Type | Description | +| ------------- | -------------------------- | --------------------------------- | +| `domain_name` | [Name](/migrations/#types) | Name of the new domain | +| `options` | `object` | Check below for available options | #### Options @@ -80,7 +80,7 @@ ### Arguments -| Name | Type | Description | -| ----------------- | ------------------------- | ---------------------- | -| `old_domain_name` | [Name](/migrations/#type) | Old name of the domain | -| `new_domain_name` | [Name](/migrations/#type) | New name of the domain | +| Name | Type | Description | +| ----------------- | -------------------------- | ---------------------- | +| `old_domain_name` | [Name](/migrations/#types) | Old name of the domain | +| `new_domain_name` | [Name](/migrations/#types) | New name of the domain | diff --git a/docs/src/migrations/functions.md b/docs/src/migrations/functions.md index 71c83ee4e..795acb48f 100644 --- a/docs/src/migrations/functions.md +++ b/docs/src/migrations/functions.md @@ -11,7 +11,7 @@ | Name | Type | Description | | ------------------ | ------------------------------- | --------------------------------- | -| `function_name` | [Name](/migrations/#type) | name of the new function | +| `function_name` | [Name](/migrations/#types) | name of the new function | | `function_params` | `array[string]` `array[object]` | parameters of the new function | | `function_options` | `object` | Check below for available options | | `definition` | `string` | definition of function | @@ -52,7 +52,7 @@ If array of strings, it is interpreted as is, if array of objects: | Name | Type | Description | | ----------------- | ------------------------------- | --------------------------------- | -| `function_name` | [Name](/migrations/#type) | name of the function to drop | +| `function_name` | [Name](/migrations/#types) | name of the function to drop | | `function_params` | `array[string]` `array[object]` | parameters of the function | | `drop_options` | `object` | Check below for available options | @@ -74,6 +74,6 @@ If array of strings, it is interpreted as is, if array of objects: | Name | Type | Description | | ------------------- | ------------------------------- | -------------------------- | -| `old_function_name` | [Name](/migrations/#type) | old name of the function | +| `old_function_name` | [Name](/migrations/#types) | old name of the function | | `function_params` | `array[string]` `array[object]` | parameters of the function | -| `new_function_name` | [Name](/migrations/#type) | new name of the function | +| `new_function_name` | [Name](/migrations/#types) | new name of the function | diff --git a/docs/src/migrations/grants.md b/docs/src/migrations/grants.md index cf6652731..856031939 100644 --- a/docs/src/migrations/grants.md +++ b/docs/src/migrations/grants.md @@ -9,11 +9,11 @@ ### Arguments -| Name | Type | Description | -| --------------------- | ------------------------------------------ | --------------------------------- | -| `roles_from` | [Name](/migrations/#type) or `array[Name]` | Names of roles | -| `roles_to` | [Name](/migrations/#type) or `array[Name]` | Names of roles | -| `grant_roles_options` | `object` | Check below for available options | +| Name | Type | Description | +| --------------------- | ------------------------------------------- | --------------------------------- | +| `roles_from` | [Name](/migrations/#types) or `array[Name]` | Names of roles | +| `roles_to` | [Name](/migrations/#types) or `array[Name]` | Names of roles | +| `grant_roles_options` | `object` | Check below for available options | #### grant_roles_options @@ -32,11 +32,11 @@ ### Arguments -| Name | Type | Description | -| -------------- | ------------------------------------------ | --------------------------------- | -| `roles` | [Name](/migrations/#type) or `array[Name]` | Names of roles | -| `roles_from` | [Name](/migrations/#type) or `array[Name]` | Names of roles | -| `drop_options` | `object` | Check below for available options | +| Name | Type | Description | +| -------------- | ------------------------------------------- | --------------------------------- | +| `roles` | [Name](/migrations/#types) or `array[Name]` | Names of roles | +| `roles_from` | [Name](/migrations/#types) or `array[Name]` | Names of roles | +| `drop_options` | `object` | Check below for available options | #### drop_options @@ -60,14 +60,14 @@ #### grant_options -| Option | Type | Description | -| ----------------- | ------------------------------------------ | ------------------------------------------- | -| `tables` | [Name](/migrations/#type) or `array[Name]` | Names of tables | -| `schema` | `string` | if tables ALL, then schema name is required | -| `privileges` | `array[TablePrivileges]` or `ALL` | list of privileges | -| `roles` | [Name](/migrations/#type) or `array[Name]` | names of roles | -| `withGrantOption` | `boolean` | default `false` | -| `cascade` | `boolean` | default `false` | +| Option | Type | Description | +| ----------------- | ------------------------------------------- | ------------------------------------------- | +| `tables` | [Name](/migrations/#types) or `array[Name]` | Names of tables | +| `schema` | `string` | if tables ALL, then schema name is required | +| `privileges` | `array[TablePrivileges]` or `ALL` | list of privileges | +| `roles` | [Name](/migrations/#types) or `array[Name]` | names of roles | +| `withGrantOption` | `boolean` | default `false` | +| `cascade` | `boolean` | default `false` | ## Reverse Operation: `revokeOnTables` @@ -84,14 +84,14 @@ #### revoke_options -| Option | Type | Description | -| ----------------- | ------------------------------------------ | ------------------------------------------- | -| `tables` | [Name](/migrations/#type) or `array[Name]` | Names of tables | -| `schema` | `string` | if tables ALL, then schema name is required | -| `privileges` | `array[TablePrivileges]` or `ALL` | list of privileges | -| `roles` | [Name](/migrations/#type) or `array[Name]` | names of roles | -| `withGrantOption` | `boolean` | default `false` | -| `cascade` | `boolean` | drops also dependent objects | +| Option | Type | Description | +| ----------------- | ------------------------------------------- | ------------------------------------------- | +| `tables` | [Name](/migrations/#types) or `array[Name]` | Names of tables | +| `schema` | `string` | if tables ALL, then schema name is required | +| `privileges` | `array[TablePrivileges]` or `ALL` | list of privileges | +| `roles` | [Name](/migrations/#types) or `array[Name]` | names of roles | +| `withGrantOption` | `boolean` | default `false` | +| `cascade` | `boolean` | drops also dependent objects | ## Operation: `grantOnSchemas` @@ -108,14 +108,14 @@ #### grant_options -| Option | Type | Description | -| ----------------- | ------------------------------------------ | ------------------ | -| `schemas` | [Name](/migrations/#type) or `array[Name]` | Names of schemas | -| `privileges` | `array[SchemaPrivileges]` or `ALL` | list of privileges | -| `roles` | [Name](/migrations/#type) or `array[Name]` | names of roles | -| `withGrantOption` | `boolean` | default `false` | -| `onlyGrantOption` | `boolean` | default `false` | -| `cascade` | `boolean` | default `false` | +| Option | Type | Description | +| ----------------- | ------------------------------------------- | ------------------ | +| `schemas` | [Name](/migrations/#types) or `array[Name]` | Names of schemas | +| `privileges` | `array[SchemaPrivileges]` or `ALL` | list of privileges | +| `roles` | [Name](/migrations/#types) or `array[Name]` | names of roles | +| `withGrantOption` | `boolean` | default `false` | +| `onlyGrantOption` | `boolean` | default `false` | +| `cascade` | `boolean` | default `false` | ## Reverse Operation: `revokeOnSchemas` @@ -132,11 +132,11 @@ #### revoke_options -| Option | Type | Description | -| ----------------- | ------------------------------------------ | ---------------------------- | -| `schemas` | [Name](/migrations/#type) or `array[Name]` | Names of schemas | -| `privileges` | `array[SchemaPrivileges]` or `ALL` | list of privileges | -| `roles` | [Name](/migrations/#type) or `array[Name]` | names of roles | -| `withGrantOption` | `boolean` | default `false` | -| `onlyGrantOption` | `boolean` | default `false` | -| `cascade` | `boolean` | drops also dependent objects | +| Option | Type | Description | +| ----------------- | ------------------------------------------- | ---------------------------- | +| `schemas` | [Name](/migrations/#types) or `array[Name]` | Names of schemas | +| `privileges` | `array[SchemaPrivileges]` or `ALL` | list of privileges | +| `roles` | [Name](/migrations/#types) or `array[Name]` | names of roles | +| `withGrantOption` | `boolean` | default `false` | +| `onlyGrantOption` | `boolean` | default `false` | +| `cascade` | `boolean` | drops also dependent objects | diff --git a/docs/src/migrations/index.md b/docs/src/migrations/index.md index a327a8b47..b45800d16 100644 --- a/docs/src/migrations/index.md +++ b/docs/src/migrations/index.md @@ -111,7 +111,7 @@ CREATE TABLE "my_schema"."my_table_name" ( ); ``` -### Type +### Types ```ts type Name = string | { schema: string; name: string }; diff --git a/docs/src/migrations/indexes.md b/docs/src/migrations/indexes.md index 909290fef..66f879b86 100644 --- a/docs/src/migrations/indexes.md +++ b/docs/src/migrations/indexes.md @@ -12,7 +12,7 @@ | Name | Type | Description | | ----------- | --------------------------- | ----------------------------------------------------------------- | -| `tablename` | [Name](/migrations/#type) | name of the table to alter | +| `tablename` | [Name](/migrations/#types) | name of the table to alter | | `columns` | `string` or `array[string]` | columns to add to the index with optional operator class and sort | | `options` | `object` | Check below for available options | @@ -70,7 +70,7 @@ pgm.createIndex('table', [ | Name | Type | Description | | ----------- | --------------------------- | ---------------------------------------------- | -| `tablename` | [Name](/migrations/#type) | name of the table to alter | +| `tablename` | [Name](/migrations/#types) | name of the table to alter | | `columns` | `string` or `array[string]` | column names, used only to infer an index name | | `options` | `object` | Check below for available options | diff --git a/docs/src/migrations/mViews.md b/docs/src/migrations/mViews.md index 586539ace..71b4f1cb0 100644 --- a/docs/src/migrations/mViews.md +++ b/docs/src/migrations/mViews.md @@ -112,10 +112,10 @@ ### Arguments -| Name | Type | Description | -| ---------- | -------- | ------------------------------------------------ | -| `viewName` | `string` | [Name](/migrations/#type) of the view to refresh | -| `options` | `object` | Check below for available options | +| Name | Type | Description | +| ---------- | -------- | ------------------------------------------------- | +| `viewName` | `string` | [Name](/migrations/#types) of the view to refresh | +| `options` | `object` | Check below for available options | ### Options diff --git a/docs/src/migrations/operators.md b/docs/src/migrations/operators.md index e29f7164d..19b12a0e1 100644 --- a/docs/src/migrations/operators.md +++ b/docs/src/migrations/operators.md @@ -9,24 +9,24 @@ ### Arguments -| Name | Type | Description | -| --------------- | ------------------------- | --------------------------------- | -| `operator_name` | [Name](/migrations/#type) | name of the new operator | -| `options` | `object` | Check below for available options | +| Name | Type | Description | +| --------------- | -------------------------- | --------------------------------- | +| `operator_name` | [Name](/migrations/#types) | name of the new operator | +| `options` | `object` | Check below for available options | ### Options -| Option | Type | Description | -| ------------ | ------------------------- | -------------------------------------- | -| `procedure` | [Name](/migrations/#type) | name of procedure performing operation | -| `left` | [Name](/migrations/#type) | type of left argument | -| `right` | [Name](/migrations/#type) | type of right argument | -| `commutator` | [Name](/migrations/#type) | name of commutative operator | -| `negator` | [Name](/migrations/#type) | name of negating operator | -| `restrict` | [Name](/migrations/#type) | name of restriction procedure | -| `join` | [Name](/migrations/#type) | name of join procedure | -| `hashes` | `boolean` | adds `HASHES` clause | -| `merges` | `boolean` | adds `MERGES` clause | +| Option | Type | Description | +| ------------ | -------------------------- | -------------------------------------- | +| `procedure` | [Name](/migrations/#types) | name of procedure performing operation | +| `left` | [Name](/migrations/#types) | type of left argument | +| `right` | [Name](/migrations/#types) | type of right argument | +| `commutator` | [Name](/migrations/#types) | name of commutative operator | +| `negator` | [Name](/migrations/#types) | name of negating operator | +| `restrict` | [Name](/migrations/#types) | name of restriction procedure | +| `join` | [Name](/migrations/#types) | name of join procedure | +| `hashes` | `boolean` | adds `HASHES` clause | +| `merges` | `boolean` | adds `MERGES` clause | ## Reverse Operation: `dropOperator` @@ -37,19 +37,19 @@ ### Arguments -| Name | Type | Description | -| --------------- | ------------------------- | --------------------------------- | -| `operator_name` | [Name](/migrations/#type) | name of the operator to drop | -| `drop_options` | `object` | Check below for available options | +| Name | Type | Description | +| --------------- | -------------------------- | --------------------------------- | +| `operator_name` | [Name](/migrations/#types) | name of the operator to drop | +| `drop_options` | `object` | Check below for available options | ### Options -| Option | Type | Description | -| ---------- | ------------------------- | ------------------------------ | -| `ifExists` | `boolean` | drops schema only if it exists | -| `cascade` | `boolean` | drops also dependent objects | -| `left` | [Name](/migrations/#type) | type of left argument | -| `right` | [Name](/migrations/#type) | type of right argument | +| Option | Type | Description | +| ---------- | -------------------------- | ------------------------------ | +| `ifExists` | `boolean` | drops schema only if it exists | +| `cascade` | `boolean` | drops also dependent objects | +| `left` | [Name](/migrations/#types) | type of left argument | +| `right` | [Name](/migrations/#types) | type of right argument | ## Operation: `renameOperator` @@ -60,13 +60,13 @@ ### Arguments -| Name | Type | Description | -| --------------------- | ------------------------- | ------------------------------------------------- | -| `operator_class_name` | [Name](/migrations/#type) | name of the new operator class | -| `type` | `string` | data type of the new operator class | -| `index_method` | [Name](/migrations/#type) | name of the index method of operator class | -| `operator_list` | `array` | of [operator objects](#operator-list-definitions) | -| `options` | `object` | Check below for available options | +| Name | Type | Description | +| --------------------- | -------------------------- | ------------------------------------------------- | +| `operator_class_name` | [Name](/migrations/#types) | name of the new operator class | +| `type` | `string` | data type of the new operator class | +| `index_method` | [Name](/migrations/#types) | name of the index method of operator class | +| `operator_list` | `array` | of [operator objects](#operator-list-definitions) | +| `options` | `object` | Check below for available options | ### Options @@ -84,11 +84,11 @@ ### Arguments -| Name | Type | Description | -| --------------------- | ------------------------- | ------------------------------------------ | -| `operator_class_name` | [Name](/migrations/#type) | name of the operator class to drop | -| `index_method` | [Name](/migrations/#type) | name of the index method of operator class | -| `drop_options` | `object` | Check below for available options | +| Name | Type | Description | +| --------------------- | -------------------------- | ------------------------------------------ | +| `operator_class_name` | [Name](/migrations/#types) | name of the operator class to drop | +| `index_method` | [Name](/migrations/#types) | name of the index method of operator class | +| `drop_options` | `object` | Check below for available options | ### Options @@ -106,11 +106,11 @@ ### Arguments -| Name | Type | Description | -| ------------------------- | ------------------------- | ------------------------------------------ | -| `old_operator_class_name` | [Name](/migrations/#type) | old name of the operator class | -| `index_method` | [Name](/migrations/#type) | name of the index method of operator class | -| `new_operator_class_name` | [Name](/migrations/#type) | new name of the operator class | +| Name | Type | Description | +| ------------------------- | -------------------------- | ------------------------------------------ | +| `old_operator_class_name` | [Name](/migrations/#types) | old name of the operator class | +| `index_method` | [Name](/migrations/#types) | name of the index method of operator class | +| `new_operator_class_name` | [Name](/migrations/#types) | new name of the operator class | ## Operation: `alterOperatorClass` @@ -121,10 +121,10 @@ ### Arguments -| Name | Type | Description | -| ---------------------- | ------------------------- | ------------------------------------------- | -| `operator_family_name` | [Name](/migrations/#type) | name of the new operator family | -| `index_method` | [Name](/migrations/#type) | name of the index method of operator family | +| Name | Type | Description | +| ---------------------- | -------------------------- | ------------------------------------------- | +| `operator_family_name` | [Name](/migrations/#types) | name of the new operator family | +| `index_method` | [Name](/migrations/#types) | name of the index method of operator family | ## Reverse Operation: `dropOperatorFamily` @@ -135,11 +135,11 @@ ### Arguments -| Name | Type | Description | -| ---------------------- | ------------------------- | ------------------------------------------- | -| `operator_family_name` | [Name](/migrations/#type) | name of the operator family to drop | -| `index_method` | [Name](/migrations/#type) | name of the index method of operator family | -| `drop_options` | `object` | Check below for available options | +| Name | Type | Description | +| ---------------------- | -------------------------- | ------------------------------------------- | +| `operator_family_name` | [Name](/migrations/#types) | name of the operator family to drop | +| `index_method` | [Name](/migrations/#types) | name of the index method of operator family | +| `drop_options` | `object` | Check below for available options | ### Options @@ -157,11 +157,11 @@ ### Arguments -| Name | Type | Description | -| -------------------------- | ------------------------- | ------------------------------------------- | -| `old_operator_family_name` | [Name](/migrations/#type) | old name of the operator family | -| `index_method` | [Name](/migrations/#type) | name of the index method of operator family | -| `new_operator_family_name` | [Name](/migrations/#type) | new name of the operator family | +| Name | Type | Description | +| -------------------------- | -------------------------- | ------------------------------------------- | +| `old_operator_family_name` | [Name](/migrations/#types) | old name of the operator family | +| `index_method` | [Name](/migrations/#types) | name of the index method of operator family | +| `new_operator_family_name` | [Name](/migrations/#types) | new name of the operator family | ## Operation: `alterOperatorFamily` @@ -172,11 +172,11 @@ ### Arguments -| Name | Type | Description | -| ---------------------- | ------------------------- | ------------------------------------------------- | -| `operator_family_name` | [Name](/migrations/#type) | name of the operator family | -| `index_method` | [Name](/migrations/#type) | name of the index method of operator family | -| `operator_list` | `array` | of [operator objects](#operator-list-definitions) | +| Name | Type | Description | +| ---------------------- | -------------------------- | ------------------------------------------------- | +| `operator_family_name` | [Name](/migrations/#types) | name of the operator family | +| `index_method` | [Name](/migrations/#types) | name of the index method of operator family | +| `operator_list` | `array` | of [operator objects](#operator-list-definitions) | ## Reverse Operation: `dropFromOperatorFamily` @@ -187,20 +187,20 @@ ### Arguments -| Name | Type | Description | -| ---------------------- | ------------------------- | ------------------------------------------------- | -| `operator_family_name` | [Name](/migrations/#type) | name of the operator family | -| `index_method` | [Name](/migrations/#type) | name of the index method of operator family | -| `operator_list` | `array` | of [operator objects](#operator-list-definitions) | +| Name | Type | Description | +| ---------------------- | -------------------------- | ------------------------------------------------- | +| `operator_family_name` | [Name](/migrations/#types) | name of the operator family | +| `index_method` | [Name](/migrations/#types) | name of the index method of operator family | +| `operator_list` | `array` | of [operator objects](#operator-list-definitions) | ## Operator List Definitions Some functions for defining operators take as parameter `operator_list` which is array of objects with the following structure: -| Name | Type | Description | -| -------- | ------------------------- | ----------------------------------------------- | -| `type` | `string` | `function` or `operator` | -| `number` | `number` | index | -| `name` | [Name](/migrations/#type) | name of operator or procedure | -| `params` | `array` | list of argument types of operator or procedure | +| Name | Type | Description | +| -------- | -------------------------- | ----------------------------------------------- | +| `type` | `string` | `function` or `operator` | +| `number` | `number` | index | +| `name` | [Name](/migrations/#types) | name of operator or procedure | +| `params` | `array` | list of argument types of operator or procedure | diff --git a/docs/src/migrations/policies.md b/docs/src/migrations/policies.md index f1d315180..ed00988e6 100644 --- a/docs/src/migrations/policies.md +++ b/docs/src/migrations/policies.md @@ -9,11 +9,11 @@ ### Arguments -| Name | Type | Description | -| ------------ | ------------------------- | --------------------------------- | -| `tableName` | [Name](/migrations/#type) | name of the table to alter | -| `policyName` | `string` | name of the new policy | -| `options` | `object` | Check below for available options | +| Name | Type | Description | +| ------------ | -------------------------- | --------------------------------- | +| `tableName` | [Name](/migrations/#types) | name of the table to alter | +| `policyName` | `string` | name of the new policy | +| `options` | `object` | Check below for available options | #### Options @@ -33,11 +33,11 @@ ### Arguments -| Name | Type | Description | -| ------------ | ------------------------- | ------------------------------------- | -| `tableName` | [Name](/migrations/#type) | name of the table where the policy is | -| `policyName` | `string` | name of the policy to delete | -| `options` | `object` | Check below for available options | +| Name | Type | Description | +| ------------ | -------------------------- | ------------------------------------- | +| `tableName` | [Name](/migrations/#types) | name of the table where the policy is | +| `policyName` | `string` | name of the policy to delete | +| `options` | `object` | Check below for available options | #### Options @@ -54,11 +54,11 @@ ### Arguments -| Name | Type | Description | -| ------------ | ------------------------- | ------------------------------------- | -| `tableName` | [Name](/migrations/#type) | name of the table where the policy is | -| `policyName` | `string` | name of the policy to alter | -| `options` | `object` | Check below for available options | +| Name | Type | Description | +| ------------ | -------------------------- | ------------------------------------- | +| `tableName` | [Name](/migrations/#types) | name of the table where the policy is | +| `policyName` | `string` | name of the policy to alter | +| `options` | `object` | Check below for available options | #### Options @@ -77,8 +77,8 @@ ### Arguments -| Name | Type | Description | -| --------------- | ------------------------- | ------------------------------------- | -| `tableName` | [Name](/migrations/#type) | name of the table where the policy is | -| `policyName` | `string` | old name of the policy | -| `newPolicyName` | `string` | new name of the policy | +| Name | Type | Description | +| --------------- | -------------------------- | ------------------------------------- | +| `tableName` | [Name](/migrations/#types) | name of the table where the policy is | +| `policyName` | `string` | old name of the policy | +| `newPolicyName` | `string` | new name of the policy | diff --git a/docs/src/migrations/roles.md b/docs/src/migrations/roles.md index f1f916b6a..0aafe2933 100644 --- a/docs/src/migrations/roles.md +++ b/docs/src/migrations/roles.md @@ -9,10 +9,10 @@ ### Arguments -| Name | Type | Description | -| -------------- | ------------------------- | --------------------------------- | -| `role_name` | [Name](/migrations/#type) | name of the new role | -| `role_options` | `object` | Check below for available options | +| Name | Type | Description | +| -------------- | -------------------------- | --------------------------------- | +| `role_name` | [Name](/migrations/#types) | name of the new role | +| `role_options` | `object` | Check below for available options | ### role_options @@ -42,9 +42,9 @@ ### Arguments -| Name | Type | Description | -| ----------- | ------------------------- | ------------------------ | -| `role_name` | [Name](/migrations/#type) | name of the role to drop | +| Name | Type | Description | +| ----------- | -------------------------- | ------------------------ | +| `role_name` | [Name](/migrations/#types) | name of the role to drop | ## Operation: `alterRole` @@ -55,10 +55,10 @@ ### Arguments -| Name | Type | Description | -| -------------- | ------------------------- | -------------------- | -| `role_name` | [Name](/migrations/#type) | name of the role | -| `role_options` | `object` | [see](#role_options) | +| Name | Type | Description | +| -------------- | -------------------------- | -------------------- | +| `role_name` | [Name](/migrations/#types) | name of the role | +| `role_options` | `object` | [see](#role_options) | ## Operation: `renameRole` @@ -69,7 +69,7 @@ ### Arguments -| Name | Type | Description | -| --------------- | ------------------------- | -------------------- | -| `old_role_name` | [Name](/migrations/#type) | old name of the role | -| `new_role_name` | [Name](/migrations/#type) | new name of the role | +| Name | Type | Description | +| --------------- | -------------------------- | -------------------- | +| `old_role_name` | [Name](/migrations/#types) | old name of the role | +| `new_role_name` | [Name](/migrations/#types) | new name of the role | diff --git a/docs/src/migrations/sequences.md b/docs/src/migrations/sequences.md index 92d47f402..002f35d62 100644 --- a/docs/src/migrations/sequences.md +++ b/docs/src/migrations/sequences.md @@ -89,7 +89,7 @@ sequence. ### Arguments -| Name | Type | Description | -| ------------------- | -------- | --------------------------------------------- | -| `old_sequence_name` | `string` | old [Name](/migrations/#type) of the sequence | -| `new_sequence_name` | `string` | new [Name](/migrations/#type) of the sequence | +| Name | Type | Description | +| ------------------- | -------- | ---------------------------------------------- | +| `old_sequence_name` | `string` | old [Name](/migrations/#types) of the sequence | +| `new_sequence_name` | `string` | new [Name](/migrations/#types) of the sequence | diff --git a/docs/src/migrations/tables.md b/docs/src/migrations/tables.md index 26f3358af..89942010c 100644 --- a/docs/src/migrations/tables.md +++ b/docs/src/migrations/tables.md @@ -9,23 +9,23 @@ ### Arguments -| Name | Type | Description | -| ----------- | ------------------------- | ----------------------------------------------------------------------------------------- | -| `tablename` | [Name](/migrations/#type) | name for the new table | -| `columns` | `object` | column names / options -- see [column definitions section](columns.md#column-definitions) | -| `options` | `object` | table options (optional) | +| Name | Type | Description | +| ----------- | -------------------------- | ----------------------------------------------------------------------------------------- | +| `tablename` | [Name](/migrations/#types) | name for the new table | +| `columns` | `object` | column names / options -- see [column definitions section](columns.md#column-definitions) | +| `options` | `object` | table options (optional) | ### Options -| Option | Type | Description | -| ------------- | ------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------- | -| `temporary` | `boolean` | default `false` | -| `ifNotExists` | `boolean` | default `false` | -| `inherits` | [Name](/migrations/#type) | table(s) to inherit from | -| `constraints` | `object` | table constraints see `expression` of [add constraint](constraints.md#pgmaddconstraint-tablename-constraint_name-expression-) | -| `like` | [Name](/migrations/#type) or `object` | table(s) to inherit from or object with `table` and `options` keys | -| `comment` | `string` | adds comment on table | -| `unlogged` | `boolean` | default `false` | +| Option | Type | Description | +| ------------- | -------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------- | +| `temporary` | `boolean` | default `false` | +| `ifNotExists` | `boolean` | default `false` | +| `inherits` | [Name](/migrations/#types) | table(s) to inherit from | +| `constraints` | `object` | table constraints see `expression` of [add constraint](constraints.md#pgmaddconstraint-tablename-constraint_name-expression-) | +| `like` | [Name](/migrations/#types) 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 @@ -43,10 +43,10 @@ ### Arguments -| Name | Type | Description | -| ----------- | ------------------------- | --------------------------------- | -| `tablename` | [Name](/migrations/#type) | name of the table to drop | -| `options` | `object` | Check below for available options | +| Name | Type | Description | +| ----------- | -------------------------- | --------------------------------- | +| `tablename` | [Name](/migrations/#types) | name of the table to drop | +| `options` | `object` | Check below for available options | ### Options @@ -66,10 +66,10 @@ ### Arguments -| Name | Type | Description | -| --------------- | ------------------------- | --------------------------- | -| `tablename` | [Name](/migrations/#type) | name of the table to rename | -| `new_tablename` | [Name](/migrations/#type) | new name of the table | +| Name | Type | Description | +| --------------- | -------------------------- | --------------------------- | +| `tablename` | [Name](/migrations/#types) | name of the table to rename | +| `new_tablename` | [Name](/migrations/#types) | new name of the table | ## Operation: `alterTable` @@ -80,10 +80,10 @@ ### Arguments -| Name | Type | Description | -| ----------- | ------------------------- | --------------------------------- | -| `tablename` | [Name](/migrations/#type) | name of the table to alter | -| `options` | `object` | Check below for available options | +| Name | Type | Description | +| ----------- | -------------------------- | --------------------------------- | +| `tablename` | [Name](/migrations/#types) | name of the table to alter | +| `options` | `object` | Check below for available options | ### Options diff --git a/docs/src/migrations/triggers.md b/docs/src/migrations/triggers.md index f4e900756..d8d1ce1c3 100644 --- a/docs/src/migrations/triggers.md +++ b/docs/src/migrations/triggers.md @@ -9,26 +9,26 @@ ### Arguments -| Name | Type | Description | -| ----------------- | ------------------------- | ------------------------------------------------------------------------------- | -| `table_name` | [Name](/migrations/#type) | Name of the table where the new trigger will live | -| `trigger_name` | `string` | Name of the new trigger | -| `trigger_options` | `object` | Check below for available options | -| `definition` | `string` | Optional definition of function which will be created with same name as trigger | +| Name | Type | Description | +| ----------------- | -------------------------- | ------------------------------------------------------------------------------- | +| `table_name` | [Name](/migrations/#types) | Name of the table where the new trigger will live | +| `trigger_name` | `string` | Name of the new trigger | +| `trigger_options` | `object` | Check below for available options | +| `definition` | `string` | Optional definition of function which will be created with same name as trigger | #### Trigger Options: -| Option | Type | Description | -| ---------------- | ------------------------- | --------------------------------------------------------- | -| `when` | `string` | `BEFORE`, `AFTER`, or `INSTEAD OF` | -| `operation` | `string or array[string]` | `INSERT`, `UPDATE[ OF ...]`, `DELETE` or `TRUNCATE` | -| `constraint` | `boolean` | Creates constraint trigger | -| `function` | [Name](/migrations/#type) | The name of procedure to execute | -| `functionParams` | `array` | Parameters of the procedure | -| `level` | `string` | `STATEMENT`, or `ROW` | -| `condition` | `string` | Condition to met to execute trigger | -| `deferrable` | `boolean` | Flag for deferrable constraint trigger | -| `deferred` | `boolean` | Flag for initially deferred deferrable constraint trigger | +| Option | Type | Description | +| ---------------- | -------------------------- | --------------------------------------------------------- | +| `when` | `string` | `BEFORE`, `AFTER`, or `INSTEAD OF` | +| `operation` | `string or array[string]` | `INSERT`, `UPDATE[ OF ...]`, `DELETE` or `TRUNCATE` | +| `constraint` | `boolean` | Creates constraint trigger | +| `function` | [Name](/migrations/#types) | The name of procedure to execute | +| `functionParams` | `array` | Parameters of the procedure | +| `level` | `string` | `STATEMENT`, or `ROW` | +| `condition` | `string` | Condition to met to execute trigger | +| `deferrable` | `boolean` | Flag for deferrable constraint trigger | +| `deferred` | `boolean` | Flag for initially deferred deferrable constraint trigger | ## Reverse Operation: `dropTrigger` @@ -39,11 +39,11 @@ ### Arguments -| Name | Type | Description | -| -------------- | ------------------------- | ----------------------------------------- | -| `table_name` | [Name](/migrations/#type) | Name of the table where the trigger lives | -| `trigger_name` | `string` | Name of the trigger to drop | -| `drop_options` | `object` | Check below for available options | +| Name | Type | Description | +| -------------- | -------------------------- | ----------------------------------------- | +| `table_name` | [Name](/migrations/#types) | Name of the table where the trigger lives | +| `trigger_name` | `string` | Name of the trigger to drop | +| `drop_options` | `object` | Check below for available options | #### Drop Options: @@ -61,8 +61,8 @@ ### Arguments -| Name | Type | Description | -| ------------------ | ------------------------- | ----------------------------------------- | -| `table_name` | [Name](/migrations/#type) | Name of the table where the trigger lives | -| `old_trigger_name` | `string` | Old name of the trigger | -| `new_trigger_name` | `string` | New name of the trigger | +| Name | Type | Description | +| ------------------ | -------------------------- | ----------------------------------------- | +| `table_name` | [Name](/migrations/#types) | Name of the table where the trigger lives | +| `old_trigger_name` | `string` | Old name of the trigger | +| `new_trigger_name` | `string` | New name of the trigger | diff --git a/docs/src/migrations/types.md b/docs/src/migrations/types.md index 93804ba7b..edf86896f 100644 --- a/docs/src/migrations/types.md +++ b/docs/src/migrations/types.md @@ -12,7 +12,7 @@ | Name | Type | Description | | ----------- | --------------------------- | ------------------------------------------------------------------------ | -| `type_name` | [Name](/migrations/#type) | name of the new type | +| `type_name` | [Name](/migrations/#types) | name of the new type | | `values` | `array[string]` or `object` | possible values for an enum type or names and types for a composite type | ## Reverse Operation: `dropType` @@ -24,9 +24,9 @@ ### Arguments -| Name | Type | Description | -| ----------- | ------------------------- | ------------------------ | -| `type_name` | [Name](/migrations/#type) | name of the type to drop | +| Name | Type | Description | +| ----------- | -------------------------- | ------------------------ | +| `type_name` | [Name](/migrations/#types) | name of the type to drop | ## Operation: `alterType` @@ -37,10 +37,10 @@ ### Arguments -| Name | Type | Description | -| --------------- | ------------------------- | -------------------------- | -| `type_name` | [Name](/migrations/#type) | name of the type to rename | -| `new_type_name` | [Name](/migrations/#type) | name of the new type | +| Name | Type | Description | +| --------------- | -------------------------- | -------------------------- | +| `type_name` | [Name](/migrations/#types) | name of the type to rename | +| `new_type_name` | [Name](/migrations/#types) | name of the new type | ## Operation: `alterType` @@ -52,11 +52,11 @@ ### Arguments -| Name | Type | Description | -| ---------------- | ------------------------- | ---------------------------- | -| `type_name` | [Name](/migrations/#type) | name of the type | -| `attribute_name` | `string` | name of the attribute to add | -| `attribute_type` | `string` | type of the attribute to add | +| Name | Type | Description | +| ---------------- | -------------------------- | ---------------------------- | +| `type_name` | [Name](/migrations/#types) | name of the type | +| `attribute_name` | `string` | name of the attribute to add | +| `attribute_type` | `string` | type of the attribute to add | ## Reverse Operation: `dropTypeAttribute` @@ -67,11 +67,11 @@ ### Arguments -| Name | Type | Description | -| ---------------- | ------------------------- | --------------------------------- | -| `type_name` | [Name](/migrations/#type) | name of the type | -| `attribute_name` | `string` | name of the attribute to drop | -| `options` | `object` | Check below for available options | +| Name | Type | Description | +| ---------------- | -------------------------- | --------------------------------- | +| `type_name` | [Name](/migrations/#types) | name of the type | +| `attribute_name` | `string` | name of the attribute to drop | +| `options` | `object` | Check below for available options | ### Options @@ -89,11 +89,11 @@ ### Arguments -| Name | Type | Description | -| ---------------- | ------------------------- | ---------------------------- | -| `type_name` | [Name](/migrations/#type) | name of the type | -| `attribute_name` | `string` | name of the attribute to set | -| `attribute_type` | `string` | new type of the attribute | +| Name | Type | Description | +| ---------------- | -------------------------- | ---------------------------- | +| `type_name` | [Name](/migrations/#types) | name of the type | +| `attribute_name` | `string` | name of the attribute to set | +| `attribute_type` | `string` | new type of the attribute | ## Operation: `alterType` @@ -105,11 +105,11 @@ ### Arguments -| Name | Type | Description | -| ----------- | ------------------------- | --------------------------------- | -| `type_name` | [Name](/migrations/#type) | name of the type | -| `value` | `string` | value to add to list | -| `options` | `object` | Check below for available options | +| Name | Type | Description | +| ----------- | -------------------------- | --------------------------------- | +| `type_name` | [Name](/migrations/#types) | name of the type | +| `value` | `string` | value to add to list | +| `options` | `object` | Check below for available options | ### Options @@ -128,11 +128,11 @@ ### Arguments -| Name | Type | Description | -| -------------------- | ------------------------- | ------------------------------- | -| `type_name` | [Name](/migrations/#type) | name of the type | -| `attribute_name` | `string` | name of the attribute to rename | -| `new_attribute_name` | `string` | new name of the attribute | +| Name | Type | Description | +| -------------------- | -------------------------- | ------------------------------- | +| `type_name` | [Name](/migrations/#types) | name of the type | +| `attribute_name` | `string` | name of the attribute to rename | +| `new_attribute_name` | `string` | new name of the attribute | ## Operation: `alterType` @@ -143,8 +143,8 @@ ### Arguments -| Name | Type | Description | -| ----------- | ------------------------- | ---------------- | -| `type_name` | [Name](/migrations/#type) | name of the type | -| `value` | `string` | value to rename | -| `new_value` | `string` | new value | +| Name | Type | Description | +| ----------- | -------------------------- | ---------------- | +| `type_name` | [Name](/migrations/#types) | name of the type | +| `value` | `string` | value to rename | +| `new_value` | `string` | new value | From 7c21d5cf516f55569c57832563c64a68d32872c2 Mon Sep 17 00:00:00 2001 From: Arttu Manninen Date: Wed, 9 Jul 2025 14:22:25 +0300 Subject: [PATCH 7/8] Create a shallow copy of the reference columns --- src/operations/tables/shared.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/operations/tables/shared.ts b/src/operations/tables/shared.ts index 461f0ac7b..e0e822dd6 100644 --- a/src/operations/tables/shared.ts +++ b/src/operations/tables/shared.ts @@ -145,7 +145,7 @@ export function parseReferences( // Optional column references const columns: string[] = ( - references?.columns == null ? [] : toArray(references.columns) + references.columns == null ? [] : [...toArray(references.columns)] ) .filter((column: string) => column && literal) .map((column: string) => literal(column)); From 2e89fd4b10c974c9a48d7604ed7373ab4e656f36 Mon Sep 17 00:00:00 2001 From: Arttu Manninen Date: Sun, 13 Jul 2025 22:38:54 +0300 Subject: [PATCH 8/8] Readability refactoring, type safety has already been established Co-authored-by: Shinigami --- src/operations/tables/shared.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/operations/tables/shared.ts b/src/operations/tables/shared.ts index e0e822dd6..26d6a5c33 100644 --- a/src/operations/tables/shared.ts +++ b/src/operations/tables/shared.ts @@ -145,10 +145,10 @@ export function parseReferences( // Optional column references const columns: string[] = ( - references.columns == null ? [] : [...toArray(references.columns)] + references.columns == null ? [] as string[] : [...toArray(references.columns)] ) - .filter((column: string) => column && literal) - .map((column: string) => literal(column)); + .filter((column) => column && literal) + .map((column) => literal(column)); const col = columns.length > 0 ? `(${columns.join(', ')})` : '';