@contember/database-migrations 2.2.0-alpha.18 → 2.2.0-alpha.19

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (44) hide show
  1. package/dist/development/index.cjs +3 -1
  2. package/dist/development/index.cjs.map +1 -1
  3. package/dist/development/index.js +3 -1
  4. package/dist/development/index.js.map +1 -1
  5. package/dist/development/src/Migration.cjs.map +1 -1
  6. package/dist/development/src/Migration.js.map +1 -1
  7. package/dist/development/src/MigrationBuilder.cjs +267 -0
  8. package/dist/development/src/MigrationBuilder.cjs.map +1 -0
  9. package/dist/development/src/MigrationBuilder.js +267 -0
  10. package/dist/development/src/MigrationBuilder.js.map +1 -0
  11. package/dist/development/src/helpers.cjs +3 -16
  12. package/dist/development/src/helpers.cjs.map +1 -1
  13. package/dist/development/src/helpers.js +3 -15
  14. package/dist/development/src/helpers.js.map +1 -1
  15. package/dist/production/index.cjs +3 -1
  16. package/dist/production/index.cjs.map +1 -1
  17. package/dist/production/index.js +3 -1
  18. package/dist/production/index.js.map +1 -1
  19. package/dist/production/src/Migration.cjs.map +1 -1
  20. package/dist/production/src/Migration.js.map +1 -1
  21. package/dist/production/src/MigrationBuilder.cjs +267 -0
  22. package/dist/production/src/MigrationBuilder.cjs.map +1 -0
  23. package/dist/production/src/MigrationBuilder.js +267 -0
  24. package/dist/production/src/MigrationBuilder.js.map +1 -0
  25. package/dist/production/src/helpers.cjs +3 -16
  26. package/dist/production/src/helpers.cjs.map +1 -1
  27. package/dist/production/src/helpers.js +3 -15
  28. package/dist/production/src/helpers.js.map +1 -1
  29. package/dist/types/Migration.d.ts +1 -1
  30. package/dist/types/Migration.d.ts.map +1 -1
  31. package/dist/types/MigrationBuilder.d.ts +90 -0
  32. package/dist/types/MigrationBuilder.d.ts.map +1 -0
  33. package/dist/types/helpers.d.ts +3 -6
  34. package/dist/types/helpers.d.ts.map +1 -1
  35. package/dist/types/index.d.ts +2 -1
  36. package/dist/types/index.d.ts.map +1 -1
  37. package/dist/types/tsconfig.tsbuildinfo +1 -1
  38. package/package.json +2 -3
  39. package/readme.md +1 -1
  40. package/src/Migration.ts +1 -1
  41. package/src/MigrationBuilder.ts +379 -0
  42. package/src/helpers.ts +4 -17
  43. package/src/index.ts +2 -1
  44. package/tests/cases/unit/migrationBuilder.test.ts +439 -0
@@ -0,0 +1 @@
1
+ {"version":3,"file":"MigrationBuilder.js","sources":["../../../../packages/database-migrations/src/MigrationBuilder.ts"],"sourcesContent":["/*\nThe SQL generation in this file is ported from the migration builder of node-pg-migrate. (https://github.com/salsita/node-pg-migrate)\n\nThe MIT License (MIT)\n\nCopyright (c) 2016-2020 Salsita Software &lt;jando@salsitasoft.com&gt;\n\nCopyright (c) 2014-2016 Theo Ephraim\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n */\n\n// Collects the SQL of engine and content migrations. The output reproduces node-pg-migrate 5 byte for byte for the\n// operations and options below, because not-yet-run migrations on existing databases must execute the same SQL.\n\nexport type Name = string | { schema?: string; name: string }\n\nexport type Value = null | boolean | string | number | readonly Value[]\n\nexport interface SequenceOptions {\n\tprecedence: 'ALWAYS' | 'BY DEFAULT'\n\ttype?: string\n\tincrement?: number\n\tminvalue?: number | null | false\n\tmaxvalue?: number | null | false\n\tstart?: number\n\tcache?: number\n\tcycle?: boolean\n\towner?: string | null | false\n}\n\nexport interface ColumnDefinition {\n\ttype: string\n\tcollation?: string\n\tdefault?: Value\n\tunique?: boolean\n\tprimaryKey?: boolean\n\tnotNull?: boolean\n\treferences?: Name\n\tonDelete?: string\n\tsequenceGenerated?: SequenceOptions\n}\n\nexport interface AlterColumnOptions {\n\ttype?: string\n\tcollation?: string\n\tusing?: string\n\tnotNull?: boolean\n\tsequenceGenerated?: SequenceOptions | false\n}\n\nexport interface TriggerOptions {\n\twhen: 'BEFORE' | 'AFTER'\n\toperation: string | readonly string[]\n\tlevel?: 'ROW' | 'STATEMENT'\n\tfunction: Name\n\tfunctionParams?: readonly Value[]\n\tconstraint?: boolean\n\tdeferrable?: boolean\n\tdeferred?: boolean\n}\n\nexport interface FunctionParam {\n\tname: string\n\ttype: string\n}\n\nconst quote = (identifier: string): string => `\"${identifier}\"`\n\nconst literal = (name: Name): string => typeof name === 'object' ? (name.schema ? `${quote(name.schema)}.` : '') + quote(name.name) : quote(name)\n\nconst nextDollarTag = function*(): Generator<string> {\n\tconst chars = 'abcdefghijklmnopqrstuvwxyz'\n\tconst ids = [0]\n\twhile (true) {\n\t\tyield `$pg${ids.map(id => chars[id]).join('')}$`\n\t\tlet i = ids.length - 1\n\t\tfor (; i >= 0; i--) {\n\t\t\tids[i] += 1\n\t\t\tif (ids[i] < chars.length) {\n\t\t\t\tbreak\n\t\t\t}\n\t\t\tids[i] = 0\n\t\t}\n\t\tif (i < 0) {\n\t\t\tids.unshift(0)\n\t\t}\n\t}\n}\n\nexport const escapeValue = (value: unknown): string | number => {\n\tif (value === null) {\n\t\treturn 'NULL'\n\t}\n\tif (typeof value === 'boolean') {\n\t\treturn value.toString()\n\t}\n\tif (typeof value === 'string') {\n\t\tfor (const tag of nextDollarTag()) {\n\t\t\tif (!value.includes(tag)) {\n\t\t\t\treturn `${tag}${value}${tag}`\n\t\t\t}\n\t\t}\n\t}\n\tif (typeof value === 'number') {\n\t\treturn value\n\t}\n\tif (Array.isArray(value)) {\n\t\treturn `ARRAY[${value.map(escapeValue).join(',').replace(/ARRAY/g, '')}]`\n\t}\n\t// node-pg-migrate's PgLiteral shape; migration JSON (e.g. a fill value or column default) can carry it.\n\tif (typeof value === 'object' && 'literal' in value && value.literal === true && 'value' in value) {\n\t\treturn typeof value.value === 'number' ? value.value : `${value.value}`\n\t}\n\treturn ''\n}\n\nconst typeAdapters: Record<string, string> = {\n\tint: 'integer',\n\tstring: 'text',\n\tfloat: 'real',\n\tdouble: 'double precision',\n\tdatetime: 'timestamp',\n\tbool: 'boolean',\n}\n\nconst adaptType = (type: string): string => typeAdapters[type] ?? type\n\n// `id` is node-pg-migrate's only default type shorthand; on columns it also implies a primary key.\nconst resolveType = (type: string): string => type === 'id' ? 'serial' : adaptType(type)\n\nconst applyColumnShorthand = (column: ColumnDefinition): ColumnDefinition =>\n\tcolumn.type === 'id' ? { primaryKey: true, ...column, type: 'serial' } : { ...column, type: adaptType(column.type) }\n\nconst formatLines = (lines: readonly string[], prefix = ' ', separator = ','): string =>\n\tlines\n\t\t.map(line => line.replace(/(?:\\r\\n|\\r|\\n)+/g, ' '))\n\t\t.join(`${separator}\\n`)\n\t\t.replace(/^/gm, prefix)\n\n// Sequence options arrive unparsed from migration JSON, so every option node-pg-migrate rendered is kept.\nconst sequenceClause = (sequence: SequenceOptions): string => {\n\tconst { type, increment, minvalue, maxvalue, start, cache, cycle, owner } = sequence\n\tconst clauses: string[] = []\n\tif (type) {\n\t\tclauses.push(`AS ${resolveType(type)}`)\n\t}\n\tif (increment) {\n\t\tclauses.push(`INCREMENT BY ${increment}`)\n\t}\n\tif (minvalue) {\n\t\tclauses.push(`MINVALUE ${minvalue}`)\n\t} else if (minvalue === null || minvalue === false) {\n\t\tclauses.push('NO MINVALUE')\n\t}\n\tif (maxvalue) {\n\t\tclauses.push(`MAXVALUE ${maxvalue}`)\n\t} else if (maxvalue === null || maxvalue === false) {\n\t\tclauses.push('NO MAXVALUE')\n\t}\n\tif (start) {\n\t\tclauses.push(`START WITH ${start}`)\n\t}\n\tif (cache) {\n\t\tclauses.push(`CACHE ${cache}`)\n\t}\n\tif (cycle) {\n\t\tclauses.push('CYCLE')\n\t} else if (cycle === false) {\n\t\tclauses.push('NO CYCLE')\n\t}\n\tif (owner) {\n\t\tclauses.push(`OWNED BY ${owner}`)\n\t} else if (owner === null || owner === false) {\n\t\tclauses.push('OWNED BY NONE')\n\t}\n\treturn `GENERATED ${sequence.precedence} AS IDENTITY${clauses.length ? ` (${clauses.join(' ')})` : ''}`\n}\n\nconst referencesClause = (column: ColumnDefinition & { references: Name }): string => {\n\tconst { references, onDelete } = column\n\tconst target = typeof references === 'string' && (references.startsWith('\"') || references.endsWith(')')) ? references : literal(references)\n\treturn `REFERENCES ${target}${onDelete ? ` ON DELETE ${onDelete}` : ''}`\n}\n\nconst columnLines = (columns: Record<string, ColumnDefinition>): { lines: string[]; primaryKey: string[] } => {\n\tconst applied = Object.entries(columns).map(([name, column]) => [name, applyColumnShorthand(column)] as const)\n\tconst primaryKey = applied.filter(([, column]) => column.primaryKey).map(([name]) => name)\n\tconst lines = applied.map(([name, column]) => {\n\t\tconst constraints: string[] = []\n\t\tif (column.collation) {\n\t\t\tconstraints.push(`COLLATE ${column.collation}`)\n\t\t}\n\t\tif (column.default !== undefined) {\n\t\t\tconstraints.push(`DEFAULT ${escapeValue(column.default)}`)\n\t\t}\n\t\tif (column.unique) {\n\t\t\tconstraints.push('UNIQUE')\n\t\t}\n\t\tif (column.primaryKey && primaryKey.length === 1) {\n\t\t\tconstraints.push('PRIMARY KEY')\n\t\t}\n\t\tif (column.notNull) {\n\t\t\tconstraints.push('NOT NULL')\n\t\t}\n\t\tif (column.references) {\n\t\t\tconstraints.push(referencesClause({ ...column, references: column.references }))\n\t\t}\n\t\tif (column.sequenceGenerated) {\n\t\t\tconstraints.push(sequenceClause(column.sequenceGenerated))\n\t\t}\n\t\treturn `${literal(name)} ${column.type}${constraints.length ? ` ${constraints.join(' ')}` : ''}`\n\t})\n\treturn { lines, primaryKey: primaryKey.length > 1 ? primaryKey : [] }\n}\n\nconst tableNameOf = (table: Name): string => typeof table === 'object' ? table.name : table\n\nexport class MigrationBuilder {\n\tprivate readonly steps: string[] = []\n\n\tgetSqlSteps(): string[] {\n\t\treturn [...this.steps]\n\t}\n\n\tgetSql(): string {\n\t\treturn `${this.steps.join('\\n')}\\n`\n\t}\n\n\tsql(sql: string): void {\n\t\tthis.steps.push(sql.lastIndexOf(';') !== sql.length - 1 ? `${sql};` : sql)\n\t}\n\n\tcreateTable(table: Name, columns: Record<string, ColumnDefinition>): void {\n\t\tconst { lines, primaryKey } = columnLines(columns)\n\t\tconst definition = primaryKey.length > 0\n\t\t\t? [...lines, `CONSTRAINT ${literal(`${tableNameOf(table)}_pkey`)} PRIMARY KEY (${primaryKey.map(name => literal(name)).join(', ')})`]\n\t\t\t: lines\n\t\tthis.steps.push(`CREATE TABLE ${literal(table)} (\\n${formatLines(definition)}\\n);`)\n\t}\n\n\tdropTable(table: Name): void {\n\t\tthis.steps.push(`DROP TABLE ${literal(table)};`)\n\t}\n\n\trenameTable(table: Name, newName: Name): void {\n\t\tthis.steps.push(`ALTER TABLE ${literal(table)} RENAME TO ${literal(newName)};`)\n\t}\n\n\taddColumn(table: Name, columns: Record<string, ColumnDefinition>): void {\n\t\tthis.steps.push(`ALTER TABLE ${literal(table)}\\n${formatLines(columnLines(columns).lines, ' ADD ')};`)\n\t}\n\n\tdropColumn(table: Name, column: string): void {\n\t\tthis.steps.push(`ALTER TABLE ${literal(table)}\\n${formatLines([literal(column)], ' DROP ')};`)\n\t}\n\n\trenameColumn(table: Name, column: string, newName: string): void {\n\t\tthis.steps.push(`ALTER TABLE ${literal(table)} RENAME ${literal(column)} TO ${literal(newName)};`)\n\t}\n\n\talterColumn(table: Name, column: string, options: AlterColumnOptions): void {\n\t\tconst actions: string[] = []\n\t\tif (options.type) {\n\t\t\tconst collation = options.collation ? ` COLLATE ${options.collation}` : ''\n\t\t\tconst using = options.using ? ` USING ${options.using}` : ''\n\t\t\tactions.push(`SET DATA TYPE ${adaptType(options.type)}${collation}${using}`)\n\t\t}\n\t\tif (options.notNull) {\n\t\t\tactions.push('SET NOT NULL')\n\t\t} else if (options.notNull === false) {\n\t\t\tactions.push('DROP NOT NULL')\n\t\t}\n\t\tif (options.sequenceGenerated !== undefined) {\n\t\t\tactions.push(options.sequenceGenerated ? `ADD ${sequenceClause(options.sequenceGenerated)}` : 'DROP IDENTITY')\n\t\t}\n\t\tif (actions.length > 0) {\n\t\t\tthis.steps.push(`ALTER TABLE ${literal(table)}\\n${formatLines(actions, ` ALTER ${literal(column)} `)};`)\n\t\t} else {\n\t\t\tthis.steps.push('')\n\t\t}\n\t}\n\n\taddConstraint(table: Name, constraintName: string | null, options: { primaryKey: readonly string[] }): void {\n\t\tconst name = literal(constraintName || `${tableNameOf(table)}_pkey`)\n\t\tconst constraint = `CONSTRAINT ${name} PRIMARY KEY (${options.primaryKey.map(column => literal(column)).join(', ')})`\n\t\tthis.steps.push(`ALTER TABLE ${literal(table)}\\n${formatLines([constraint], ' ADD ')};`)\n\t}\n\n\tdropConstraint(table: Name, constraintName: string): void {\n\t\tthis.steps.push(`ALTER TABLE ${literal(table)} DROP CONSTRAINT ${literal(constraintName)};`)\n\t}\n\n\tcreateIndex(table: Name, columns: readonly string[], options: { name: string }): void {\n\t\tconst columnsSql = columns.map(column => /[. ()]/.test(column) ? column : literal(column)).join(', ')\n\t\tconst name = options.name || `${tableNameOf(table)}_${columns.join('_')}_index`\n\t\tthis.steps.push(`CREATE INDEX ${literal(name)} ON ${literal(table)} (${columnsSql});`)\n\t}\n\n\tcreateDomain(domain: Name, type: string, options: { check: string; constraintName?: string }): void {\n\t\tconst constraintName = options.constraintName ? ` CONSTRAINT ${literal(options.constraintName)}` : ''\n\t\tconst check = options.check ? `${constraintName} CHECK (${options.check})` : ''\n\t\tthis.steps.push(`CREATE DOMAIN ${literal(domain)} AS ${resolveType(type)}${check};`)\n\t}\n\n\trenameDomain(domain: Name, newName: Name): void {\n\t\tthis.steps.push(`ALTER DOMAIN ${literal(domain)} RENAME TO ${literal(newName)};`)\n\t}\n\n\tdropDomain(domain: Name): void {\n\t\tthis.steps.push(`DROP DOMAIN ${literal(domain)};`)\n\t}\n\n\tcreateView(view: Name, options: { replace?: boolean }, definition: string): void {\n\t\tthis.steps.push(`CREATE${options.replace ? ' OR REPLACE' : ''} VIEW ${literal(view)} AS ${definition};`)\n\t}\n\n\trenameView(view: Name, newName: Name): void {\n\t\tthis.steps.push(`ALTER VIEW ${literal(view)} RENAME TO ${literal(newName)};`)\n\t}\n\n\tdropView(view: Name): void {\n\t\tthis.steps.push(`DROP VIEW ${literal(view)};`)\n\t}\n\n\tcreateMaterializedView(view: Name, options: { data?: boolean }, definition: string): void {\n\t\tconst data = options.data !== undefined ? ` WITH${options.data ? '' : ' NO'} DATA` : ''\n\t\tthis.steps.push(`CREATE MATERIALIZED VIEW ${literal(view)} AS ${definition}${data};`)\n\t}\n\n\tdropMaterializedView(view: Name): void {\n\t\tthis.steps.push(`DROP MATERIALIZED VIEW ${literal(view)};`)\n\t}\n\n\tcreateTrigger(table: Name, trigger: string, options: TriggerOptions): void {\n\t\tconst { constraint, deferrable, deferred, functionParams = [], level = 'STATEMENT' } = options\n\t\tconst when = constraint ? 'AFTER' : options.when\n\t\tconst operations = typeof options.operation === 'string' ? options.operation : options.operation.join(' OR ')\n\t\tif (!options.function) {\n\t\t\tthrow new Error(\"Can't determine function name\")\n\t\t}\n\t\tif (!operations) {\n\t\t\tthrow new Error('\"operation\" (INSERT/UPDATE[ OF ...]/DELETE/TRUNCATE) have to be specified')\n\t\t}\n\t\tconst defer = constraint ? `${deferrable ? `DEFERRABLE INITIALLY ${deferred ? 'DEFERRED' : 'IMMEDIATE'}` : 'NOT DEFERRABLE'}\\n ` : ''\n\t\tthis.steps.push(\n\t\t\t`CREATE${constraint ? ' CONSTRAINT' : ''} TRIGGER ${literal(trigger)}\\n`\n\t\t\t\t+ ` ${when} ${operations} ON ${literal(table)}\\n`\n\t\t\t\t+ ` ${defer}FOR EACH ${level}\\n`\n\t\t\t\t+ ` EXECUTE PROCEDURE ${literal(options.function)}(${functionParams.map(escapeValue).join(', ')});`,\n\t\t)\n\t}\n\n\tdropTrigger(table: Name, trigger: string, options: { ifExists?: boolean } = {}): void {\n\t\tthis.steps.push(`DROP TRIGGER${options.ifExists ? ' IF EXISTS' : ''} ${literal(trigger)} ON ${literal(table)};`)\n\t}\n\n\tdropFunction(fn: Name, params: readonly FunctionParam[]): void {\n\t\tconst paramsSql = params.map(param => [param.name ? literal(param.name) : '', param.type ? resolveType(param.type) : ''].filter(Boolean).join(' '))\n\t\t\t.join(', ')\n\t\tthis.steps.push(`DROP FUNCTION ${literal(fn)}(${paramsSql});`)\n\t}\n}\n"],"names":[],"mappings":";;;AAmFA,MAAM,QAAQ,CAAC,eAA+B,IAAI,UAAU;AAE5D,MAAM,UAAU,CAAC,SAAuB,OAAO,SAAS,YAAY,KAAK,SAAS,GAAG,MAAM,KAAK,MAAM,CAAC,MAAM,MAAM,MAAM,KAAK,IAAI,IAAI,MAAM,IAAI;AAEhJ,MAAM,gBAAgB,aAA+B;AACpD,QAAM,QAAQ;AACd,QAAM,MAAM,CAAC,CAAC;AACd,SAAO,MAAM;AACZ,UAAM,MAAM,IAAI,IAAI,CAAA,OAAM,MAAM,EAAE,CAAC,EAAE,KAAK,EAAE,CAAC;AAC7C,QAAI,IAAI,IAAI,SAAS;AACrB,WAAO,KAAK,GAAG,KAAK;AACnB,UAAI,CAAC,KAAK;AACV,UAAI,IAAI,CAAC,IAAI,MAAM,QAAQ;AAC1B;AAAA,MACD;AACA,UAAI,CAAC,IAAI;AAAA,IACV;AACA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;AAAA,sBACJ,QAAQ,QAAQ,QAAQ,CAAC,IAAI,eAAe,IAAI,WAAW,EAAE,KAAK,IAAI,CAAC;AAAA,IAAA;AAAA,EAEnG;AAAA,EAEA,YAAY,OAAa,SAAiB,UAAkC,CAAA,GAAU;AACrF,SAAK,MAAM,KAAK,eAAe,QAAQ,WAAW,eAAe,EAAE,IAAI,QAAQ,OAAO,CAAC,OAAO,QAAQ,KAAK,CAAC,GAAG;AAAA,EAChH;AAAA,EAEA,aAAa,IAAU,QAAwC;AAC9D,UAAM,YAAY,OAAO,IAAI,CAAA,UAAS,CAAC,MAAM,OAAO,QAAQ,MAAM,IAAI,IAAI,IAAI,MAAM,OAAO,YAAY,MAAM,IAAI,IAAI,EAAE,EAAE,OAAO,OAAO,EAAE,KAAK,GAAG,CAAC,EAChJ,KAAK,IAAI;AACX,SAAK,MAAM,KAAK,iBAAiB,QAAQ,EAAE,CAAC,IAAI,SAAS,IAAI;AAAA,EAC9D;AACD;"}
@@ -1,21 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
- const MigrationBuilderImpl = require("node-pg-migrate/dist/migration-builder.js");
4
- const utils_js = require("node-pg-migrate/dist/utils.js");
3
+ const MigrationBuilder = require("./MigrationBuilder.cjs");
5
4
  function createMigrationBuilder() {
6
- const impl = "default" in MigrationBuilderImpl ? MigrationBuilderImpl.default : MigrationBuilderImpl;
7
- return new impl(
8
- {
9
- query: null,
10
- select: null
11
- },
12
- {},
13
- false,
14
- {}
15
- );
16
- }
17
- function escapeValue(value) {
18
- return utils_js.escapeValue(value);
5
+ return new MigrationBuilder.MigrationBuilder();
19
6
  }
20
7
  const timePrefixLength = "YYYY-MM-DD-XXXXXX".length;
21
8
  const checkOrder = (runMigrations, migrations) => {
@@ -31,8 +18,8 @@ const checkOrder = (runMigrations, migrations) => {
31
18
  }
32
19
  }
33
20
  };
21
+ exports.escapeValue = MigrationBuilder.escapeValue;
34
22
  exports.checkOrder = checkOrder;
35
23
  exports.createMigrationBuilder = createMigrationBuilder;
36
- exports.escapeValue = escapeValue;
37
24
  exports.timePrefixLength = timePrefixLength;
38
25
  //# sourceMappingURL=helpers.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"helpers.cjs","sources":["../../../../packages/database-migrations/src/helpers.ts"],"sourcesContent":["import { MigrationBuilder } from 'node-pg-migrate'\nimport { Migration, RunMigration } from './Migration.js'\nimport MigrationBuilderImpl from 'node-pg-migrate/dist/migration-builder.js'\nimport { escapeValue as pgEscape } from 'node-pg-migrate/dist/utils.js'\n\nexport function createMigrationBuilder(): MigrationBuilder & { getSql: () => string; getSqlSteps: () => string[] } {\n\tconst impl = 'default' in MigrationBuilderImpl ? (MigrationBuilderImpl as any).default : MigrationBuilderImpl\n\treturn new impl(\n\t\t{\n\t\t\tquery: null,\n\t\t\tselect: null,\n\t\t} as any,\n\t\t{},\n\t\tfalse,\n\t\t{} as any,\n\t)\n}\n\nexport function escapeValue(value: any): string | number {\n\treturn pgEscape(value)\n}\n\nexport const timePrefixLength = 'YYYY-MM-DD-XXXXXX'.length\n\nexport const checkOrder = (runMigrations: RunMigration[], migrations: Migration<any>[]) => {\n\tconst len = Math.min(runMigrations.length, migrations.length)\n\tfor (let i = 0; i < len; i++) {\n\t\tconst run = runMigrations[i]\n\t\tconst migrationName = migrations[i].name\n\t\tif (migrationName > run.name) {\n\t\t\tthrow new Error(`Previously executed migration ${run} is missing`)\n\t\t}\n\t\tif (run.name > migrationName) {\n\t\t\tthrow new Error(`Not executed migration ${migrationName} is preceding already run migration ${run.name}`)\n\t\t}\n\t}\n}\n"],"names":["pgEscape"],"mappings":";;;;AAKO,SAAS,yBAAmG;AAClH,QAAM,OAAO,aAAa,uBAAwB,qBAA6B,UAAU;AACzF,SAAO,IAAI;AAAA,IACV;AAAA,MACC,OAAO;AAAA,MACP,QAAQ;AAAA,IAAA;AAAA,IAET,CAAA;AAAA,IACA;AAAA,IACA,CAAA;AAAA,EAAC;AAEH;AAEO,SAAS,YAAY,OAA6B;AACxD,SAAOA,SAAAA,YAAS,KAAK;AACtB;AAEO,MAAM,mBAAmB,oBAAoB;AAE7C,MAAM,aAAa,CAAC,eAA+B,eAAiC;AAC1F,QAAM,MAAM,KAAK,IAAI,cAAc,QAAQ,WAAW,MAAM;AAC5D,WAAS,IAAI,GAAG,IAAI,KAAK,KAAK;AAC7B,UAAM,MAAM,cAAc,CAAC;AAC3B,UAAM,gBAAgB,WAAW,CAAC,EAAE;AACpC,QAAI,gBAAgB,IAAI,MAAM;AAC7B,YAAM,IAAI,MAAM,iCAAiC,GAAG,aAAa;AAAA,IAClE;AACA,QAAI,IAAI,OAAO,eAAe;AAC7B,YAAM,IAAI,MAAM,0BAA0B,aAAa,uCAAuC,IAAI,IAAI,EAAE;AAAA,IACzG;AAAA,EACD;AACD;;;;;"}
1
+ {"version":3,"file":"helpers.cjs","sources":["../../../../packages/database-migrations/src/helpers.ts"],"sourcesContent":["import { Migration, RunMigration } from './Migration.js'\nimport { MigrationBuilder } from './MigrationBuilder.js'\n\nexport { escapeValue } from './MigrationBuilder.js'\n\nexport function createMigrationBuilder(): MigrationBuilder {\n\treturn new MigrationBuilder()\n}\n\nexport const timePrefixLength = 'YYYY-MM-DD-XXXXXX'.length\n\nexport const checkOrder = (runMigrations: RunMigration[], migrations: Migration<any>[]) => {\n\tconst len = Math.min(runMigrations.length, migrations.length)\n\tfor (let i = 0; i < len; i++) {\n\t\tconst run = runMigrations[i]\n\t\tconst migrationName = migrations[i].name\n\t\tif (migrationName > run.name) {\n\t\t\tthrow new Error(`Previously executed migration ${run} is missing`)\n\t\t}\n\t\tif (run.name > migrationName) {\n\t\t\tthrow new Error(`Not executed migration ${migrationName} is preceding already run migration ${run.name}`)\n\t\t}\n\t}\n}\n"],"names":["MigrationBuilder"],"mappings":";;;AAKO,SAAS,yBAA2C;AAC1D,SAAO,IAAIA,iBAAAA,iBAAA;AACZ;AAEO,MAAM,mBAAmB,oBAAoB;AAE7C,MAAM,aAAa,CAAC,eAA+B,eAAiC;AAC1F,QAAM,MAAM,KAAK,IAAI,cAAc,QAAQ,WAAW,MAAM;AAC5D,WAAS,IAAI,GAAG,IAAI,KAAK,KAAK;AAC7B,UAAM,MAAM,cAAc,CAAC;AAC3B,UAAM,gBAAgB,WAAW,CAAC,EAAE;AACpC,QAAI,gBAAgB,IAAI,MAAM;AAC7B,YAAM,IAAI,MAAM,iCAAiC,GAAG,aAAa;AAAA,IAClE;AACA,QAAI,IAAI,OAAO,eAAe;AAC7B,YAAM,IAAI,MAAM,0BAA0B,aAAa,uCAAuC,IAAI,IAAI,EAAE;AAAA,IACzG;AAAA,EACD;AACD;;;;;"}
@@ -1,19 +1,7 @@
1
- import MigrationBuilderImpl from "node-pg-migrate/dist/migration-builder.js";
2
- import { escapeValue as escapeValue$1 } from "node-pg-migrate/dist/utils.js";
1
+ import { MigrationBuilder } from "./MigrationBuilder.js";
2
+ import { escapeValue } from "./MigrationBuilder.js";
3
3
  function createMigrationBuilder() {
4
- const impl = "default" in MigrationBuilderImpl ? MigrationBuilderImpl.default : MigrationBuilderImpl;
5
- return new impl(
6
- {
7
- query: null,
8
- select: null
9
- },
10
- {},
11
- false,
12
- {}
13
- );
14
- }
15
- function escapeValue(value) {
16
- return escapeValue$1(value);
4
+ return new MigrationBuilder();
17
5
  }
18
6
  const timePrefixLength = "YYYY-MM-DD-XXXXXX".length;
19
7
  const checkOrder = (runMigrations, migrations) => {
@@ -1 +1 @@
1
- {"version":3,"file":"helpers.js","sources":["../../../../packages/database-migrations/src/helpers.ts"],"sourcesContent":["import { MigrationBuilder } from 'node-pg-migrate'\nimport { Migration, RunMigration } from './Migration.js'\nimport MigrationBuilderImpl from 'node-pg-migrate/dist/migration-builder.js'\nimport { escapeValue as pgEscape } from 'node-pg-migrate/dist/utils.js'\n\nexport function createMigrationBuilder(): MigrationBuilder & { getSql: () => string; getSqlSteps: () => string[] } {\n\tconst impl = 'default' in MigrationBuilderImpl ? (MigrationBuilderImpl as any).default : MigrationBuilderImpl\n\treturn new impl(\n\t\t{\n\t\t\tquery: null,\n\t\t\tselect: null,\n\t\t} as any,\n\t\t{},\n\t\tfalse,\n\t\t{} as any,\n\t)\n}\n\nexport function escapeValue(value: any): string | number {\n\treturn pgEscape(value)\n}\n\nexport const timePrefixLength = 'YYYY-MM-DD-XXXXXX'.length\n\nexport const checkOrder = (runMigrations: RunMigration[], migrations: Migration<any>[]) => {\n\tconst len = Math.min(runMigrations.length, migrations.length)\n\tfor (let i = 0; i < len; i++) {\n\t\tconst run = runMigrations[i]\n\t\tconst migrationName = migrations[i].name\n\t\tif (migrationName > run.name) {\n\t\t\tthrow new Error(`Previously executed migration ${run} is missing`)\n\t\t}\n\t\tif (run.name > migrationName) {\n\t\t\tthrow new Error(`Not executed migration ${migrationName} is preceding already run migration ${run.name}`)\n\t\t}\n\t}\n}\n"],"names":["pgEscape"],"mappings":";;AAKO,SAAS,yBAAmG;AAClH,QAAM,OAAO,aAAa,uBAAwB,qBAA6B,UAAU;AACzF,SAAO,IAAI;AAAA,IACV;AAAA,MACC,OAAO;AAAA,MACP,QAAQ;AAAA,IAAA;AAAA,IAET,CAAA;AAAA,IACA;AAAA,IACA,CAAA;AAAA,EAAC;AAEH;AAEO,SAAS,YAAY,OAA6B;AACxD,SAAOA,cAAS,KAAK;AACtB;AAEO,MAAM,mBAAmB,oBAAoB;AAE7C,MAAM,aAAa,CAAC,eAA+B,eAAiC;AAC1F,QAAM,MAAM,KAAK,IAAI,cAAc,QAAQ,WAAW,MAAM;AAC5D,WAAS,IAAI,GAAG,IAAI,KAAK,KAAK;AAC7B,UAAM,MAAM,cAAc,CAAC;AAC3B,UAAM,gBAAgB,WAAW,CAAC,EAAE;AACpC,QAAI,gBAAgB,IAAI,MAAM;AAC7B,YAAM,IAAI,MAAM,iCAAiC,GAAG,aAAa;AAAA,IAClE;AACA,QAAI,IAAI,OAAO,eAAe;AAC7B,YAAM,IAAI,MAAM,0BAA0B,aAAa,uCAAuC,IAAI,IAAI,EAAE;AAAA,IACzG;AAAA,EACD;AACD;"}
1
+ {"version":3,"file":"helpers.js","sources":["../../../../packages/database-migrations/src/helpers.ts"],"sourcesContent":["import { Migration, RunMigration } from './Migration.js'\nimport { MigrationBuilder } from './MigrationBuilder.js'\n\nexport { escapeValue } from './MigrationBuilder.js'\n\nexport function createMigrationBuilder(): MigrationBuilder {\n\treturn new MigrationBuilder()\n}\n\nexport const timePrefixLength = 'YYYY-MM-DD-XXXXXX'.length\n\nexport const checkOrder = (runMigrations: RunMigration[], migrations: Migration<any>[]) => {\n\tconst len = Math.min(runMigrations.length, migrations.length)\n\tfor (let i = 0; i < len; i++) {\n\t\tconst run = runMigrations[i]\n\t\tconst migrationName = migrations[i].name\n\t\tif (migrationName > run.name) {\n\t\t\tthrow new Error(`Previously executed migration ${run} is missing`)\n\t\t}\n\t\tif (run.name > migrationName) {\n\t\t\tthrow new Error(`Not executed migration ${migrationName} is preceding already run migration ${run.name}`)\n\t\t}\n\t}\n}\n"],"names":[],"mappings":";;AAKO,SAAS,yBAA2C;AAC1D,SAAO,IAAI,iBAAA;AACZ;AAEO,MAAM,mBAAmB,oBAAoB;AAE7C,MAAM,aAAa,CAAC,eAA+B,eAAiC;AAC1F,QAAM,MAAM,KAAK,IAAI,cAAc,QAAQ,WAAW,MAAM;AAC5D,WAAS,IAAI,GAAG,IAAI,KAAK,KAAK;AAC7B,UAAM,MAAM,cAAc,CAAC;AAC3B,UAAM,gBAAgB,WAAW,CAAC,EAAE;AACpC,QAAI,gBAAgB,IAAI,MAAM;AAC7B,YAAM,IAAI,MAAM,iCAAiC,GAAG,aAAa;AAAA,IAClE;AACA,QAAI,IAAI,OAAO,eAAe;AAC7B,YAAM,IAAI,MAAM,0BAA0B,aAAa,uCAAuC,IAAI,IAAI,EAAE;AAAA,IACzG;AAAA,EACD;AACD;"}
@@ -5,13 +5,15 @@ const GroupMigrationsResolver = require("./src/GroupMigrationsResolver.cjs");
5
5
  const SnapshotMigrationResolver = require("./src/SnapshotMigrationResolver.cjs");
6
6
  const helpers = require("./src/helpers.cjs");
7
7
  const Migration = require("./src/Migration.cjs");
8
+ const MigrationBuilder = require("./src/MigrationBuilder.cjs");
8
9
  exports.MigrationsRunner = MigrationsRunner.MigrationsRunner;
9
10
  exports.GroupMigrationsResolver = GroupMigrationsResolver.GroupMigrationsResolver;
10
11
  exports.SnapshotMigrationResolver = SnapshotMigrationResolver.SnapshotMigrationResolver;
11
12
  exports.checkOrder = helpers.checkOrder;
12
13
  exports.createMigrationBuilder = helpers.createMigrationBuilder;
13
- exports.escapeValue = helpers.escapeValue;
14
14
  exports.timePrefixLength = helpers.timePrefixLength;
15
15
  exports.Migration = Migration.Migration;
16
16
  exports.MigrationGroup = Migration.MigrationGroup;
17
+ exports.MigrationBuilder = MigrationBuilder.MigrationBuilder;
18
+ exports.escapeValue = MigrationBuilder.escapeValue;
17
19
  //# sourceMappingURL=index.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"index.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;"}
@@ -1,11 +1,13 @@
1
1
  import { MigrationsRunner } from "./src/MigrationsRunner.js";
2
2
  import { GroupMigrationsResolver } from "./src/GroupMigrationsResolver.js";
3
3
  import { SnapshotMigrationResolver } from "./src/SnapshotMigrationResolver.js";
4
- import { checkOrder, createMigrationBuilder, escapeValue, timePrefixLength } from "./src/helpers.js";
4
+ import { checkOrder, createMigrationBuilder, timePrefixLength } from "./src/helpers.js";
5
5
  import { Migration, MigrationGroup } from "./src/Migration.js";
6
+ import { MigrationBuilder, escapeValue } from "./src/MigrationBuilder.js";
6
7
  export {
7
8
  GroupMigrationsResolver,
8
9
  Migration,
10
+ MigrationBuilder,
9
11
  MigrationGroup,
10
12
  MigrationsRunner,
11
13
  SnapshotMigrationResolver,
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;"}
1
+ {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"Migration.cjs","sources":["../../../../packages/database-migrations/src/Migration.ts"],"sourcesContent":["import { MigrationBuilder } from 'node-pg-migrate'\nimport { Connection } from '@contember/database'\n\nexport type MigrationExecutor<Args = unknown> = (builder: MigrationBuilder, args: MigrationArgs<Args>) => Promise<void> | void\n\nexport class Migration<Args = unknown> {\n\tconstructor(\n\t\tpublic readonly name: string,\n\t\tpublic readonly migration: MigrationExecutor<Args>,\n\t\tpublic readonly group: string | null = null,\n\t) {\n\t}\n}\n\nexport type MigrationArgs<Args> =\n\t& Args\n\t& {\n\t\tconnection: Connection.ConnectionLike\n\t}\n\nexport interface RunMigration {\n\tname: string\n\tgroup: string | null\n}\n\nexport class MigrationGroup<Args = unknown> {\n\tconstructor(\n\t\tpublic readonly snapshot: MigrationExecutor<Args>,\n\t\tpublic readonly migrations: Record<string, MigrationExecutor<Args>>,\n\t) {\n\t}\n}\n"],"names":[],"mappings":";;AAKO,MAAM,UAA0B;AAAA,EACtC,YACiB,MACA,WACA,QAAuB,MACtC;AAHe,SAAA,OAAA;AACA,SAAA,YAAA;AACA,SAAA,QAAA;AAAA,EAEjB;AACD;AAaO,MAAM,eAA+B;AAAA,EAC3C,YACiB,UACA,YACf;AAFe,SAAA,WAAA;AACA,SAAA,aAAA;AAAA,EAEjB;AACD;;;"}
1
+ {"version":3,"file":"Migration.cjs","sources":["../../../../packages/database-migrations/src/Migration.ts"],"sourcesContent":["import type { MigrationBuilder } from './MigrationBuilder.js'\nimport { Connection } from '@contember/database'\n\nexport type MigrationExecutor<Args = unknown> = (builder: MigrationBuilder, args: MigrationArgs<Args>) => Promise<void> | void\n\nexport class Migration<Args = unknown> {\n\tconstructor(\n\t\tpublic readonly name: string,\n\t\tpublic readonly migration: MigrationExecutor<Args>,\n\t\tpublic readonly group: string | null = null,\n\t) {\n\t}\n}\n\nexport type MigrationArgs<Args> =\n\t& Args\n\t& {\n\t\tconnection: Connection.ConnectionLike\n\t}\n\nexport interface RunMigration {\n\tname: string\n\tgroup: string | null\n}\n\nexport class MigrationGroup<Args = unknown> {\n\tconstructor(\n\t\tpublic readonly snapshot: MigrationExecutor<Args>,\n\t\tpublic readonly migrations: Record<string, MigrationExecutor<Args>>,\n\t) {\n\t}\n}\n"],"names":[],"mappings":";;AAKO,MAAM,UAA0B;AAAA,EACtC,YACiB,MACA,WACA,QAAuB,MACtC;AAHe,SAAA,OAAA;AACA,SAAA,YAAA;AACA,SAAA,QAAA;AAAA,EAEjB;AACD;AAaO,MAAM,eAA+B;AAAA,EAC3C,YACiB,UACA,YACf;AAFe,SAAA,WAAA;AACA,SAAA,aAAA;AAAA,EAEjB;AACD;;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"Migration.js","sources":["../../../../packages/database-migrations/src/Migration.ts"],"sourcesContent":["import { MigrationBuilder } from 'node-pg-migrate'\nimport { Connection } from '@contember/database'\n\nexport type MigrationExecutor<Args = unknown> = (builder: MigrationBuilder, args: MigrationArgs<Args>) => Promise<void> | void\n\nexport class Migration<Args = unknown> {\n\tconstructor(\n\t\tpublic readonly name: string,\n\t\tpublic readonly migration: MigrationExecutor<Args>,\n\t\tpublic readonly group: string | null = null,\n\t) {\n\t}\n}\n\nexport type MigrationArgs<Args> =\n\t& Args\n\t& {\n\t\tconnection: Connection.ConnectionLike\n\t}\n\nexport interface RunMigration {\n\tname: string\n\tgroup: string | null\n}\n\nexport class MigrationGroup<Args = unknown> {\n\tconstructor(\n\t\tpublic readonly snapshot: MigrationExecutor<Args>,\n\t\tpublic readonly migrations: Record<string, MigrationExecutor<Args>>,\n\t) {\n\t}\n}\n"],"names":[],"mappings":"AAKO,MAAM,UAA0B;AAAA,EACtC,YACiB,MACA,WACA,QAAuB,MACtC;AAHe,SAAA,OAAA;AACA,SAAA,YAAA;AACA,SAAA,QAAA;AAAA,EAEjB;AACD;AAaO,MAAM,eAA+B;AAAA,EAC3C,YACiB,UACA,YACf;AAFe,SAAA,WAAA;AACA,SAAA,aAAA;AAAA,EAEjB;AACD;"}
1
+ {"version":3,"file":"Migration.js","sources":["../../../../packages/database-migrations/src/Migration.ts"],"sourcesContent":["import type { MigrationBuilder } from './MigrationBuilder.js'\nimport { Connection } from '@contember/database'\n\nexport type MigrationExecutor<Args = unknown> = (builder: MigrationBuilder, args: MigrationArgs<Args>) => Promise<void> | void\n\nexport class Migration<Args = unknown> {\n\tconstructor(\n\t\tpublic readonly name: string,\n\t\tpublic readonly migration: MigrationExecutor<Args>,\n\t\tpublic readonly group: string | null = null,\n\t) {\n\t}\n}\n\nexport type MigrationArgs<Args> =\n\t& Args\n\t& {\n\t\tconnection: Connection.ConnectionLike\n\t}\n\nexport interface RunMigration {\n\tname: string\n\tgroup: string | null\n}\n\nexport class MigrationGroup<Args = unknown> {\n\tconstructor(\n\t\tpublic readonly snapshot: MigrationExecutor<Args>,\n\t\tpublic readonly migrations: Record<string, MigrationExecutor<Args>>,\n\t) {\n\t}\n}\n"],"names":[],"mappings":"AAKO,MAAM,UAA0B;AAAA,EACtC,YACiB,MACA,WACA,QAAuB,MACtC;AAHe,SAAA,OAAA;AACA,SAAA,YAAA;AACA,SAAA,QAAA;AAAA,EAEjB;AACD;AAaO,MAAM,eAA+B;AAAA,EAC3C,YACiB,UACA,YACf;AAFe,SAAA,WAAA;AACA,SAAA,aAAA;AAAA,EAEjB;AACD;"}
@@ -0,0 +1,267 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ var __defProp = Object.defineProperty;
4
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
5
+ var __publicField = (obj, key, value) => __defNormalProp(obj, key + "", value);
6
+ const quote = (identifier) => `"${identifier}"`;
7
+ const literal = (name) => typeof name === "object" ? (name.schema ? `${quote(name.schema)}.` : "") + quote(name.name) : quote(name);
8
+ const nextDollarTag = function* () {
9
+ const chars = "abcdefghijklmnopqrstuvwxyz";
10
+ const ids = [0];
11
+ while (true) {
12
+ yield `$pg${ids.map((id) => chars[id]).join("")}$`;
13
+ let i = ids.length - 1;
14
+ for (; i >= 0; i--) {
15
+ ids[i] += 1;
16
+ if (ids[i] < chars.length) {
17
+ break;
18
+ }
19
+ ids[i] = 0;
20
+ }
21
+ if (i < 0) {
22
+ ids.unshift(0);
23
+ }
24
+ }
25
+ };
26
+ const escapeValue = (value) => {
27
+ if (value === null) {
28
+ return "NULL";
29
+ }
30
+ if (typeof value === "boolean") {
31
+ return value.toString();
32
+ }
33
+ if (typeof value === "string") {
34
+ for (const tag of nextDollarTag()) {
35
+ if (!value.includes(tag)) {
36
+ return `${tag}${value}${tag}`;
37
+ }
38
+ }
39
+ }
40
+ if (typeof value === "number") {
41
+ return value;
42
+ }
43
+ if (Array.isArray(value)) {
44
+ return `ARRAY[${value.map(escapeValue).join(",").replace(/ARRAY/g, "")}]`;
45
+ }
46
+ if (typeof value === "object" && "literal" in value && value.literal === true && "value" in value) {
47
+ return typeof value.value === "number" ? value.value : `${value.value}`;
48
+ }
49
+ return "";
50
+ };
51
+ const typeAdapters = {
52
+ int: "integer",
53
+ string: "text",
54
+ float: "real",
55
+ double: "double precision",
56
+ datetime: "timestamp",
57
+ bool: "boolean"
58
+ };
59
+ const adaptType = (type) => typeAdapters[type] ?? type;
60
+ const resolveType = (type) => type === "id" ? "serial" : adaptType(type);
61
+ const applyColumnShorthand = (column) => column.type === "id" ? { primaryKey: true, ...column, type: "serial" } : { ...column, type: adaptType(column.type) };
62
+ const formatLines = (lines, prefix = " ", separator = ",") => lines.map((line) => line.replace(/(?:\r\n|\r|\n)+/g, " ")).join(`${separator}
63
+ `).replace(/^/gm, prefix);
64
+ const sequenceClause = (sequence) => {
65
+ const { type, increment, minvalue, maxvalue, start, cache, cycle, owner } = sequence;
66
+ const clauses = [];
67
+ if (type) {
68
+ clauses.push(`AS ${resolveType(type)}`);
69
+ }
70
+ if (increment) {
71
+ clauses.push(`INCREMENT BY ${increment}`);
72
+ }
73
+ if (minvalue) {
74
+ clauses.push(`MINVALUE ${minvalue}`);
75
+ } else if (minvalue === null || minvalue === false) {
76
+ clauses.push("NO MINVALUE");
77
+ }
78
+ if (maxvalue) {
79
+ clauses.push(`MAXVALUE ${maxvalue}`);
80
+ } else if (maxvalue === null || maxvalue === false) {
81
+ clauses.push("NO MAXVALUE");
82
+ }
83
+ if (start) {
84
+ clauses.push(`START WITH ${start}`);
85
+ }
86
+ if (cache) {
87
+ clauses.push(`CACHE ${cache}`);
88
+ }
89
+ if (cycle) {
90
+ clauses.push("CYCLE");
91
+ } else if (cycle === false) {
92
+ clauses.push("NO CYCLE");
93
+ }
94
+ if (owner) {
95
+ clauses.push(`OWNED BY ${owner}`);
96
+ } else if (owner === null || owner === false) {
97
+ clauses.push("OWNED BY NONE");
98
+ }
99
+ return `GENERATED ${sequence.precedence} AS IDENTITY${clauses.length ? ` (${clauses.join(" ")})` : ""}`;
100
+ };
101
+ const referencesClause = (column) => {
102
+ const { references, onDelete } = column;
103
+ const target = typeof references === "string" && (references.startsWith('"') || references.endsWith(")")) ? references : literal(references);
104
+ return `REFERENCES ${target}${onDelete ? ` ON DELETE ${onDelete}` : ""}`;
105
+ };
106
+ const columnLines = (columns) => {
107
+ const applied = Object.entries(columns).map(([name, column]) => [name, applyColumnShorthand(column)]);
108
+ const primaryKey = applied.filter(([, column]) => column.primaryKey).map(([name]) => name);
109
+ const lines = applied.map(([name, column]) => {
110
+ const constraints = [];
111
+ if (column.collation) {
112
+ constraints.push(`COLLATE ${column.collation}`);
113
+ }
114
+ if (column.default !== void 0) {
115
+ constraints.push(`DEFAULT ${escapeValue(column.default)}`);
116
+ }
117
+ if (column.unique) {
118
+ constraints.push("UNIQUE");
119
+ }
120
+ if (column.primaryKey && primaryKey.length === 1) {
121
+ constraints.push("PRIMARY KEY");
122
+ }
123
+ if (column.notNull) {
124
+ constraints.push("NOT NULL");
125
+ }
126
+ if (column.references) {
127
+ constraints.push(referencesClause({ ...column, references: column.references }));
128
+ }
129
+ if (column.sequenceGenerated) {
130
+ constraints.push(sequenceClause(column.sequenceGenerated));
131
+ }
132
+ return `${literal(name)} ${column.type}${constraints.length ? ` ${constraints.join(" ")}` : ""}`;
133
+ });
134
+ return { lines, primaryKey: primaryKey.length > 1 ? primaryKey : [] };
135
+ };
136
+ const tableNameOf = (table) => typeof table === "object" ? table.name : table;
137
+ class MigrationBuilder {
138
+ constructor() {
139
+ __publicField(this, "steps", []);
140
+ }
141
+ getSqlSteps() {
142
+ return [...this.steps];
143
+ }
144
+ getSql() {
145
+ return `${this.steps.join("\n")}
146
+ `;
147
+ }
148
+ sql(sql) {
149
+ this.steps.push(sql.lastIndexOf(";") !== sql.length - 1 ? `${sql};` : sql);
150
+ }
151
+ createTable(table, columns) {
152
+ const { lines, primaryKey } = columnLines(columns);
153
+ const definition = primaryKey.length > 0 ? [...lines, `CONSTRAINT ${literal(`${tableNameOf(table)}_pkey`)} PRIMARY KEY (${primaryKey.map((name) => literal(name)).join(", ")})`] : lines;
154
+ this.steps.push(`CREATE TABLE ${literal(table)} (
155
+ ${formatLines(definition)}
156
+ );`);
157
+ }
158
+ dropTable(table) {
159
+ this.steps.push(`DROP TABLE ${literal(table)};`);
160
+ }
161
+ renameTable(table, newName) {
162
+ this.steps.push(`ALTER TABLE ${literal(table)} RENAME TO ${literal(newName)};`);
163
+ }
164
+ addColumn(table, columns) {
165
+ this.steps.push(`ALTER TABLE ${literal(table)}
166
+ ${formatLines(columnLines(columns).lines, " ADD ")};`);
167
+ }
168
+ dropColumn(table, column) {
169
+ this.steps.push(`ALTER TABLE ${literal(table)}
170
+ ${formatLines([literal(column)], " DROP ")};`);
171
+ }
172
+ renameColumn(table, column, newName) {
173
+ this.steps.push(`ALTER TABLE ${literal(table)} RENAME ${literal(column)} TO ${literal(newName)};`);
174
+ }
175
+ alterColumn(table, column, options) {
176
+ const actions = [];
177
+ if (options.type) {
178
+ const collation = options.collation ? ` COLLATE ${options.collation}` : "";
179
+ const using = options.using ? ` USING ${options.using}` : "";
180
+ actions.push(`SET DATA TYPE ${adaptType(options.type)}${collation}${using}`);
181
+ }
182
+ if (options.notNull) {
183
+ actions.push("SET NOT NULL");
184
+ } else if (options.notNull === false) {
185
+ actions.push("DROP NOT NULL");
186
+ }
187
+ if (options.sequenceGenerated !== void 0) {
188
+ actions.push(options.sequenceGenerated ? `ADD ${sequenceClause(options.sequenceGenerated)}` : "DROP IDENTITY");
189
+ }
190
+ if (actions.length > 0) {
191
+ this.steps.push(`ALTER TABLE ${literal(table)}
192
+ ${formatLines(actions, ` ALTER ${literal(column)} `)};`);
193
+ } else {
194
+ this.steps.push("");
195
+ }
196
+ }
197
+ addConstraint(table, constraintName, options) {
198
+ const name = literal(constraintName || `${tableNameOf(table)}_pkey`);
199
+ const constraint = `CONSTRAINT ${name} PRIMARY KEY (${options.primaryKey.map((column) => literal(column)).join(", ")})`;
200
+ this.steps.push(`ALTER TABLE ${literal(table)}
201
+ ${formatLines([constraint], " ADD ")};`);
202
+ }
203
+ dropConstraint(table, constraintName) {
204
+ this.steps.push(`ALTER TABLE ${literal(table)} DROP CONSTRAINT ${literal(constraintName)};`);
205
+ }
206
+ createIndex(table, columns, options) {
207
+ const columnsSql = columns.map((column) => /[. ()]/.test(column) ? column : literal(column)).join(", ");
208
+ const name = options.name || `${tableNameOf(table)}_${columns.join("_")}_index`;
209
+ this.steps.push(`CREATE INDEX ${literal(name)} ON ${literal(table)} (${columnsSql});`);
210
+ }
211
+ createDomain(domain, type, options) {
212
+ const constraintName = options.constraintName ? ` CONSTRAINT ${literal(options.constraintName)}` : "";
213
+ const check = options.check ? `${constraintName} CHECK (${options.check})` : "";
214
+ this.steps.push(`CREATE DOMAIN ${literal(domain)} AS ${resolveType(type)}${check};`);
215
+ }
216
+ renameDomain(domain, newName) {
217
+ this.steps.push(`ALTER DOMAIN ${literal(domain)} RENAME TO ${literal(newName)};`);
218
+ }
219
+ dropDomain(domain) {
220
+ this.steps.push(`DROP DOMAIN ${literal(domain)};`);
221
+ }
222
+ createView(view, options, definition) {
223
+ this.steps.push(`CREATE${options.replace ? " OR REPLACE" : ""} VIEW ${literal(view)} AS ${definition};`);
224
+ }
225
+ renameView(view, newName) {
226
+ this.steps.push(`ALTER VIEW ${literal(view)} RENAME TO ${literal(newName)};`);
227
+ }
228
+ dropView(view) {
229
+ this.steps.push(`DROP VIEW ${literal(view)};`);
230
+ }
231
+ createMaterializedView(view, options, definition) {
232
+ const data = options.data !== void 0 ? ` WITH${options.data ? "" : " NO"} DATA` : "";
233
+ this.steps.push(`CREATE MATERIALIZED VIEW ${literal(view)} AS ${definition}${data};`);
234
+ }
235
+ dropMaterializedView(view) {
236
+ this.steps.push(`DROP MATERIALIZED VIEW ${literal(view)};`);
237
+ }
238
+ createTrigger(table, trigger, options) {
239
+ const { constraint, deferrable, deferred, functionParams = [], level = "STATEMENT" } = options;
240
+ const when = constraint ? "AFTER" : options.when;
241
+ const operations = typeof options.operation === "string" ? options.operation : options.operation.join(" OR ");
242
+ if (!options.function) {
243
+ throw new Error("Can't determine function name");
244
+ }
245
+ if (!operations) {
246
+ throw new Error('"operation" (INSERT/UPDATE[ OF ...]/DELETE/TRUNCATE) have to be specified');
247
+ }
248
+ const defer = constraint ? `${deferrable ? `DEFERRABLE INITIALLY ${deferred ? "DEFERRED" : "IMMEDIATE"}` : "NOT DEFERRABLE"}
249
+ ` : "";
250
+ this.steps.push(
251
+ `CREATE${constraint ? " CONSTRAINT" : ""} TRIGGER ${literal(trigger)}
252
+ ${when} ${operations} ON ${literal(table)}
253
+ ${defer}FOR EACH ${level}
254
+ EXECUTE PROCEDURE ${literal(options.function)}(${functionParams.map(escapeValue).join(", ")});`
255
+ );
256
+ }
257
+ dropTrigger(table, trigger, options = {}) {
258
+ this.steps.push(`DROP TRIGGER${options.ifExists ? " IF EXISTS" : ""} ${literal(trigger)} ON ${literal(table)};`);
259
+ }
260
+ dropFunction(fn, params) {
261
+ const paramsSql = params.map((param) => [param.name ? literal(param.name) : "", param.type ? resolveType(param.type) : ""].filter(Boolean).join(" ")).join(", ");
262
+ this.steps.push(`DROP FUNCTION ${literal(fn)}(${paramsSql});`);
263
+ }
264
+ }
265
+ exports.MigrationBuilder = MigrationBuilder;
266
+ exports.escapeValue = escapeValue;
267
+ //# sourceMappingURL=MigrationBuilder.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"MigrationBuilder.cjs","sources":["../../../../packages/database-migrations/src/MigrationBuilder.ts"],"sourcesContent":["/*\nThe SQL generation in this file is ported from the migration builder of node-pg-migrate. (https://github.com/salsita/node-pg-migrate)\n\nThe MIT License (MIT)\n\nCopyright (c) 2016-2020 Salsita Software &lt;jando@salsitasoft.com&gt;\n\nCopyright (c) 2014-2016 Theo Ephraim\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n */\n\n// Collects the SQL of engine and content migrations. The output reproduces node-pg-migrate 5 byte for byte for the\n// operations and options below, because not-yet-run migrations on existing databases must execute the same SQL.\n\nexport type Name = string | { schema?: string; name: string }\n\nexport type Value = null | boolean | string | number | readonly Value[]\n\nexport interface SequenceOptions {\n\tprecedence: 'ALWAYS' | 'BY DEFAULT'\n\ttype?: string\n\tincrement?: number\n\tminvalue?: number | null | false\n\tmaxvalue?: number | null | false\n\tstart?: number\n\tcache?: number\n\tcycle?: boolean\n\towner?: string | null | false\n}\n\nexport interface ColumnDefinition {\n\ttype: string\n\tcollation?: string\n\tdefault?: Value\n\tunique?: boolean\n\tprimaryKey?: boolean\n\tnotNull?: boolean\n\treferences?: Name\n\tonDelete?: string\n\tsequenceGenerated?: SequenceOptions\n}\n\nexport interface AlterColumnOptions {\n\ttype?: string\n\tcollation?: string\n\tusing?: string\n\tnotNull?: boolean\n\tsequenceGenerated?: SequenceOptions | false\n}\n\nexport interface TriggerOptions {\n\twhen: 'BEFORE' | 'AFTER'\n\toperation: string | readonly string[]\n\tlevel?: 'ROW' | 'STATEMENT'\n\tfunction: Name\n\tfunctionParams?: readonly Value[]\n\tconstraint?: boolean\n\tdeferrable?: boolean\n\tdeferred?: boolean\n}\n\nexport interface FunctionParam {\n\tname: string\n\ttype: string\n}\n\nconst quote = (identifier: string): string => `\"${identifier}\"`\n\nconst literal = (name: Name): string => typeof name === 'object' ? (name.schema ? `${quote(name.schema)}.` : '') + quote(name.name) : quote(name)\n\nconst nextDollarTag = function*(): Generator<string> {\n\tconst chars = 'abcdefghijklmnopqrstuvwxyz'\n\tconst ids = [0]\n\twhile (true) {\n\t\tyield `$pg${ids.map(id => chars[id]).join('')}$`\n\t\tlet i = ids.length - 1\n\t\tfor (; i >= 0; i--) {\n\t\t\tids[i] += 1\n\t\t\tif (ids[i] < chars.length) {\n\t\t\t\tbreak\n\t\t\t}\n\t\t\tids[i] = 0\n\t\t}\n\t\tif (i < 0) {\n\t\t\tids.unshift(0)\n\t\t}\n\t}\n}\n\nexport const escapeValue = (value: unknown): string | number => {\n\tif (value === null) {\n\t\treturn 'NULL'\n\t}\n\tif (typeof value === 'boolean') {\n\t\treturn value.toString()\n\t}\n\tif (typeof value === 'string') {\n\t\tfor (const tag of nextDollarTag()) {\n\t\t\tif (!value.includes(tag)) {\n\t\t\t\treturn `${tag}${value}${tag}`\n\t\t\t}\n\t\t}\n\t}\n\tif (typeof value === 'number') {\n\t\treturn value\n\t}\n\tif (Array.isArray(value)) {\n\t\treturn `ARRAY[${value.map(escapeValue).join(',').replace(/ARRAY/g, '')}]`\n\t}\n\t// node-pg-migrate's PgLiteral shape; migration JSON (e.g. a fill value or column default) can carry it.\n\tif (typeof value === 'object' && 'literal' in value && value.literal === true && 'value' in value) {\n\t\treturn typeof value.value === 'number' ? value.value : `${value.value}`\n\t}\n\treturn ''\n}\n\nconst typeAdapters: Record<string, string> = {\n\tint: 'integer',\n\tstring: 'text',\n\tfloat: 'real',\n\tdouble: 'double precision',\n\tdatetime: 'timestamp',\n\tbool: 'boolean',\n}\n\nconst adaptType = (type: string): string => typeAdapters[type] ?? type\n\n// `id` is node-pg-migrate's only default type shorthand; on columns it also implies a primary key.\nconst resolveType = (type: string): string => type === 'id' ? 'serial' : adaptType(type)\n\nconst applyColumnShorthand = (column: ColumnDefinition): ColumnDefinition =>\n\tcolumn.type === 'id' ? { primaryKey: true, ...column, type: 'serial' } : { ...column, type: adaptType(column.type) }\n\nconst formatLines = (lines: readonly string[], prefix = ' ', separator = ','): string =>\n\tlines\n\t\t.map(line => line.replace(/(?:\\r\\n|\\r|\\n)+/g, ' '))\n\t\t.join(`${separator}\\n`)\n\t\t.replace(/^/gm, prefix)\n\n// Sequence options arrive unparsed from migration JSON, so every option node-pg-migrate rendered is kept.\nconst sequenceClause = (sequence: SequenceOptions): string => {\n\tconst { type, increment, minvalue, maxvalue, start, cache, cycle, owner } = sequence\n\tconst clauses: string[] = []\n\tif (type) {\n\t\tclauses.push(`AS ${resolveType(type)}`)\n\t}\n\tif (increment) {\n\t\tclauses.push(`INCREMENT BY ${increment}`)\n\t}\n\tif (minvalue) {\n\t\tclauses.push(`MINVALUE ${minvalue}`)\n\t} else if (minvalue === null || minvalue === false) {\n\t\tclauses.push('NO MINVALUE')\n\t}\n\tif (maxvalue) {\n\t\tclauses.push(`MAXVALUE ${maxvalue}`)\n\t} else if (maxvalue === null || maxvalue === false) {\n\t\tclauses.push('NO MAXVALUE')\n\t}\n\tif (start) {\n\t\tclauses.push(`START WITH ${start}`)\n\t}\n\tif (cache) {\n\t\tclauses.push(`CACHE ${cache}`)\n\t}\n\tif (cycle) {\n\t\tclauses.push('CYCLE')\n\t} else if (cycle === false) {\n\t\tclauses.push('NO CYCLE')\n\t}\n\tif (owner) {\n\t\tclauses.push(`OWNED BY ${owner}`)\n\t} else if (owner === null || owner === false) {\n\t\tclauses.push('OWNED BY NONE')\n\t}\n\treturn `GENERATED ${sequence.precedence} AS IDENTITY${clauses.length ? ` (${clauses.join(' ')})` : ''}`\n}\n\nconst referencesClause = (column: ColumnDefinition & { references: Name }): string => {\n\tconst { references, onDelete } = column\n\tconst target = typeof references === 'string' && (references.startsWith('\"') || references.endsWith(')')) ? references : literal(references)\n\treturn `REFERENCES ${target}${onDelete ? ` ON DELETE ${onDelete}` : ''}`\n}\n\nconst columnLines = (columns: Record<string, ColumnDefinition>): { lines: string[]; primaryKey: string[] } => {\n\tconst applied = Object.entries(columns).map(([name, column]) => [name, applyColumnShorthand(column)] as const)\n\tconst primaryKey = applied.filter(([, column]) => column.primaryKey).map(([name]) => name)\n\tconst lines = applied.map(([name, column]) => {\n\t\tconst constraints: string[] = []\n\t\tif (column.collation) {\n\t\t\tconstraints.push(`COLLATE ${column.collation}`)\n\t\t}\n\t\tif (column.default !== undefined) {\n\t\t\tconstraints.push(`DEFAULT ${escapeValue(column.default)}`)\n\t\t}\n\t\tif (column.unique) {\n\t\t\tconstraints.push('UNIQUE')\n\t\t}\n\t\tif (column.primaryKey && primaryKey.length === 1) {\n\t\t\tconstraints.push('PRIMARY KEY')\n\t\t}\n\t\tif (column.notNull) {\n\t\t\tconstraints.push('NOT NULL')\n\t\t}\n\t\tif (column.references) {\n\t\t\tconstraints.push(referencesClause({ ...column, references: column.references }))\n\t\t}\n\t\tif (column.sequenceGenerated) {\n\t\t\tconstraints.push(sequenceClause(column.sequenceGenerated))\n\t\t}\n\t\treturn `${literal(name)} ${column.type}${constraints.length ? ` ${constraints.join(' ')}` : ''}`\n\t})\n\treturn { lines, primaryKey: primaryKey.length > 1 ? primaryKey : [] }\n}\n\nconst tableNameOf = (table: Name): string => typeof table === 'object' ? table.name : table\n\nexport class MigrationBuilder {\n\tprivate readonly steps: string[] = []\n\n\tgetSqlSteps(): string[] {\n\t\treturn [...this.steps]\n\t}\n\n\tgetSql(): string {\n\t\treturn `${this.steps.join('\\n')}\\n`\n\t}\n\n\tsql(sql: string): void {\n\t\tthis.steps.push(sql.lastIndexOf(';') !== sql.length - 1 ? `${sql};` : sql)\n\t}\n\n\tcreateTable(table: Name, columns: Record<string, ColumnDefinition>): void {\n\t\tconst { lines, primaryKey } = columnLines(columns)\n\t\tconst definition = primaryKey.length > 0\n\t\t\t? [...lines, `CONSTRAINT ${literal(`${tableNameOf(table)}_pkey`)} PRIMARY KEY (${primaryKey.map(name => literal(name)).join(', ')})`]\n\t\t\t: lines\n\t\tthis.steps.push(`CREATE TABLE ${literal(table)} (\\n${formatLines(definition)}\\n);`)\n\t}\n\n\tdropTable(table: Name): void {\n\t\tthis.steps.push(`DROP TABLE ${literal(table)};`)\n\t}\n\n\trenameTable(table: Name, newName: Name): void {\n\t\tthis.steps.push(`ALTER TABLE ${literal(table)} RENAME TO ${literal(newName)};`)\n\t}\n\n\taddColumn(table: Name, columns: Record<string, ColumnDefinition>): void {\n\t\tthis.steps.push(`ALTER TABLE ${literal(table)}\\n${formatLines(columnLines(columns).lines, ' ADD ')};`)\n\t}\n\n\tdropColumn(table: Name, column: string): void {\n\t\tthis.steps.push(`ALTER TABLE ${literal(table)}\\n${formatLines([literal(column)], ' DROP ')};`)\n\t}\n\n\trenameColumn(table: Name, column: string, newName: string): void {\n\t\tthis.steps.push(`ALTER TABLE ${literal(table)} RENAME ${literal(column)} TO ${literal(newName)};`)\n\t}\n\n\talterColumn(table: Name, column: string, options: AlterColumnOptions): void {\n\t\tconst actions: string[] = []\n\t\tif (options.type) {\n\t\t\tconst collation = options.collation ? ` COLLATE ${options.collation}` : ''\n\t\t\tconst using = options.using ? ` USING ${options.using}` : ''\n\t\t\tactions.push(`SET DATA TYPE ${adaptType(options.type)}${collation}${using}`)\n\t\t}\n\t\tif (options.notNull) {\n\t\t\tactions.push('SET NOT NULL')\n\t\t} else if (options.notNull === false) {\n\t\t\tactions.push('DROP NOT NULL')\n\t\t}\n\t\tif (options.sequenceGenerated !== undefined) {\n\t\t\tactions.push(options.sequenceGenerated ? `ADD ${sequenceClause(options.sequenceGenerated)}` : 'DROP IDENTITY')\n\t\t}\n\t\tif (actions.length > 0) {\n\t\t\tthis.steps.push(`ALTER TABLE ${literal(table)}\\n${formatLines(actions, ` ALTER ${literal(column)} `)};`)\n\t\t} else {\n\t\t\tthis.steps.push('')\n\t\t}\n\t}\n\n\taddConstraint(table: Name, constraintName: string | null, options: { primaryKey: readonly string[] }): void {\n\t\tconst name = literal(constraintName || `${tableNameOf(table)}_pkey`)\n\t\tconst constraint = `CONSTRAINT ${name} PRIMARY KEY (${options.primaryKey.map(column => literal(column)).join(', ')})`\n\t\tthis.steps.push(`ALTER TABLE ${literal(table)}\\n${formatLines([constraint], ' ADD ')};`)\n\t}\n\n\tdropConstraint(table: Name, constraintName: string): void {\n\t\tthis.steps.push(`ALTER TABLE ${literal(table)} DROP CONSTRAINT ${literal(constraintName)};`)\n\t}\n\n\tcreateIndex(table: Name, columns: readonly string[], options: { name: string }): void {\n\t\tconst columnsSql = columns.map(column => /[. ()]/.test(column) ? column : literal(column)).join(', ')\n\t\tconst name = options.name || `${tableNameOf(table)}_${columns.join('_')}_index`\n\t\tthis.steps.push(`CREATE INDEX ${literal(name)} ON ${literal(table)} (${columnsSql});`)\n\t}\n\n\tcreateDomain(domain: Name, type: string, options: { check: string; constraintName?: string }): void {\n\t\tconst constraintName = options.constraintName ? ` CONSTRAINT ${literal(options.constraintName)}` : ''\n\t\tconst check = options.check ? `${constraintName} CHECK (${options.check})` : ''\n\t\tthis.steps.push(`CREATE DOMAIN ${literal(domain)} AS ${resolveType(type)}${check};`)\n\t}\n\n\trenameDomain(domain: Name, newName: Name): void {\n\t\tthis.steps.push(`ALTER DOMAIN ${literal(domain)} RENAME TO ${literal(newName)};`)\n\t}\n\n\tdropDomain(domain: Name): void {\n\t\tthis.steps.push(`DROP DOMAIN ${literal(domain)};`)\n\t}\n\n\tcreateView(view: Name, options: { replace?: boolean }, definition: string): void {\n\t\tthis.steps.push(`CREATE${options.replace ? ' OR REPLACE' : ''} VIEW ${literal(view)} AS ${definition};`)\n\t}\n\n\trenameView(view: Name, newName: Name): void {\n\t\tthis.steps.push(`ALTER VIEW ${literal(view)} RENAME TO ${literal(newName)};`)\n\t}\n\n\tdropView(view: Name): void {\n\t\tthis.steps.push(`DROP VIEW ${literal(view)};`)\n\t}\n\n\tcreateMaterializedView(view: Name, options: { data?: boolean }, definition: string): void {\n\t\tconst data = options.data !== undefined ? ` WITH${options.data ? '' : ' NO'} DATA` : ''\n\t\tthis.steps.push(`CREATE MATERIALIZED VIEW ${literal(view)} AS ${definition}${data};`)\n\t}\n\n\tdropMaterializedView(view: Name): void {\n\t\tthis.steps.push(`DROP MATERIALIZED VIEW ${literal(view)};`)\n\t}\n\n\tcreateTrigger(table: Name, trigger: string, options: TriggerOptions): void {\n\t\tconst { constraint, deferrable, deferred, functionParams = [], level = 'STATEMENT' } = options\n\t\tconst when = constraint ? 'AFTER' : options.when\n\t\tconst operations = typeof options.operation === 'string' ? options.operation : options.operation.join(' OR ')\n\t\tif (!options.function) {\n\t\t\tthrow new Error(\"Can't determine function name\")\n\t\t}\n\t\tif (!operations) {\n\t\t\tthrow new Error('\"operation\" (INSERT/UPDATE[ OF ...]/DELETE/TRUNCATE) have to be specified')\n\t\t}\n\t\tconst defer = constraint ? `${deferrable ? `DEFERRABLE INITIALLY ${deferred ? 'DEFERRED' : 'IMMEDIATE'}` : 'NOT DEFERRABLE'}\\n ` : ''\n\t\tthis.steps.push(\n\t\t\t`CREATE${constraint ? ' CONSTRAINT' : ''} TRIGGER ${literal(trigger)}\\n`\n\t\t\t\t+ ` ${when} ${operations} ON ${literal(table)}\\n`\n\t\t\t\t+ ` ${defer}FOR EACH ${level}\\n`\n\t\t\t\t+ ` EXECUTE PROCEDURE ${literal(options.function)}(${functionParams.map(escapeValue).join(', ')});`,\n\t\t)\n\t}\n\n\tdropTrigger(table: Name, trigger: string, options: { ifExists?: boolean } = {}): void {\n\t\tthis.steps.push(`DROP TRIGGER${options.ifExists ? ' IF EXISTS' : ''} ${literal(trigger)} ON ${literal(table)};`)\n\t}\n\n\tdropFunction(fn: Name, params: readonly FunctionParam[]): void {\n\t\tconst paramsSql = params.map(param => [param.name ? literal(param.name) : '', param.type ? resolveType(param.type) : ''].filter(Boolean).join(' '))\n\t\t\t.join(', ')\n\t\tthis.steps.push(`DROP FUNCTION ${literal(fn)}(${paramsSql});`)\n\t}\n}\n"],"names":[],"mappings":";;;;;AAmFA,MAAM,QAAQ,CAAC,eAA+B,IAAI,UAAU;AAE5D,MAAM,UAAU,CAAC,SAAuB,OAAO,SAAS,YAAY,KAAK,SAAS,GAAG,MAAM,KAAK,MAAM,CAAC,MAAM,MAAM,MAAM,KAAK,IAAI,IAAI,MAAM,IAAI;AAEhJ,MAAM,gBAAgB,aAA+B;AACpD,QAAM,QAAQ;AACd,QAAM,MAAM,CAAC,CAAC;AACd,SAAO,MAAM;AACZ,UAAM,MAAM,IAAI,IAAI,CAAA,OAAM,MAAM,EAAE,CAAC,EAAE,KAAK,EAAE,CAAC;AAC7C,QAAI,IAAI,IAAI,SAAS;AACrB,WAAO,KAAK,GAAG,KAAK;AACnB,UAAI,CAAC,KAA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