@prisma-next/target-postgres 0.13.0 → 0.14.0-dev.2
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.
- package/dist/{codec-ids-CTikp1if.mjs → codec-ids-BvytN2P8.mjs} +3 -3
- package/dist/codec-ids-BvytN2P8.mjs.map +1 -0
- package/dist/{codec-ids-B1vOchLE.d.mts → codec-ids-CnXu9Qy3.d.mts} +3 -3
- package/dist/codec-ids-CnXu9Qy3.d.mts.map +1 -0
- package/dist/codec-ids.d.mts +2 -2
- package/dist/codec-ids.mjs +2 -2
- package/dist/{codec-types-CnFiNML4.d.mts → codec-types-DHCkwPKE.d.mts} +3 -3
- package/dist/{codec-types-CnFiNML4.d.mts.map → codec-types-DHCkwPKE.d.mts.map} +1 -1
- package/dist/codec-types.d.mts +1 -1
- package/dist/{codecs-CBpEv4s5.d.mts → codecs--0A5_4Bq.d.mts} +26 -23
- package/dist/codecs--0A5_4Bq.d.mts.map +1 -0
- package/dist/codecs.d.mts +2 -2
- package/dist/codecs.mjs +28 -35
- package/dist/codecs.mjs.map +1 -1
- package/dist/contract-free.d.mts +163 -15
- package/dist/contract-free.d.mts.map +1 -1
- package/dist/contract-free.mjs +4 -17
- package/dist/contract-free.mjs.map +1 -1
- package/dist/control.d.mts.map +1 -1
- package/dist/control.mjs +21 -27
- package/dist/control.mjs.map +1 -1
- package/dist/{data-transform-D25tLeYU.mjs → data-transform-BOWpliq8.mjs} +9 -17
- package/dist/data-transform-BOWpliq8.mjs.map +1 -0
- package/dist/{data-transform-DGOqcLrf.d.mts → data-transform-DDgWdB5o.d.mts} +2 -2
- package/dist/data-transform-DDgWdB5o.d.mts.map +1 -0
- package/dist/data-transform.d.mts +1 -1
- package/dist/data-transform.mjs +1 -1
- package/dist/ddl-QDyOSeLc.mjs +251 -0
- package/dist/ddl-QDyOSeLc.mjs.map +1 -0
- package/dist/ddl.d.mts +2 -2
- package/dist/ddl.mjs +2 -2
- package/dist/descriptor-meta-CpGygXpI.mjs +140 -0
- package/dist/descriptor-meta-CpGygXpI.mjs.map +1 -0
- package/dist/{issue-planner-Br0pt1Ea.mjs → issue-planner-DL6g3CmE.mjs} +52 -366
- package/dist/issue-planner-DL6g3CmE.mjs.map +1 -0
- package/dist/issue-planner.d.mts +8 -11
- package/dist/issue-planner.d.mts.map +1 -1
- package/dist/issue-planner.mjs +1 -1
- package/dist/migration.d.mts +5 -92
- package/dist/migration.d.mts.map +1 -1
- package/dist/migration.mjs +4 -4
- package/dist/{nodes-DZk2JZG3.mjs → nodes-Bbhs2rwj.mjs} +31 -2
- package/dist/nodes-Bbhs2rwj.mjs.map +1 -0
- package/dist/{nodes-779hmCfL.d.mts → nodes-pLeLgdis.d.mts} +30 -3
- package/dist/nodes-pLeLgdis.d.mts.map +1 -0
- package/dist/{op-factory-call-D2aAUhmS.mjs → op-factory-call-D_p5vxwt.mjs} +601 -418
- package/dist/op-factory-call-D_p5vxwt.mjs.map +1 -0
- package/dist/{op-factory-call-DMA86_2D.d.mts → op-factory-call-DmQEc3XV.d.mts} +119 -72
- package/dist/op-factory-call-DmQEc3XV.d.mts.map +1 -0
- package/dist/op-factory-call.d.mts +2 -2
- package/dist/op-factory-call.mjs +2 -2
- package/dist/pack.d.mts +36 -15
- package/dist/pack.d.mts.map +1 -1
- package/dist/pack.mjs +1 -1
- package/dist/{planner-CAYPJObw.mjs → planner-Bs_baQax.mjs} +25 -45
- package/dist/planner-Bs_baQax.mjs.map +1 -0
- package/dist/{planner-ddl-builders-Cw2n2llW.mjs → planner-ddl-builders-B2wOwLqI.mjs} +2 -2
- package/dist/planner-ddl-builders-B2wOwLqI.mjs.map +1 -0
- package/dist/planner-ddl-builders.d.mts +4 -4
- package/dist/planner-ddl-builders.d.mts.map +1 -1
- package/dist/planner-ddl-builders.mjs +1 -1
- package/dist/{planner-identity-values-BIpa5p2I.mjs → planner-identity-values-CJPha2Sz.mjs} +3 -9
- package/dist/planner-identity-values-CJPha2Sz.mjs.map +1 -0
- package/dist/planner-identity-values.d.mts +1 -1
- package/dist/planner-identity-values.d.mts.map +1 -1
- package/dist/planner-identity-values.mjs +1 -1
- package/dist/{planner-produced-postgres-migration-NSEhWL0L.mjs → planner-produced-postgres-migration-Cji5vxUf.mjs} +6 -4
- package/dist/planner-produced-postgres-migration-Cji5vxUf.mjs.map +1 -0
- package/dist/{planner-produced-postgres-migration-B4EDvLdz.d.mts → planner-produced-postgres-migration-QqHa2C2l.d.mts} +5 -6
- package/dist/planner-produced-postgres-migration-QqHa2C2l.d.mts.map +1 -0
- package/dist/planner-produced-postgres-migration.d.mts +1 -1
- package/dist/planner-produced-postgres-migration.mjs +1 -1
- package/dist/planner-sql-checks-jqUUGyQR.mjs +152 -0
- package/dist/planner-sql-checks-jqUUGyQR.mjs.map +1 -0
- package/dist/planner-sql-checks.d.mts +3 -49
- package/dist/planner-sql-checks.d.mts.map +1 -1
- package/dist/planner-sql-checks.mjs +2 -2
- package/dist/{planner-type-resolution-836DExFN.mjs → planner-type-resolution-Bt2f_q-F.mjs} +1 -6
- package/dist/planner-type-resolution-Bt2f_q-F.mjs.map +1 -0
- package/dist/planner.d.mts +4 -4
- package/dist/planner.d.mts.map +1 -1
- package/dist/planner.mjs +1 -1
- package/dist/{postgres-contract-serializer-DYTyXjPf.mjs → postgres-contract-serializer-k3TAcPMY.mjs} +30 -37
- package/dist/postgres-contract-serializer-k3TAcPMY.mjs.map +1 -0
- package/dist/postgres-migration-B5jKrXv3.mjs +145 -0
- package/dist/postgres-migration-B5jKrXv3.mjs.map +1 -0
- package/dist/postgres-migration-Y4YBJqkS.d.mts +181 -0
- package/dist/postgres-migration-Y4YBJqkS.d.mts.map +1 -0
- package/dist/{postgres-schema-BuxCxbvB.mjs → postgres-schema-COGZ1ark.mjs} +82 -23
- package/dist/postgres-schema-COGZ1ark.mjs.map +1 -0
- package/dist/{render-ops-BpjstrKQ.mjs → render-ops-BREh1kHe.mjs} +10 -5
- package/dist/render-ops-BREh1kHe.mjs.map +1 -0
- package/dist/render-ops.d.mts +2 -2
- package/dist/render-ops.d.mts.map +1 -1
- package/dist/render-ops.mjs +1 -1
- package/dist/runtime.d.mts +1 -0
- package/dist/runtime.d.mts.map +1 -1
- package/dist/runtime.mjs +2 -2
- package/dist/table-source-BvFo7gVs.d.mts +15 -0
- package/dist/table-source-BvFo7gVs.d.mts.map +1 -0
- package/dist/types.d.mts +34 -19
- package/dist/types.d.mts.map +1 -1
- package/dist/types.mjs +2 -3
- package/package.json +17 -18
- package/src/contract-free/checks.ts +363 -0
- package/src/contract-free/ddl.ts +28 -1
- package/src/core/authoring.ts +43 -44
- package/src/core/codec-helpers.ts +0 -17
- package/src/core/codec-ids.ts +1 -1
- package/src/core/codec-type-map.ts +2 -2
- package/src/core/codecs.ts +43 -48
- package/src/core/ddl/nodes.ts +59 -1
- package/src/core/migrations/control-policy.ts +17 -47
- package/src/core/migrations/issue-planner.ts +34 -70
- package/src/core/migrations/op-factory-call.ts +486 -215
- package/src/core/migrations/operations/columns.ts +175 -140
- package/src/core/migrations/operations/constraints.ts +79 -108
- package/src/core/migrations/operations/data-transform.ts +15 -18
- package/src/core/migrations/operations/dependencies.ts +16 -14
- package/src/core/migrations/operations/indexes.ts +31 -28
- package/src/core/migrations/operations/shared.ts +2 -2
- package/src/core/migrations/operations/tables.ts +13 -14
- package/src/core/migrations/planner-ddl-builders.ts +3 -4
- package/src/core/migrations/planner-identity-values.ts +4 -28
- package/src/core/migrations/planner-produced-postgres-migration.ts +15 -7
- package/src/core/migrations/planner-recipes.ts +44 -39
- package/src/core/migrations/planner-sql-checks.ts +3 -178
- package/src/core/migrations/planner-strategies.ts +76 -449
- package/src/core/migrations/planner-type-resolution.ts +2 -20
- package/src/core/migrations/planner.ts +6 -6
- package/src/core/migrations/postgres-migration.ts +287 -7
- package/src/core/migrations/render-ops.ts +26 -13
- package/src/core/migrations/runner.ts +26 -20
- package/src/core/postgres-contract-serializer.ts +37 -54
- package/src/core/postgres-enum-type-schema.ts +17 -0
- package/src/core/postgres-schema.ts +86 -46
- package/src/exports/codecs.ts +2 -2
- package/src/exports/contract-free.ts +22 -1
- package/src/exports/control.ts +0 -22
- package/src/exports/ddl.ts +4 -0
- package/src/exports/migration.ts +1 -29
- package/src/exports/op-factory-call.ts +0 -4
- package/src/exports/planner-sql-checks.ts +0 -7
- package/src/exports/types.ts +0 -1
- package/dist/codec-ids-B1vOchLE.d.mts.map +0 -1
- package/dist/codec-ids-CTikp1if.mjs.map +0 -1
- package/dist/codecs-CBpEv4s5.d.mts.map +0 -1
- package/dist/data-transform-D25tLeYU.mjs.map +0 -1
- package/dist/data-transform-DGOqcLrf.d.mts.map +0 -1
- package/dist/ddl-77SyXgFt.mjs +0 -30
- package/dist/ddl-77SyXgFt.mjs.map +0 -1
- package/dist/descriptor-meta-DKmj-IMN.mjs +0 -14
- package/dist/descriptor-meta-DKmj-IMN.mjs.map +0 -1
- package/dist/descriptor-meta-runtime-My8_s4cs.mjs +0 -130
- package/dist/descriptor-meta-runtime-My8_s4cs.mjs.map +0 -1
- package/dist/enum-planning-BCyvlFHk.mjs +0 -0
- package/dist/enum-planning-BCyvlFHk.mjs.map +0 -1
- package/dist/enum-planning.d.mts +0 -86
- package/dist/enum-planning.d.mts.map +0 -1
- package/dist/enum-planning.mjs +0 -2
- package/dist/issue-planner-Br0pt1Ea.mjs.map +0 -1
- package/dist/nodes-779hmCfL.d.mts.map +0 -1
- package/dist/nodes-DZk2JZG3.mjs.map +0 -1
- package/dist/op-factory-call-D2aAUhmS.mjs.map +0 -1
- package/dist/op-factory-call-DMA86_2D.d.mts.map +0 -1
- package/dist/planner-CAYPJObw.mjs.map +0 -1
- package/dist/planner-ddl-builders-Cw2n2llW.mjs.map +0 -1
- package/dist/planner-identity-values-BIpa5p2I.mjs.map +0 -1
- package/dist/planner-produced-postgres-migration-B4EDvLdz.d.mts.map +0 -1
- package/dist/planner-produced-postgres-migration-NSEhWL0L.mjs.map +0 -1
- package/dist/planner-sql-checks-DAdhnI2c.mjs +0 -272
- package/dist/planner-sql-checks-DAdhnI2c.mjs.map +0 -1
- package/dist/planner-type-resolution-836DExFN.mjs.map +0 -1
- package/dist/postgres-contract-serializer-DYTyXjPf.mjs.map +0 -1
- package/dist/postgres-enum-type-BVn63a89.d.mts +0 -72
- package/dist/postgres-enum-type-BVn63a89.d.mts.map +0 -1
- package/dist/postgres-enum-type-DPKqCBem.mjs +0 -62
- package/dist/postgres-enum-type-DPKqCBem.mjs.map +0 -1
- package/dist/postgres-migration-COore9Mz.mjs +0 -71
- package/dist/postgres-migration-COore9Mz.mjs.map +0 -1
- package/dist/postgres-migration-DZ_gLUOW.d.mts +0 -72
- package/dist/postgres-migration-DZ_gLUOW.d.mts.map +0 -1
- package/dist/postgres-schema-BuxCxbvB.mjs.map +0 -1
- package/dist/render-ops-BpjstrKQ.mjs.map +0 -1
- package/dist/shared-DarONYBZ.d.mts +0 -43
- package/dist/shared-DarONYBZ.d.mts.map +0 -1
- package/src/core/migrations/enum-planning.ts +0 -213
- package/src/core/migrations/operations/enums.ts +0 -114
- package/src/core/postgres-enum-type.ts +0 -89
- package/src/exports/enum-planning.ts +0 -11
|
@@ -1,18 +1,20 @@
|
|
|
1
|
-
import { i as quoteIdentifier, n as escapeLiteral
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
1
|
+
import { i as quoteIdentifier, n as escapeLiteral } from "./sql-utils-DcfMz4MQ.mjs";
|
|
2
|
+
import { a as columnDefaultAst, c as columnTypeAst, d as indexExistsAst, f as noNullValuesAst, i as createTable, l as constraintExistsAst, m as tableIsEmptyAst, n as alterTable, o as columnExistsAst, p as tableExistsAst, r as createSchema, s as columnNullabilityAst, t as addColumnAction, u as extensionExistsAst } from "./ddl-QDyOSeLc.mjs";
|
|
3
|
+
import { n as qualifyTableName } from "./planner-sql-checks-jqUUGyQR.mjs";
|
|
4
|
+
import { t as buildAddColumnSql } from "./planner-ddl-builders-B2wOwLqI.mjs";
|
|
4
5
|
import { FunctionColumnDefault, LiteralColumnDefault } from "@prisma-next/sql-relational-core/ast";
|
|
6
|
+
import { blindCast } from "@prisma-next/utils/casts";
|
|
5
7
|
import { ifDefined } from "@prisma-next/utils/defined";
|
|
6
8
|
import { UNBOUND_NAMESPACE_ID } from "@prisma-next/framework-components/ir";
|
|
7
|
-
import { blindCast } from "@prisma-next/utils/casts";
|
|
8
9
|
import { errorUnfilledPlaceholder } from "@prisma-next/errors/migration";
|
|
9
10
|
import { TsExpression, jsonToTsSource } from "@prisma-next/ts-render";
|
|
10
11
|
import { REFERENTIAL_ACTION_SQL } from "@prisma-next/sql-contract/referential-action-sql";
|
|
11
12
|
//#region src/core/migrations/operations/shared.ts
|
|
12
|
-
function step(description, sql) {
|
|
13
|
+
function step(description, sql, params) {
|
|
13
14
|
return {
|
|
14
15
|
description,
|
|
15
|
-
sql
|
|
16
|
+
sql,
|
|
17
|
+
...ifDefined("params", params)
|
|
16
18
|
};
|
|
17
19
|
}
|
|
18
20
|
function targetDetails(objectType, name, schema, table) {
|
|
@@ -28,51 +30,28 @@ function targetDetails(objectType, name, schema, table) {
|
|
|
28
30
|
}
|
|
29
31
|
//#endregion
|
|
30
32
|
//#region src/core/migrations/operations/columns.ts
|
|
31
|
-
function
|
|
32
|
-
const
|
|
33
|
-
`ALTER TABLE ${qualifyTableName(schemaName, tableName)}`,
|
|
34
|
-
`ADD COLUMN ${quoteIdentifier(column.name)} ${column.typeSql}`,
|
|
35
|
-
column.defaultSql,
|
|
36
|
-
column.nullable ? "" : "NOT NULL"
|
|
37
|
-
].filter(Boolean).join(" ");
|
|
33
|
+
async function columnExistsSteps(lowerer, options) {
|
|
34
|
+
const checks = columnExistsAst(options);
|
|
38
35
|
return {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
operationClass: "additive",
|
|
42
|
-
target: targetDetails("column", column.name, schemaName, tableName),
|
|
43
|
-
precheck: [step(`ensure column "${column.name}" is missing`, columnExistsCheck({
|
|
44
|
-
schema: schemaName,
|
|
45
|
-
table: tableName,
|
|
46
|
-
column: column.name,
|
|
47
|
-
exists: false
|
|
48
|
-
}))],
|
|
49
|
-
execute: [step(`add column "${column.name}"`, addSql)],
|
|
50
|
-
postcheck: [step(`verify column "${column.name}" exists`, columnExistsCheck({
|
|
51
|
-
schema: schemaName,
|
|
52
|
-
table: tableName,
|
|
53
|
-
column: column.name
|
|
54
|
-
}))]
|
|
36
|
+
present: await lowerer.lowerToExecuteRequest(checks.columnPresent()),
|
|
37
|
+
absent: await lowerer.lowerToExecuteRequest(checks.columnAbsent())
|
|
55
38
|
};
|
|
56
39
|
}
|
|
57
|
-
function dropColumn(schemaName, tableName, columnName) {
|
|
40
|
+
async function dropColumn(schemaName, tableName, columnName, lowerer) {
|
|
58
41
|
const qualified = qualifyTableName(schemaName, tableName);
|
|
42
|
+
const { present, absent } = await columnExistsSteps(lowerer, {
|
|
43
|
+
schema: schemaName,
|
|
44
|
+
table: tableName,
|
|
45
|
+
column: columnName
|
|
46
|
+
});
|
|
59
47
|
return {
|
|
60
48
|
id: `dropColumn.${tableName}.${columnName}`,
|
|
61
49
|
label: `Drop column "${columnName}" from "${tableName}"`,
|
|
62
50
|
operationClass: "destructive",
|
|
63
51
|
target: targetDetails("column", columnName, schemaName, tableName),
|
|
64
|
-
precheck: [step(`ensure column "${columnName}" exists`,
|
|
65
|
-
schema: schemaName,
|
|
66
|
-
table: tableName,
|
|
67
|
-
column: columnName
|
|
68
|
-
}))],
|
|
52
|
+
precheck: [step(`ensure column "${columnName}" exists`, present.sql, present.params)],
|
|
69
53
|
execute: [step(`drop column "${columnName}"`, `ALTER TABLE ${qualified} DROP COLUMN ${quoteIdentifier(columnName)}`)],
|
|
70
|
-
postcheck: [step(`verify column "${columnName}" does not exist`,
|
|
71
|
-
schema: schemaName,
|
|
72
|
-
table: tableName,
|
|
73
|
-
column: columnName,
|
|
74
|
-
exists: false
|
|
75
|
-
}))]
|
|
54
|
+
postcheck: [step(`verify column "${columnName}" does not exist`, absent.sql, absent.params)]
|
|
76
55
|
};
|
|
77
56
|
}
|
|
78
57
|
/**
|
|
@@ -83,69 +62,80 @@ function dropColumn(schemaName, tableName, columnName) {
|
|
|
83
62
|
* string appearing in the human-readable label (typically `toType` when
|
|
84
63
|
* explicit, else the column's native type).
|
|
85
64
|
*/
|
|
86
|
-
function alterColumnType(schemaName, tableName, columnName, options) {
|
|
65
|
+
async function alterColumnType(schemaName, tableName, columnName, options, lowerer) {
|
|
87
66
|
const qualified = qualifyTableName(schemaName, tableName);
|
|
88
67
|
const usingClause = options.using ? ` USING ${options.using}` : ` USING ${quoteIdentifier(columnName)}::${options.qualifiedTargetType}`;
|
|
68
|
+
const { present } = await columnExistsSteps(lowerer, {
|
|
69
|
+
schema: schemaName,
|
|
70
|
+
table: tableName,
|
|
71
|
+
column: columnName
|
|
72
|
+
});
|
|
73
|
+
const typeCheck = await lowerer.lowerToExecuteRequest(columnTypeAst({
|
|
74
|
+
schema: schemaName,
|
|
75
|
+
table: tableName,
|
|
76
|
+
column: columnName,
|
|
77
|
+
expectedType: options.formatTypeExpected
|
|
78
|
+
}));
|
|
89
79
|
return {
|
|
90
80
|
id: `alterType.${tableName}.${columnName}`,
|
|
91
81
|
label: `Alter type of "${tableName}"."${columnName}" to ${options.rawTargetTypeForLabel}`,
|
|
92
82
|
operationClass: "destructive",
|
|
93
83
|
target: targetDetails("column", columnName, schemaName, tableName),
|
|
94
|
-
precheck: [step(`ensure column "${columnName}" exists`,
|
|
95
|
-
schema: schemaName,
|
|
96
|
-
table: tableName,
|
|
97
|
-
column: columnName
|
|
98
|
-
}))],
|
|
84
|
+
precheck: [step(`ensure column "${columnName}" exists`, present.sql, present.params)],
|
|
99
85
|
execute: [step(`alter type of "${columnName}"`, `ALTER TABLE ${qualified} ALTER COLUMN ${quoteIdentifier(columnName)} TYPE ${options.qualifiedTargetType}${usingClause}`)],
|
|
100
|
-
postcheck: [step(`verify column "${columnName}" has type "${options.formatTypeExpected}"`,
|
|
101
|
-
schema: schemaName,
|
|
102
|
-
table: tableName,
|
|
103
|
-
column: columnName,
|
|
104
|
-
expectedType: options.formatTypeExpected
|
|
105
|
-
}))],
|
|
86
|
+
postcheck: [step(`verify column "${columnName}" has type "${options.formatTypeExpected}"`, typeCheck.sql, typeCheck.params)],
|
|
106
87
|
meta: { warning: "TABLE_REWRITE" }
|
|
107
88
|
};
|
|
108
89
|
}
|
|
109
|
-
function setNotNull(schemaName, tableName, columnName) {
|
|
90
|
+
async function setNotNull(schemaName, tableName, columnName, lowerer) {
|
|
110
91
|
const qualified = qualifyTableName(schemaName, tableName);
|
|
92
|
+
const { present } = await columnExistsSteps(lowerer, {
|
|
93
|
+
schema: schemaName,
|
|
94
|
+
table: tableName,
|
|
95
|
+
column: columnName
|
|
96
|
+
});
|
|
97
|
+
const noNulls = await lowerer.lowerToExecuteRequest(noNullValuesAst({
|
|
98
|
+
schema: schemaName,
|
|
99
|
+
table: tableName,
|
|
100
|
+
column: columnName
|
|
101
|
+
}));
|
|
102
|
+
const notNullable = await lowerer.lowerToExecuteRequest(columnNullabilityAst({
|
|
103
|
+
schema: schemaName,
|
|
104
|
+
table: tableName,
|
|
105
|
+
column: columnName,
|
|
106
|
+
nullable: false
|
|
107
|
+
}));
|
|
111
108
|
return {
|
|
112
109
|
id: `alterNullability.setNotNull.${tableName}.${columnName}`,
|
|
113
110
|
label: `Set NOT NULL on "${tableName}"."${columnName}"`,
|
|
114
111
|
operationClass: "destructive",
|
|
115
112
|
target: targetDetails("column", columnName, schemaName, tableName),
|
|
116
|
-
precheck: [step(`ensure column "${columnName}" exists`,
|
|
117
|
-
schema: schemaName,
|
|
118
|
-
table: tableName,
|
|
119
|
-
column: columnName
|
|
120
|
-
})), step(`ensure no NULL values in "${columnName}"`, `SELECT NOT EXISTS (SELECT 1 FROM ${qualified} WHERE ${quoteIdentifier(columnName)} IS NULL)`)],
|
|
113
|
+
precheck: [step(`ensure column "${columnName}" exists`, present.sql, present.params), step(`ensure no NULL values in "${columnName}"`, noNulls.sql, noNulls.params)],
|
|
121
114
|
execute: [step(`set NOT NULL on "${columnName}"`, `ALTER TABLE ${qualified} ALTER COLUMN ${quoteIdentifier(columnName)} SET NOT NULL`)],
|
|
122
|
-
postcheck: [step(`verify column "${columnName}" is NOT NULL`,
|
|
123
|
-
schema: schemaName,
|
|
124
|
-
table: tableName,
|
|
125
|
-
column: columnName,
|
|
126
|
-
nullable: false
|
|
127
|
-
}))]
|
|
115
|
+
postcheck: [step(`verify column "${columnName}" is NOT NULL`, notNullable.sql, notNullable.params)]
|
|
128
116
|
};
|
|
129
117
|
}
|
|
130
|
-
function dropNotNull(schemaName, tableName, columnName) {
|
|
118
|
+
async function dropNotNull(schemaName, tableName, columnName, lowerer) {
|
|
131
119
|
const qualified = qualifyTableName(schemaName, tableName);
|
|
120
|
+
const { present } = await columnExistsSteps(lowerer, {
|
|
121
|
+
schema: schemaName,
|
|
122
|
+
table: tableName,
|
|
123
|
+
column: columnName
|
|
124
|
+
});
|
|
125
|
+
const nullable = await lowerer.lowerToExecuteRequest(columnNullabilityAst({
|
|
126
|
+
schema: schemaName,
|
|
127
|
+
table: tableName,
|
|
128
|
+
column: columnName,
|
|
129
|
+
nullable: true
|
|
130
|
+
}));
|
|
132
131
|
return {
|
|
133
132
|
id: `alterNullability.dropNotNull.${tableName}.${columnName}`,
|
|
134
133
|
label: `Drop NOT NULL on "${tableName}"."${columnName}"`,
|
|
135
134
|
operationClass: "widening",
|
|
136
135
|
target: targetDetails("column", columnName, schemaName, tableName),
|
|
137
|
-
precheck: [step(`ensure column "${columnName}" exists`,
|
|
138
|
-
schema: schemaName,
|
|
139
|
-
table: tableName,
|
|
140
|
-
column: columnName
|
|
141
|
-
}))],
|
|
136
|
+
precheck: [step(`ensure column "${columnName}" exists`, present.sql, present.params)],
|
|
142
137
|
execute: [step(`drop NOT NULL on "${columnName}"`, `ALTER TABLE ${qualified} ALTER COLUMN ${quoteIdentifier(columnName)} DROP NOT NULL`)],
|
|
143
|
-
postcheck: [step(`verify column "${columnName}" is nullable`,
|
|
144
|
-
schema: schemaName,
|
|
145
|
-
table: tableName,
|
|
146
|
-
column: columnName,
|
|
147
|
-
nullable: true
|
|
148
|
-
}))]
|
|
138
|
+
postcheck: [step(`verify column "${columnName}" is nullable`, nullable.sql, nullable.params)]
|
|
149
139
|
};
|
|
150
140
|
}
|
|
151
141
|
/**
|
|
@@ -158,50 +148,94 @@ function dropNotNull(schemaName, tableName, columnName) {
|
|
|
158
148
|
* when the column already has a different default — policy enforcement
|
|
159
149
|
* treats that as a widening change rather than an additive one.
|
|
160
150
|
*/
|
|
161
|
-
function setDefault(schemaName, tableName, columnName, defaultSql, operationClass = "additive") {
|
|
151
|
+
async function setDefault(schemaName, tableName, columnName, defaultSql, lowerer, operationClass = "additive") {
|
|
162
152
|
const qualified = qualifyTableName(schemaName, tableName);
|
|
153
|
+
const { present } = await columnExistsSteps(lowerer, {
|
|
154
|
+
schema: schemaName,
|
|
155
|
+
table: tableName,
|
|
156
|
+
column: columnName
|
|
157
|
+
});
|
|
158
|
+
const hasDefault = await lowerer.lowerToExecuteRequest(columnDefaultAst({
|
|
159
|
+
schema: schemaName,
|
|
160
|
+
table: tableName,
|
|
161
|
+
column: columnName
|
|
162
|
+
}).defaultPresent());
|
|
163
163
|
return {
|
|
164
164
|
id: `setDefault.${tableName}.${columnName}`,
|
|
165
165
|
label: `Set default on "${tableName}"."${columnName}"`,
|
|
166
166
|
operationClass,
|
|
167
167
|
target: targetDetails("column", columnName, schemaName, tableName),
|
|
168
|
-
precheck: [step(`ensure column "${columnName}" exists`,
|
|
169
|
-
schema: schemaName,
|
|
170
|
-
table: tableName,
|
|
171
|
-
column: columnName
|
|
172
|
-
}))],
|
|
168
|
+
precheck: [step(`ensure column "${columnName}" exists`, present.sql, present.params)],
|
|
173
169
|
execute: [step(`set default on "${columnName}"`, `ALTER TABLE ${qualified} ALTER COLUMN ${quoteIdentifier(columnName)} SET ${defaultSql}`)],
|
|
174
|
-
postcheck: [step(`verify column "${columnName}" has a default`,
|
|
175
|
-
schema: schemaName,
|
|
176
|
-
table: tableName,
|
|
177
|
-
column: columnName,
|
|
178
|
-
exists: true
|
|
179
|
-
}))]
|
|
170
|
+
postcheck: [step(`verify column "${columnName}" has a default`, hasDefault.sql, hasDefault.params)]
|
|
180
171
|
};
|
|
181
172
|
}
|
|
182
|
-
function dropDefault(schemaName, tableName, columnName) {
|
|
173
|
+
async function dropDefault(schemaName, tableName, columnName, lowerer) {
|
|
183
174
|
const qualified = qualifyTableName(schemaName, tableName);
|
|
175
|
+
const { present } = await columnExistsSteps(lowerer, {
|
|
176
|
+
schema: schemaName,
|
|
177
|
+
table: tableName,
|
|
178
|
+
column: columnName
|
|
179
|
+
});
|
|
180
|
+
const noDefault = await lowerer.lowerToExecuteRequest(columnDefaultAst({
|
|
181
|
+
schema: schemaName,
|
|
182
|
+
table: tableName,
|
|
183
|
+
column: columnName
|
|
184
|
+
}).defaultAbsent());
|
|
184
185
|
return {
|
|
185
186
|
id: `dropDefault.${tableName}.${columnName}`,
|
|
186
187
|
label: `Drop default on "${tableName}"."${columnName}"`,
|
|
187
188
|
operationClass: "destructive",
|
|
188
189
|
target: targetDetails("column", columnName, schemaName, tableName),
|
|
189
|
-
precheck: [step(`ensure column "${columnName}" exists`,
|
|
190
|
-
schema: schemaName,
|
|
191
|
-
table: tableName,
|
|
192
|
-
column: columnName
|
|
193
|
-
}))],
|
|
190
|
+
precheck: [step(`ensure column "${columnName}" exists`, present.sql, present.params)],
|
|
194
191
|
execute: [step(`drop default on "${columnName}"`, `ALTER TABLE ${qualified} ALTER COLUMN ${quoteIdentifier(columnName)} DROP DEFAULT`)],
|
|
195
|
-
postcheck: [step(`verify column "${columnName}" has no default`,
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
192
|
+
postcheck: [step(`verify column "${columnName}" has no default`, noDefault.sql, noDefault.params)]
|
|
193
|
+
};
|
|
194
|
+
}
|
|
195
|
+
/**
|
|
196
|
+
* Builds the op for adding a NOT NULL column (no contract default) to a
|
|
197
|
+
* non-empty table. Prechecks assert the column is absent and the table is
|
|
198
|
+
* empty; the execute step is the raw ADD COLUMN SQL passed by the caller
|
|
199
|
+
* (slice-7 deferred); postchecks assert the column exists and is NOT NULL.
|
|
200
|
+
*/
|
|
201
|
+
async function addNotNullColumnDirect(schemaName, tableName, columnName, executeStepSql, lowerer) {
|
|
202
|
+
const absent = await lowerer.lowerToExecuteRequest(columnExistsAst({
|
|
203
|
+
schema: schemaName,
|
|
204
|
+
table: tableName,
|
|
205
|
+
column: columnName
|
|
206
|
+
}).columnAbsent());
|
|
207
|
+
const tableEmpty = await lowerer.lowerToExecuteRequest(tableIsEmptyAst(schemaName, tableName));
|
|
208
|
+
const present = await lowerer.lowerToExecuteRequest(columnExistsAst({
|
|
209
|
+
schema: schemaName,
|
|
210
|
+
table: tableName,
|
|
211
|
+
column: columnName
|
|
212
|
+
}).columnPresent());
|
|
213
|
+
const notNullable = await lowerer.lowerToExecuteRequest(columnNullabilityAst({
|
|
214
|
+
schema: schemaName,
|
|
215
|
+
table: tableName,
|
|
216
|
+
column: columnName,
|
|
217
|
+
nullable: false
|
|
218
|
+
}));
|
|
219
|
+
return {
|
|
220
|
+
id: `column.${tableName}.${columnName}`,
|
|
221
|
+
label: `Add column ${columnName} to ${tableName}`,
|
|
222
|
+
summary: `Adds column ${columnName} to table ${tableName}`,
|
|
223
|
+
operationClass: "additive",
|
|
224
|
+
target: targetDetails("column", columnName, schemaName, tableName),
|
|
225
|
+
precheck: [step(`ensure column "${columnName}" is missing`, absent.sql, absent.params), step(`ensure table "${tableName}" is empty before adding NOT NULL column without default`, tableEmpty.sql, tableEmpty.params)],
|
|
226
|
+
execute: [step(`add column "${columnName}"`, executeStepSql)],
|
|
227
|
+
postcheck: [step(`verify column "${columnName}" exists`, present.sql, present.params), step(`verify column "${columnName}" is NOT NULL`, notNullable.sql, notNullable.params)]
|
|
201
228
|
};
|
|
202
229
|
}
|
|
203
230
|
//#endregion
|
|
204
231
|
//#region src/core/migrations/operations/constraints.ts
|
|
232
|
+
async function constraintCheckSteps(lowerer, options) {
|
|
233
|
+
const checks = constraintExistsAst(options);
|
|
234
|
+
return {
|
|
235
|
+
absent: await lowerer.lowerToExecuteRequest(checks.constraintAbsent()),
|
|
236
|
+
present: await lowerer.lowerToExecuteRequest(checks.constraintPresent())
|
|
237
|
+
};
|
|
238
|
+
}
|
|
205
239
|
function renderForeignKeySql(schemaName, tableName, fk) {
|
|
206
240
|
let sql = `ALTER TABLE ${qualifyTableName(schemaName, tableName)}
|
|
207
241
|
ADD CONSTRAINT ${quoteIdentifier(fk.name)}
|
|
@@ -219,111 +253,91 @@ REFERENCES ${qualifyTableName(fk.references.schema, fk.references.table)} (${fk.
|
|
|
219
253
|
}
|
|
220
254
|
return sql;
|
|
221
255
|
}
|
|
222
|
-
function addPrimaryKey(schemaName, tableName, constraintName, columns) {
|
|
256
|
+
async function addPrimaryKey(schemaName, tableName, constraintName, columns, lowerer) {
|
|
223
257
|
const qualified = qualifyTableName(schemaName, tableName);
|
|
224
258
|
const columnList = columns.map(quoteIdentifier).join(", ");
|
|
259
|
+
const { absent, present } = await constraintCheckSteps(lowerer, {
|
|
260
|
+
constraintName,
|
|
261
|
+
schema: schemaName,
|
|
262
|
+
table: tableName
|
|
263
|
+
});
|
|
225
264
|
return {
|
|
226
265
|
id: `primaryKey.${tableName}.${constraintName}`,
|
|
227
266
|
label: `Add primary key on "${tableName}"`,
|
|
228
267
|
operationClass: "additive",
|
|
229
268
|
target: targetDetails("primaryKey", constraintName, schemaName, tableName),
|
|
230
|
-
precheck: [step(`ensure primary key "${constraintName}" does not exist`,
|
|
231
|
-
constraintName,
|
|
232
|
-
schema: schemaName,
|
|
233
|
-
table: tableName,
|
|
234
|
-
exists: false
|
|
235
|
-
}))],
|
|
269
|
+
precheck: [step(`ensure primary key "${constraintName}" does not exist`, absent.sql, absent.params)],
|
|
236
270
|
execute: [step(`add primary key "${constraintName}"`, `ALTER TABLE ${qualified} ADD CONSTRAINT ${quoteIdentifier(constraintName)} PRIMARY KEY (${columnList})`)],
|
|
237
|
-
postcheck: [step(`verify primary key "${constraintName}" exists`,
|
|
238
|
-
constraintName,
|
|
239
|
-
schema: schemaName,
|
|
240
|
-
table: tableName
|
|
241
|
-
}))]
|
|
271
|
+
postcheck: [step(`verify primary key "${constraintName}" exists`, present.sql, present.params)]
|
|
242
272
|
};
|
|
243
273
|
}
|
|
244
|
-
function addUnique(schemaName, tableName, constraintName, columns) {
|
|
274
|
+
async function addUnique(schemaName, tableName, constraintName, columns, lowerer) {
|
|
245
275
|
const qualified = qualifyTableName(schemaName, tableName);
|
|
246
276
|
const columnList = columns.map(quoteIdentifier).join(", ");
|
|
277
|
+
const { absent, present } = await constraintCheckSteps(lowerer, {
|
|
278
|
+
constraintName,
|
|
279
|
+
schema: schemaName,
|
|
280
|
+
table: tableName
|
|
281
|
+
});
|
|
247
282
|
return {
|
|
248
283
|
id: `unique.${tableName}.${constraintName}`,
|
|
249
284
|
label: `Add unique constraint on "${tableName}" (${columns.join(", ")})`,
|
|
250
285
|
operationClass: "additive",
|
|
251
286
|
target: targetDetails("unique", constraintName, schemaName, tableName),
|
|
252
|
-
precheck: [step(`ensure constraint "${constraintName}" does not exist`,
|
|
253
|
-
constraintName,
|
|
254
|
-
schema: schemaName,
|
|
255
|
-
table: tableName,
|
|
256
|
-
exists: false
|
|
257
|
-
}))],
|
|
287
|
+
precheck: [step(`ensure constraint "${constraintName}" does not exist`, absent.sql, absent.params)],
|
|
258
288
|
execute: [step(`add unique constraint "${constraintName}"`, `ALTER TABLE ${qualified} ADD CONSTRAINT ${quoteIdentifier(constraintName)} UNIQUE (${columnList})`)],
|
|
259
|
-
postcheck: [step(`verify constraint "${constraintName}" exists`,
|
|
260
|
-
constraintName,
|
|
261
|
-
schema: schemaName,
|
|
262
|
-
table: tableName
|
|
263
|
-
}))]
|
|
289
|
+
postcheck: [step(`verify constraint "${constraintName}" exists`, present.sql, present.params)]
|
|
264
290
|
};
|
|
265
291
|
}
|
|
266
|
-
function addForeignKey(schemaName, tableName, fk) {
|
|
292
|
+
async function addForeignKey(schemaName, tableName, fk, lowerer) {
|
|
293
|
+
const { absent, present } = await constraintCheckSteps(lowerer, {
|
|
294
|
+
constraintName: fk.name,
|
|
295
|
+
schema: schemaName,
|
|
296
|
+
table: tableName
|
|
297
|
+
});
|
|
267
298
|
return {
|
|
268
299
|
id: `foreignKey.${tableName}.${fk.name}`,
|
|
269
300
|
label: `Add foreign key "${fk.name}" on "${tableName}"`,
|
|
270
301
|
operationClass: "additive",
|
|
271
302
|
target: targetDetails("foreignKey", fk.name, schemaName, tableName),
|
|
272
|
-
precheck: [step(`ensure FK "${fk.name}" does not exist`,
|
|
273
|
-
constraintName: fk.name,
|
|
274
|
-
schema: schemaName,
|
|
275
|
-
table: tableName,
|
|
276
|
-
exists: false
|
|
277
|
-
}))],
|
|
303
|
+
precheck: [step(`ensure FK "${fk.name}" does not exist`, absent.sql, absent.params)],
|
|
278
304
|
execute: [step(`add FK "${fk.name}"`, renderForeignKeySql(schemaName, tableName, fk))],
|
|
279
|
-
postcheck: [step(`verify FK "${fk.name}" exists`,
|
|
280
|
-
constraintName: fk.name,
|
|
281
|
-
schema: schemaName,
|
|
282
|
-
table: tableName
|
|
283
|
-
}))]
|
|
305
|
+
postcheck: [step(`verify FK "${fk.name}" exists`, present.sql, present.params)]
|
|
284
306
|
};
|
|
285
307
|
}
|
|
286
|
-
function addCheckConstraint(schemaName, tableName, constraintName, column, values) {
|
|
308
|
+
async function addCheckConstraint(schemaName, tableName, constraintName, column, values, lowerer) {
|
|
287
309
|
const qualified = qualifyTableName(schemaName, tableName);
|
|
288
310
|
const valueList = values.map((v) => `'${escapeLiteral(v)}'`).join(", ");
|
|
311
|
+
const { absent, present } = await constraintCheckSteps(lowerer, {
|
|
312
|
+
constraintName,
|
|
313
|
+
schema: schemaName,
|
|
314
|
+
table: tableName
|
|
315
|
+
});
|
|
289
316
|
return {
|
|
290
317
|
id: `checkConstraint.${tableName}.${constraintName}`,
|
|
291
318
|
label: `Add check constraint "${constraintName}" on "${tableName}"."${column}"`,
|
|
292
319
|
operationClass: "additive",
|
|
293
320
|
target: targetDetails("checkConstraint", constraintName, schemaName, tableName),
|
|
294
|
-
precheck: [step(`ensure constraint "${constraintName}" does not exist`,
|
|
295
|
-
constraintName,
|
|
296
|
-
schema: schemaName,
|
|
297
|
-
table: tableName,
|
|
298
|
-
exists: false
|
|
299
|
-
}))],
|
|
321
|
+
precheck: [step(`ensure constraint "${constraintName}" does not exist`, absent.sql, absent.params)],
|
|
300
322
|
execute: [step(`add check constraint "${constraintName}"`, `ALTER TABLE ${qualified} ADD CONSTRAINT ${quoteIdentifier(constraintName)} CHECK (${quoteIdentifier(column)} IN (${valueList}))`)],
|
|
301
|
-
postcheck: [step(`verify constraint "${constraintName}" exists`,
|
|
302
|
-
constraintName,
|
|
303
|
-
schema: schemaName,
|
|
304
|
-
table: tableName
|
|
305
|
-
}))]
|
|
323
|
+
postcheck: [step(`verify constraint "${constraintName}" exists`, present.sql, present.params)]
|
|
306
324
|
};
|
|
307
325
|
}
|
|
308
|
-
function dropCheckConstraint(schemaName, tableName, constraintName) {
|
|
326
|
+
async function dropCheckConstraint(schemaName, tableName, constraintName, lowerer) {
|
|
309
327
|
const qualified = qualifyTableName(schemaName, tableName);
|
|
328
|
+
const { absent, present } = await constraintCheckSteps(lowerer, {
|
|
329
|
+
constraintName,
|
|
330
|
+
schema: schemaName,
|
|
331
|
+
table: tableName
|
|
332
|
+
});
|
|
310
333
|
return {
|
|
311
334
|
id: `dropCheckConstraint.${tableName}.${constraintName}`,
|
|
312
335
|
label: `Drop check constraint "${constraintName}" on "${tableName}"`,
|
|
313
336
|
operationClass: "destructive",
|
|
314
337
|
target: targetDetails("checkConstraint", constraintName, schemaName, tableName),
|
|
315
|
-
precheck: [step(`ensure constraint "${constraintName}" exists`,
|
|
316
|
-
constraintName,
|
|
317
|
-
schema: schemaName,
|
|
318
|
-
table: tableName
|
|
319
|
-
}))],
|
|
338
|
+
precheck: [step(`ensure constraint "${constraintName}" exists`, present.sql, present.params)],
|
|
320
339
|
execute: [step(`drop check constraint "${constraintName}"`, `ALTER TABLE ${qualified} DROP CONSTRAINT ${quoteIdentifier(constraintName)}`)],
|
|
321
|
-
postcheck: [step(`verify constraint "${constraintName}" does not exist`,
|
|
322
|
-
constraintName,
|
|
323
|
-
schema: schemaName,
|
|
324
|
-
table: tableName,
|
|
325
|
-
exists: false
|
|
326
|
-
}))]
|
|
340
|
+
postcheck: [step(`verify constraint "${constraintName}" does not exist`, absent.sql, absent.params)]
|
|
327
341
|
};
|
|
328
342
|
}
|
|
329
343
|
/**
|
|
@@ -333,25 +347,21 @@ function dropCheckConstraint(schemaName, tableName, constraintName) {
|
|
|
333
347
|
* (`'foreignKey'`, `'primaryKey'`, or `'unique'`) based on the `SchemaIssue`
|
|
334
348
|
* that produced the drop.
|
|
335
349
|
*/
|
|
336
|
-
function dropConstraint(schemaName, tableName, constraintName, kind = "unique") {
|
|
350
|
+
async function dropConstraint(schemaName, tableName, constraintName, lowerer, kind = "unique") {
|
|
337
351
|
const qualified = qualifyTableName(schemaName, tableName);
|
|
352
|
+
const { absent, present } = await constraintCheckSteps(lowerer, {
|
|
353
|
+
constraintName,
|
|
354
|
+
schema: schemaName,
|
|
355
|
+
table: tableName
|
|
356
|
+
});
|
|
338
357
|
return {
|
|
339
358
|
id: `dropConstraint.${tableName}.${constraintName}`,
|
|
340
359
|
label: `Drop constraint "${constraintName}" on "${tableName}"`,
|
|
341
360
|
operationClass: "destructive",
|
|
342
361
|
target: targetDetails(kind, constraintName, schemaName, tableName),
|
|
343
|
-
precheck: [step(`ensure constraint "${constraintName}" exists`,
|
|
344
|
-
constraintName,
|
|
345
|
-
schema: schemaName,
|
|
346
|
-
table: tableName
|
|
347
|
-
}))],
|
|
362
|
+
precheck: [step(`ensure constraint "${constraintName}" exists`, present.sql, present.params)],
|
|
348
363
|
execute: [step(`drop constraint "${constraintName}"`, `ALTER TABLE ${qualified} DROP CONSTRAINT ${quoteIdentifier(constraintName)}`)],
|
|
349
|
-
postcheck: [step(`verify constraint "${constraintName}" does not exist`,
|
|
350
|
-
constraintName,
|
|
351
|
-
schema: schemaName,
|
|
352
|
-
table: tableName,
|
|
353
|
-
exists: false
|
|
354
|
-
}))]
|
|
364
|
+
postcheck: [step(`verify constraint "${constraintName}" does not exist`, absent.sql, absent.params)]
|
|
355
365
|
};
|
|
356
366
|
}
|
|
357
367
|
//#endregion
|
|
@@ -381,11 +391,15 @@ function createExtension(extensionName) {
|
|
|
381
391
|
* use the bare {@link createExtension} for planner-emitted ops where the
|
|
382
392
|
* caller already controls idempotency through the surrounding plan.
|
|
383
393
|
*/
|
|
384
|
-
function installExtension(options) {
|
|
394
|
+
async function installExtension(options, lowerer) {
|
|
385
395
|
const { extensionName, invariantId, id } = options;
|
|
396
|
+
const label = options.label ?? `Enable extension "${extensionName}"`;
|
|
397
|
+
const checks = extensionExistsAst(extensionName);
|
|
398
|
+
const absent = await lowerer.lowerToExecuteRequest(checks.extensionAbsent());
|
|
399
|
+
const present = await lowerer.lowerToExecuteRequest(checks.extensionPresent());
|
|
386
400
|
return {
|
|
387
401
|
id,
|
|
388
|
-
label
|
|
402
|
+
label,
|
|
389
403
|
operationClass: "additive",
|
|
390
404
|
invariantId,
|
|
391
405
|
target: {
|
|
@@ -396,77 +410,20 @@ function installExtension(options) {
|
|
|
396
410
|
name: extensionName
|
|
397
411
|
}
|
|
398
412
|
},
|
|
399
|
-
precheck: [step(`verify extension "${extensionName}" is not already enabled`,
|
|
413
|
+
precheck: [step(`verify extension "${extensionName}" is not already enabled`, absent.sql, absent.params)],
|
|
400
414
|
execute: [step(`create extension "${extensionName}"`, `CREATE EXTENSION IF NOT EXISTS ${extensionName}`)],
|
|
401
|
-
postcheck: [step(`confirm extension "${extensionName}" is enabled`,
|
|
415
|
+
postcheck: [step(`confirm extension "${extensionName}" is enabled`, present.sql, present.params)]
|
|
402
416
|
};
|
|
403
417
|
}
|
|
404
418
|
//#endregion
|
|
405
|
-
//#region src/core/migrations/operations/
|
|
406
|
-
function
|
|
407
|
-
|
|
408
|
-
SELECT 1
|
|
409
|
-
FROM pg_type t
|
|
410
|
-
JOIN pg_namespace n ON t.typnamespace = n.oid
|
|
411
|
-
WHERE n.nspname = '${escapeLiteral(schemaName)}'
|
|
412
|
-
AND t.typname = '${escapeLiteral(nativeType)}'
|
|
413
|
-
)`;
|
|
414
|
-
}
|
|
415
|
-
function createEnumType(schemaName, typeName, values, nativeType = typeName) {
|
|
416
|
-
const qualifiedType = qualifyName(schemaName, nativeType);
|
|
417
|
-
const literalValues = values.map((v) => `'${escapeLiteral(v)}'`).join(", ");
|
|
418
|
-
return {
|
|
419
|
-
id: `type.${typeName}`,
|
|
420
|
-
label: `Create enum type "${typeName}"`,
|
|
421
|
-
operationClass: "additive",
|
|
422
|
-
target: targetDetails("type", typeName, schemaName),
|
|
423
|
-
precheck: [step(`ensure type "${nativeType}" does not exist`, enumTypeExistsCheck(schemaName, nativeType, false))],
|
|
424
|
-
execute: [step(`create enum type "${typeName}"`, `CREATE TYPE ${qualifiedType} AS ENUM (${literalValues})`)],
|
|
425
|
-
postcheck: [step(`verify type "${nativeType}" exists`, enumTypeExistsCheck(schemaName, nativeType))]
|
|
426
|
-
};
|
|
427
|
-
}
|
|
428
|
-
/**
|
|
429
|
-
* `typeName` is the contract-facing type name (used for id/label).
|
|
430
|
-
* `nativeType` is the Postgres type name to mutate (may differ for external types).
|
|
431
|
-
*/
|
|
432
|
-
function addEnumValues(schemaName, typeName, nativeType, values) {
|
|
433
|
-
const qualifiedType = qualifyName(schemaName, nativeType);
|
|
434
|
-
return {
|
|
435
|
-
id: `type.${typeName}.addValues`,
|
|
436
|
-
label: `Add values to enum type "${typeName}": ${values.join(", ")}`,
|
|
437
|
-
operationClass: "additive",
|
|
438
|
-
target: targetDetails("type", typeName, schemaName),
|
|
439
|
-
precheck: [step(`ensure type "${nativeType}" exists`, enumTypeExistsCheck(schemaName, nativeType))],
|
|
440
|
-
execute: values.map((value) => step(`add value '${value}' to enum "${nativeType}"`, `ALTER TYPE ${qualifiedType} ADD VALUE '${escapeLiteral(value)}'`)),
|
|
441
|
-
postcheck: [step(`verify type "${nativeType}" exists`, enumTypeExistsCheck(schemaName, nativeType))]
|
|
442
|
-
};
|
|
443
|
-
}
|
|
444
|
-
function dropEnumType(schemaName, typeName) {
|
|
445
|
-
const qualified = qualifyName(schemaName, typeName);
|
|
446
|
-
return {
|
|
447
|
-
id: `type.${typeName}.drop`,
|
|
448
|
-
label: `Drop enum type "${typeName}"`,
|
|
449
|
-
operationClass: "destructive",
|
|
450
|
-
target: targetDetails("type", typeName, schemaName),
|
|
451
|
-
precheck: [step(`ensure type "${typeName}" exists`, enumTypeExistsCheck(schemaName, typeName))],
|
|
452
|
-
execute: [step(`drop enum type "${typeName}"`, `DROP TYPE ${qualified}`)],
|
|
453
|
-
postcheck: [step(`verify type "${typeName}" removed`, enumTypeExistsCheck(schemaName, typeName, false))]
|
|
454
|
-
};
|
|
455
|
-
}
|
|
456
|
-
function renameType(schemaName, fromName, toName) {
|
|
457
|
-
const qualifiedFrom = qualifyName(schemaName, fromName);
|
|
419
|
+
//#region src/core/migrations/operations/indexes.ts
|
|
420
|
+
async function indexExistsSteps(lowerer, schemaName, indexName) {
|
|
421
|
+
const checks = indexExistsAst(schemaName, indexName);
|
|
458
422
|
return {
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
operationClass: "destructive",
|
|
462
|
-
target: targetDetails("type", fromName, schemaName),
|
|
463
|
-
precheck: [step(`ensure type "${fromName}" exists`, enumTypeExistsCheck(schemaName, fromName)), step(`ensure type "${toName}" does not already exist`, enumTypeExistsCheck(schemaName, toName, false))],
|
|
464
|
-
execute: [step(`rename type "${fromName}" to "${toName}"`, `ALTER TYPE ${qualifiedFrom} RENAME TO ${quoteIdentifier(toName)}`)],
|
|
465
|
-
postcheck: [step(`verify type "${toName}" exists`, enumTypeExistsCheck(schemaName, toName))]
|
|
423
|
+
present: await lowerer.lowerToExecuteRequest(checks.indexPresent()),
|
|
424
|
+
absent: await lowerer.lowerToExecuteRequest(checks.indexAbsent())
|
|
466
425
|
};
|
|
467
426
|
}
|
|
468
|
-
//#endregion
|
|
469
|
-
//#region src/core/migrations/operations/indexes.ts
|
|
470
427
|
function renderIndexOptionValue(key, value) {
|
|
471
428
|
if (typeof value === "string") return `'${escapeLiteral(value)}'`;
|
|
472
429
|
if (typeof value === "number" && Number.isFinite(value)) return String(value);
|
|
@@ -476,45 +433,115 @@ function renderIndexOptionValue(key, value) {
|
|
|
476
433
|
function renderIndexOptions(options) {
|
|
477
434
|
return Object.entries(options).map(([key, value]) => `${quoteIdentifier(key)} = ${renderIndexOptionValue(key, value)}`).join(", ");
|
|
478
435
|
}
|
|
479
|
-
function createIndex(schemaName, tableName, indexName, columns, extras) {
|
|
436
|
+
async function createIndex(schemaName, tableName, indexName, columns, lowerer, extras) {
|
|
480
437
|
const qualified = qualifyTableName(schemaName, tableName);
|
|
481
438
|
const columnList = columns.map(quoteIdentifier).join(", ");
|
|
482
439
|
const using = extras?.type ? ` USING ${quoteIdentifier(extras.type)}` : "";
|
|
483
440
|
const options = extras?.options;
|
|
484
441
|
const withClause = options && Object.keys(options).length > 0 ? ` WITH (${renderIndexOptions(options)})` : "";
|
|
442
|
+
const { present, absent } = await indexExistsSteps(lowerer, schemaName, indexName);
|
|
485
443
|
return {
|
|
486
444
|
id: `index.${tableName}.${indexName}`,
|
|
487
445
|
label: `Create index "${indexName}" on "${tableName}"`,
|
|
488
446
|
operationClass: "additive",
|
|
489
447
|
target: targetDetails("index", indexName, schemaName, tableName),
|
|
490
|
-
precheck: [step(`ensure index "${indexName}" does not exist`,
|
|
448
|
+
precheck: [step(`ensure index "${indexName}" does not exist`, absent.sql, absent.params)],
|
|
491
449
|
execute: [step(`create index "${indexName}"`, `CREATE INDEX ${quoteIdentifier(indexName)} ON ${qualified}${using} (${columnList})${withClause}`)],
|
|
492
|
-
postcheck: [step(`verify index "${indexName}" exists`,
|
|
450
|
+
postcheck: [step(`verify index "${indexName}" exists`, present.sql, present.params)]
|
|
493
451
|
};
|
|
494
452
|
}
|
|
495
|
-
function dropIndex(schemaName, tableName, indexName) {
|
|
453
|
+
async function dropIndex(schemaName, tableName, indexName, lowerer) {
|
|
454
|
+
const { present, absent } = await indexExistsSteps(lowerer, schemaName, indexName);
|
|
496
455
|
return {
|
|
497
456
|
id: `dropIndex.${tableName}.${indexName}`,
|
|
498
457
|
label: `Drop index "${indexName}"`,
|
|
499
458
|
operationClass: "destructive",
|
|
500
459
|
target: targetDetails("index", indexName, schemaName, tableName),
|
|
501
|
-
precheck: [step(`ensure index "${indexName}" exists`,
|
|
460
|
+
precheck: [step(`ensure index "${indexName}" exists`, present.sql, present.params)],
|
|
502
461
|
execute: [step(`drop index "${indexName}"`, `DROP INDEX ${qualifyTableName(schemaName, indexName)}`)],
|
|
503
|
-
postcheck: [step(`verify index "${indexName}" does not exist`,
|
|
462
|
+
postcheck: [step(`verify index "${indexName}" does not exist`, absent.sql, absent.params)]
|
|
504
463
|
};
|
|
505
464
|
}
|
|
506
465
|
//#endregion
|
|
507
466
|
//#region src/core/migrations/operations/tables.ts
|
|
508
|
-
function dropTable(schemaName, tableName) {
|
|
467
|
+
async function dropTable(schemaName, tableName, lowerer) {
|
|
509
468
|
const qualified = qualifyTableName(schemaName, tableName);
|
|
469
|
+
const checks = tableExistsAst(schemaName, tableName);
|
|
470
|
+
const present = await lowerer.lowerToExecuteRequest(checks.tablePresent());
|
|
471
|
+
const absent = await lowerer.lowerToExecuteRequest(checks.tableAbsent());
|
|
510
472
|
return {
|
|
511
473
|
id: `dropTable.${tableName}`,
|
|
512
474
|
label: `Drop table "${tableName}"`,
|
|
513
475
|
operationClass: "destructive",
|
|
514
476
|
target: targetDetails("table", tableName, schemaName),
|
|
515
|
-
precheck: [step(`ensure table "${tableName}" exists`,
|
|
477
|
+
precheck: [step(`ensure table "${tableName}" exists`, present.sql, present.params)],
|
|
516
478
|
execute: [step(`drop table "${tableName}"`, `DROP TABLE ${qualified}`)],
|
|
517
|
-
postcheck: [step(`verify table "${tableName}" does not exist`,
|
|
479
|
+
postcheck: [step(`verify table "${tableName}" does not exist`, absent.sql, absent.params)]
|
|
480
|
+
};
|
|
481
|
+
}
|
|
482
|
+
//#endregion
|
|
483
|
+
//#region src/core/migrations/planner-target-details.ts
|
|
484
|
+
function buildTargetDetails(objectType, name, schema, table) {
|
|
485
|
+
return {
|
|
486
|
+
schema,
|
|
487
|
+
objectType,
|
|
488
|
+
name,
|
|
489
|
+
...ifDefined("table", table)
|
|
490
|
+
};
|
|
491
|
+
}
|
|
492
|
+
//#endregion
|
|
493
|
+
//#region src/core/migrations/planner-recipes.ts
|
|
494
|
+
function buildAddColumnOperationIdentity(schema, tableName, columnName) {
|
|
495
|
+
return {
|
|
496
|
+
id: `column.${tableName}.${columnName}`,
|
|
497
|
+
label: `Add column ${columnName} to ${tableName}`,
|
|
498
|
+
summary: `Adds column ${columnName} to table ${tableName}`,
|
|
499
|
+
target: {
|
|
500
|
+
id: "postgres",
|
|
501
|
+
details: buildTargetDetails("table", tableName, schema)
|
|
502
|
+
}
|
|
503
|
+
};
|
|
504
|
+
}
|
|
505
|
+
async function buildAddNotNullColumnWithTemporaryDefaultOperation(options) {
|
|
506
|
+
const { schema, tableName, columnName, column, codecHooks, storageTypes, temporaryDefault, lowerer } = options;
|
|
507
|
+
const qualified = qualifyTableName(schema, tableName);
|
|
508
|
+
const absent = await lowerer.lowerToExecuteRequest(columnExistsAst({
|
|
509
|
+
schema,
|
|
510
|
+
table: tableName,
|
|
511
|
+
column: columnName
|
|
512
|
+
}).columnAbsent());
|
|
513
|
+
const present = await lowerer.lowerToExecuteRequest(columnExistsAst({
|
|
514
|
+
schema,
|
|
515
|
+
table: tableName,
|
|
516
|
+
column: columnName
|
|
517
|
+
}).columnPresent());
|
|
518
|
+
const notNullable = await lowerer.lowerToExecuteRequest(columnNullabilityAst({
|
|
519
|
+
schema,
|
|
520
|
+
table: tableName,
|
|
521
|
+
column: columnName,
|
|
522
|
+
nullable: false
|
|
523
|
+
}));
|
|
524
|
+
const noDefault = await lowerer.lowerToExecuteRequest(columnDefaultAst({
|
|
525
|
+
schema,
|
|
526
|
+
table: tableName,
|
|
527
|
+
column: columnName
|
|
528
|
+
}).noDefault());
|
|
529
|
+
return {
|
|
530
|
+
...buildAddColumnOperationIdentity(schema, tableName, columnName),
|
|
531
|
+
operationClass: "additive",
|
|
532
|
+
precheck: [step(`ensure column "${columnName}" is missing`, absent.sql, absent.params)],
|
|
533
|
+
execute: [{
|
|
534
|
+
description: `add column "${columnName}"`,
|
|
535
|
+
sql: buildAddColumnSql(qualified, columnName, column, codecHooks, temporaryDefault, storageTypes)
|
|
536
|
+
}, {
|
|
537
|
+
description: `drop temporary default from column "${columnName}"`,
|
|
538
|
+
sql: `ALTER TABLE ${qualified} ALTER COLUMN ${quoteIdentifier(columnName)} DROP DEFAULT`
|
|
539
|
+
}],
|
|
540
|
+
postcheck: [
|
|
541
|
+
step(`verify column "${columnName}" exists`, present.sql, present.params),
|
|
542
|
+
step(`verify column "${columnName}" is NOT NULL`, notNullable.sql, notNullable.params),
|
|
543
|
+
step(`verify column "${columnName}" has no default after temporary default removal`, noDefault.sql, noDefault.params)
|
|
544
|
+
]
|
|
518
545
|
};
|
|
519
546
|
}
|
|
520
547
|
//#endregion
|
|
@@ -541,6 +568,9 @@ function dropTable(schemaName, tableName) {
|
|
|
541
568
|
* `PostgresOpFactoryCall` union.
|
|
542
569
|
*/
|
|
543
570
|
const POSTGRES_MIGRATION_FACADE = "@prisma-next/postgres/migration";
|
|
571
|
+
function boundSchema(schemaName) {
|
|
572
|
+
return schemaName === UNBOUND_NAMESPACE_ID ? void 0 : schemaName;
|
|
573
|
+
}
|
|
544
574
|
var PostgresOpFactoryCallNode = class extends TsExpression {
|
|
545
575
|
importRequirements() {
|
|
546
576
|
return [{
|
|
@@ -573,6 +603,7 @@ function renderDdlColumnAsTsCall(col) {
|
|
|
573
603
|
if (col.notNull) opts.push("notNull: true");
|
|
574
604
|
if (col.primaryKey) opts.push("primaryKey: true");
|
|
575
605
|
if (col.default) opts.push(`default: ${renderDdlColumnDefault(col.default)}`);
|
|
606
|
+
if (col.codecRef) opts.push(`codecRef: ${jsonToTsSource(col.codecRef)}`);
|
|
576
607
|
const optsStr = opts.length > 0 ? `, { ${opts.join(", ")} }` : "";
|
|
577
608
|
return `col(${jsonToTsSource(col.name)}, ${jsonToTsSource(col.type)}${optsStr})`;
|
|
578
609
|
}
|
|
@@ -630,26 +661,33 @@ var CreateTableCall = class extends PostgresOpFactoryCallNode {
|
|
|
630
661
|
this.label = `Create table "${tableName}"`;
|
|
631
662
|
this.freeze();
|
|
632
663
|
}
|
|
633
|
-
toOp(lowerer) {
|
|
664
|
+
async toOp(lowerer) {
|
|
634
665
|
if (lowerer === void 0) throw new Error(`CreateTableCall.toOp: a DDL lowerer is required on the Postgres planner path (table "${this.tableName}"). Pass the control adapter to createPostgresMigrationPlanner.`);
|
|
635
666
|
const ddlNode = createTable({
|
|
636
|
-
...
|
|
667
|
+
...ifDefined("schema", boundSchema(this.schemaName)),
|
|
637
668
|
table: this.tableName,
|
|
638
669
|
columns: this.columns,
|
|
639
|
-
...
|
|
670
|
+
...ifDefined("constraints", this.constraints)
|
|
640
671
|
});
|
|
641
|
-
const
|
|
672
|
+
const statement = await lowerer.lowerToExecuteRequest(ddlNode);
|
|
642
673
|
const schemaName = this.schemaName;
|
|
643
674
|
const tableName = this.tableName;
|
|
675
|
+
const checks = tableExistsAst(schemaName, tableName);
|
|
676
|
+
const absent = await lowerer.lowerToExecuteRequest(checks.tableAbsent());
|
|
677
|
+
const present = await lowerer.lowerToExecuteRequest(checks.tablePresent());
|
|
644
678
|
return {
|
|
645
679
|
id: `table.${tableName}`,
|
|
646
680
|
label: `Create table "${tableName}"`,
|
|
647
681
|
summary: `Creates table "${tableName}"`,
|
|
648
682
|
operationClass: "additive",
|
|
649
683
|
target: targetDetails("table", tableName, schemaName),
|
|
650
|
-
precheck: [step(`ensure table "${tableName}" does not exist`,
|
|
651
|
-
execute: [
|
|
652
|
-
|
|
684
|
+
precheck: [step(`ensure table "${tableName}" does not exist`, absent.sql, absent.params)],
|
|
685
|
+
execute: [{
|
|
686
|
+
description: `create table "${tableName}"`,
|
|
687
|
+
sql: statement.sql,
|
|
688
|
+
params: statement.params ?? []
|
|
689
|
+
}],
|
|
690
|
+
postcheck: [step(`verify table "${tableName}" exists`, present.sql, present.params)]
|
|
653
691
|
};
|
|
654
692
|
}
|
|
655
693
|
renderTypeScript() {
|
|
@@ -694,11 +732,18 @@ var DropTableCall = class extends PostgresOpFactoryCallNode {
|
|
|
694
732
|
this.label = `Drop table "${tableName}"`;
|
|
695
733
|
this.freeze();
|
|
696
734
|
}
|
|
697
|
-
toOp() {
|
|
698
|
-
|
|
735
|
+
async toOp(lowerer) {
|
|
736
|
+
if (lowerer === void 0) throw new Error(`DropTableCall.toOp: a lowerer is required on the Postgres planner path (table "${this.tableName}"). Pass the control adapter to createPostgresMigrationPlanner.`);
|
|
737
|
+
return dropTable(this.schemaName, this.tableName, lowerer);
|
|
699
738
|
}
|
|
700
739
|
renderTypeScript() {
|
|
701
|
-
|
|
740
|
+
const opts = [];
|
|
741
|
+
if (this.schemaName !== UNBOUND_NAMESPACE_ID) opts.push(`schema: ${jsonToTsSource(this.schemaName)}`);
|
|
742
|
+
opts.push(`table: ${jsonToTsSource(this.tableName)}`);
|
|
743
|
+
return `this.dropTable({ ${opts.join(", ")} })`;
|
|
744
|
+
}
|
|
745
|
+
importRequirements() {
|
|
746
|
+
return [];
|
|
702
747
|
}
|
|
703
748
|
};
|
|
704
749
|
var AddColumnCall = class extends PostgresOpFactoryCallNode {
|
|
@@ -716,11 +761,51 @@ var AddColumnCall = class extends PostgresOpFactoryCallNode {
|
|
|
716
761
|
this.label = `Add column "${column.name}" to "${tableName}"`;
|
|
717
762
|
this.freeze();
|
|
718
763
|
}
|
|
719
|
-
toOp() {
|
|
720
|
-
|
|
764
|
+
async toOp(lowerer) {
|
|
765
|
+
if (lowerer === void 0) throw new Error(`AddColumnCall.toOp: a DDL lowerer is required on the Postgres planner path (column "${this.column.name}" on table "${this.tableName}"). Pass the control adapter to createPostgresMigrationPlanner.`);
|
|
766
|
+
const ddlNode = alterTable({
|
|
767
|
+
...ifDefined("schema", boundSchema(this.schemaName)),
|
|
768
|
+
table: this.tableName,
|
|
769
|
+
actions: [addColumnAction(this.column)]
|
|
770
|
+
});
|
|
771
|
+
const statement = await lowerer.lowerToExecuteRequest(ddlNode);
|
|
772
|
+
const schemaName = this.schemaName;
|
|
773
|
+
const tableName = this.tableName;
|
|
774
|
+
const columnName = this.column.name;
|
|
775
|
+
const colChecks = columnExistsAst({
|
|
776
|
+
schema: schemaName,
|
|
777
|
+
table: tableName,
|
|
778
|
+
column: columnName
|
|
779
|
+
});
|
|
780
|
+
const absent = await lowerer.lowerToExecuteRequest(colChecks.columnAbsent());
|
|
781
|
+
const present = await lowerer.lowerToExecuteRequest(colChecks.columnPresent());
|
|
782
|
+
return {
|
|
783
|
+
id: `column.${schemaName}.${tableName}.${columnName}`,
|
|
784
|
+
label: `Add column "${columnName}" to "${tableName}"`,
|
|
785
|
+
operationClass: "additive",
|
|
786
|
+
target: targetDetails("column", columnName, schemaName, tableName),
|
|
787
|
+
precheck: [step(`ensure column "${columnName}" is missing`, absent.sql, absent.params)],
|
|
788
|
+
execute: [step(`add column "${columnName}"`, statement.sql)],
|
|
789
|
+
postcheck: [step(`verify column "${columnName}" exists`, present.sql, present.params)]
|
|
790
|
+
};
|
|
721
791
|
}
|
|
722
792
|
renderTypeScript() {
|
|
723
|
-
|
|
793
|
+
const opts = [];
|
|
794
|
+
if (this.schemaName !== UNBOUND_NAMESPACE_ID) opts.push(`schema: ${jsonToTsSource(this.schemaName)}`);
|
|
795
|
+
opts.push(`table: ${jsonToTsSource(this.tableName)}`);
|
|
796
|
+
opts.push(`column: ${renderDdlColumnAsTsCall(this.column)}`);
|
|
797
|
+
return `this.addColumn({ ${opts.join(", ")} })`;
|
|
798
|
+
}
|
|
799
|
+
importRequirements() {
|
|
800
|
+
const req = [{
|
|
801
|
+
moduleSpecifier: POSTGRES_MIGRATION_FACADE,
|
|
802
|
+
symbol: "col"
|
|
803
|
+
}];
|
|
804
|
+
for (const sym of defaultImportSymbols([this.column])) req.push({
|
|
805
|
+
moduleSpecifier: POSTGRES_MIGRATION_FACADE,
|
|
806
|
+
symbol: sym
|
|
807
|
+
});
|
|
808
|
+
return req;
|
|
724
809
|
}
|
|
725
810
|
};
|
|
726
811
|
var DropColumnCall = class extends PostgresOpFactoryCallNode {
|
|
@@ -738,11 +823,19 @@ var DropColumnCall = class extends PostgresOpFactoryCallNode {
|
|
|
738
823
|
this.label = `Drop column "${columnName}" from "${tableName}"`;
|
|
739
824
|
this.freeze();
|
|
740
825
|
}
|
|
741
|
-
toOp() {
|
|
742
|
-
|
|
826
|
+
async toOp(lowerer) {
|
|
827
|
+
if (lowerer === void 0) throw new Error(`DropColumnCall.toOp: a lowerer is required on the Postgres planner path (column "${this.columnName}" on table "${this.tableName}"). Pass the control adapter to createPostgresMigrationPlanner.`);
|
|
828
|
+
return dropColumn(this.schemaName, this.tableName, this.columnName, lowerer);
|
|
743
829
|
}
|
|
744
830
|
renderTypeScript() {
|
|
745
|
-
|
|
831
|
+
const opts = [];
|
|
832
|
+
if (this.schemaName !== UNBOUND_NAMESPACE_ID) opts.push(`schema: ${jsonToTsSource(this.schemaName)}`);
|
|
833
|
+
opts.push(`table: ${jsonToTsSource(this.tableName)}`);
|
|
834
|
+
opts.push(`column: ${jsonToTsSource(this.columnName)}`);
|
|
835
|
+
return `this.dropColumn({ ${opts.join(", ")} })`;
|
|
836
|
+
}
|
|
837
|
+
importRequirements() {
|
|
838
|
+
return [];
|
|
746
839
|
}
|
|
747
840
|
};
|
|
748
841
|
var AlterColumnTypeCall = class extends PostgresOpFactoryCallNode {
|
|
@@ -762,11 +855,20 @@ var AlterColumnTypeCall = class extends PostgresOpFactoryCallNode {
|
|
|
762
855
|
this.label = `Alter type of "${tableName}"."${columnName}" to ${options.rawTargetTypeForLabel}`;
|
|
763
856
|
this.freeze();
|
|
764
857
|
}
|
|
765
|
-
toOp() {
|
|
766
|
-
|
|
858
|
+
async toOp(lowerer) {
|
|
859
|
+
if (lowerer === void 0) throw new Error(`AlterColumnTypeCall.toOp: a lowerer is required on the Postgres planner path (column "${this.columnName}" on table "${this.tableName}"). Pass the control adapter to createPostgresMigrationPlanner.`);
|
|
860
|
+
return alterColumnType(this.schemaName, this.tableName, this.columnName, this.options, lowerer);
|
|
767
861
|
}
|
|
768
862
|
renderTypeScript() {
|
|
769
|
-
|
|
863
|
+
const opts = [];
|
|
864
|
+
if (this.schemaName !== UNBOUND_NAMESPACE_ID) opts.push(`schema: ${jsonToTsSource(this.schemaName)}`);
|
|
865
|
+
opts.push(`table: ${jsonToTsSource(this.tableName)}`);
|
|
866
|
+
opts.push(`column: ${jsonToTsSource(this.columnName)}`);
|
|
867
|
+
opts.push(`options: ${jsonToTsSource(this.options)}`);
|
|
868
|
+
return `this.alterColumnType({ ${opts.join(", ")} })`;
|
|
869
|
+
}
|
|
870
|
+
importRequirements() {
|
|
871
|
+
return [];
|
|
770
872
|
}
|
|
771
873
|
};
|
|
772
874
|
var SetNotNullCall = class extends PostgresOpFactoryCallNode {
|
|
@@ -784,11 +886,19 @@ var SetNotNullCall = class extends PostgresOpFactoryCallNode {
|
|
|
784
886
|
this.label = `Set NOT NULL on "${tableName}"."${columnName}"`;
|
|
785
887
|
this.freeze();
|
|
786
888
|
}
|
|
787
|
-
toOp() {
|
|
788
|
-
|
|
889
|
+
async toOp(lowerer) {
|
|
890
|
+
if (lowerer === void 0) throw new Error(`SetNotNullCall.toOp: a lowerer is required on the Postgres planner path (column "${this.columnName}" on table "${this.tableName}"). Pass the control adapter to createPostgresMigrationPlanner.`);
|
|
891
|
+
return setNotNull(this.schemaName, this.tableName, this.columnName, lowerer);
|
|
789
892
|
}
|
|
790
893
|
renderTypeScript() {
|
|
791
|
-
|
|
894
|
+
const opts = [];
|
|
895
|
+
if (this.schemaName !== UNBOUND_NAMESPACE_ID) opts.push(`schema: ${jsonToTsSource(this.schemaName)}`);
|
|
896
|
+
opts.push(`table: ${jsonToTsSource(this.tableName)}`);
|
|
897
|
+
opts.push(`column: ${jsonToTsSource(this.columnName)}`);
|
|
898
|
+
return `this.setNotNull({ ${opts.join(", ")} })`;
|
|
899
|
+
}
|
|
900
|
+
importRequirements() {
|
|
901
|
+
return [];
|
|
792
902
|
}
|
|
793
903
|
};
|
|
794
904
|
var DropNotNullCall = class extends PostgresOpFactoryCallNode {
|
|
@@ -806,11 +916,19 @@ var DropNotNullCall = class extends PostgresOpFactoryCallNode {
|
|
|
806
916
|
this.label = `Drop NOT NULL on "${tableName}"."${columnName}"`;
|
|
807
917
|
this.freeze();
|
|
808
918
|
}
|
|
809
|
-
toOp() {
|
|
810
|
-
|
|
919
|
+
async toOp(lowerer) {
|
|
920
|
+
if (lowerer === void 0) throw new Error(`DropNotNullCall.toOp: a lowerer is required on the Postgres planner path (column "${this.columnName}" on table "${this.tableName}"). Pass the control adapter to createPostgresMigrationPlanner.`);
|
|
921
|
+
return dropNotNull(this.schemaName, this.tableName, this.columnName, lowerer);
|
|
811
922
|
}
|
|
812
923
|
renderTypeScript() {
|
|
813
|
-
|
|
924
|
+
const opts = [];
|
|
925
|
+
if (this.schemaName !== UNBOUND_NAMESPACE_ID) opts.push(`schema: ${jsonToTsSource(this.schemaName)}`);
|
|
926
|
+
opts.push(`table: ${jsonToTsSource(this.tableName)}`);
|
|
927
|
+
opts.push(`column: ${jsonToTsSource(this.columnName)}`);
|
|
928
|
+
return `this.dropNotNull({ ${opts.join(", ")} })`;
|
|
929
|
+
}
|
|
930
|
+
importRequirements() {
|
|
931
|
+
return [];
|
|
814
932
|
}
|
|
815
933
|
};
|
|
816
934
|
var SetDefaultCall = class extends PostgresOpFactoryCallNode {
|
|
@@ -831,18 +949,21 @@ var SetDefaultCall = class extends PostgresOpFactoryCallNode {
|
|
|
831
949
|
this.label = `Set default on "${tableName}"."${columnName}"`;
|
|
832
950
|
this.freeze();
|
|
833
951
|
}
|
|
834
|
-
toOp() {
|
|
835
|
-
|
|
952
|
+
async toOp(lowerer) {
|
|
953
|
+
if (lowerer === void 0) throw new Error(`SetDefaultCall.toOp: a lowerer is required on the Postgres planner path (column "${this.columnName}" on table "${this.tableName}"). Pass the control adapter to createPostgresMigrationPlanner.`);
|
|
954
|
+
return setDefault(this.schemaName, this.tableName, this.columnName, this.defaultSql, lowerer, this.operationClass);
|
|
836
955
|
}
|
|
837
956
|
renderTypeScript() {
|
|
838
|
-
const
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
957
|
+
const opts = [];
|
|
958
|
+
if (this.schemaName !== UNBOUND_NAMESPACE_ID) opts.push(`schema: ${jsonToTsSource(this.schemaName)}`);
|
|
959
|
+
opts.push(`table: ${jsonToTsSource(this.tableName)}`);
|
|
960
|
+
opts.push(`column: ${jsonToTsSource(this.columnName)}`);
|
|
961
|
+
opts.push(`defaultSql: ${jsonToTsSource(this.defaultSql)}`);
|
|
962
|
+
if (this.operationClass !== "additive") opts.push(`operationClass: ${jsonToTsSource(this.operationClass)}`);
|
|
963
|
+
return `this.setDefault({ ${opts.join(", ")} })`;
|
|
964
|
+
}
|
|
965
|
+
importRequirements() {
|
|
966
|
+
return [];
|
|
846
967
|
}
|
|
847
968
|
};
|
|
848
969
|
var DropDefaultCall = class extends PostgresOpFactoryCallNode {
|
|
@@ -860,13 +981,127 @@ var DropDefaultCall = class extends PostgresOpFactoryCallNode {
|
|
|
860
981
|
this.label = `Drop default on "${tableName}"."${columnName}"`;
|
|
861
982
|
this.freeze();
|
|
862
983
|
}
|
|
863
|
-
toOp() {
|
|
864
|
-
|
|
984
|
+
async toOp(lowerer) {
|
|
985
|
+
if (lowerer === void 0) throw new Error(`DropDefaultCall.toOp: a lowerer is required on the Postgres planner path (column "${this.columnName}" on table "${this.tableName}"). Pass the control adapter to createPostgresMigrationPlanner.`);
|
|
986
|
+
return dropDefault(this.schemaName, this.tableName, this.columnName, lowerer);
|
|
987
|
+
}
|
|
988
|
+
renderTypeScript() {
|
|
989
|
+
const opts = [];
|
|
990
|
+
if (this.schemaName !== UNBOUND_NAMESPACE_ID) opts.push(`schema: ${jsonToTsSource(this.schemaName)}`);
|
|
991
|
+
opts.push(`table: ${jsonToTsSource(this.tableName)}`);
|
|
992
|
+
opts.push(`column: ${jsonToTsSource(this.columnName)}`);
|
|
993
|
+
return `this.dropDefault({ ${opts.join(", ")} })`;
|
|
994
|
+
}
|
|
995
|
+
importRequirements() {
|
|
996
|
+
return [];
|
|
997
|
+
}
|
|
998
|
+
};
|
|
999
|
+
/**
|
|
1000
|
+
* Planner-internal call for adding a NOT NULL column (no contract default) to
|
|
1001
|
+
* a table that must be empty at migration time. Carries the raw ADD COLUMN SQL
|
|
1002
|
+
* (produced by `buildAddColumnSql` at plan time — deferred from slice-7 typed
|
|
1003
|
+
* DDL) plus the parameters needed to lower the typed pre/postchecks at render
|
|
1004
|
+
* time.
|
|
1005
|
+
*
|
|
1006
|
+
* No authored `PostgresMigration` method: this call is only emitted by the
|
|
1007
|
+
* planner, never hand-written by migration authors.
|
|
1008
|
+
*/
|
|
1009
|
+
var AddNotNullColumnDirectCall = class extends PostgresOpFactoryCallNode {
|
|
1010
|
+
factoryName = "rawSql";
|
|
1011
|
+
operationClass = "additive";
|
|
1012
|
+
schemaName;
|
|
1013
|
+
tableName;
|
|
1014
|
+
columnName;
|
|
1015
|
+
executeStepSql;
|
|
1016
|
+
label;
|
|
1017
|
+
constructor(schemaName, tableName, columnName, executeStepSql) {
|
|
1018
|
+
super();
|
|
1019
|
+
this.schemaName = schemaName;
|
|
1020
|
+
this.tableName = tableName;
|
|
1021
|
+
this.columnName = columnName;
|
|
1022
|
+
this.executeStepSql = executeStepSql;
|
|
1023
|
+
this.label = `Add column ${columnName} to ${tableName}`;
|
|
1024
|
+
this.freeze();
|
|
1025
|
+
}
|
|
1026
|
+
async toOp(lowerer) {
|
|
1027
|
+
if (lowerer === void 0) throw new Error(`AddNotNullColumnDirectCall.toOp: a lowerer is required on the Postgres planner path (column "${this.columnName}" on table "${this.tableName}"). Pass the control adapter to createPostgresMigrationPlanner.`);
|
|
1028
|
+
return addNotNullColumnDirect(this.schemaName, this.tableName, this.columnName, this.executeStepSql, lowerer);
|
|
1029
|
+
}
|
|
1030
|
+
renderTypeScript() {
|
|
1031
|
+
return `rawSql(${jsonToTsSource({
|
|
1032
|
+
id: `column.${this.tableName}.${this.columnName}`,
|
|
1033
|
+
label: this.label,
|
|
1034
|
+
operationClass: "additive"
|
|
1035
|
+
})})`;
|
|
1036
|
+
}
|
|
1037
|
+
importRequirements() {
|
|
1038
|
+
return [];
|
|
1039
|
+
}
|
|
1040
|
+
};
|
|
1041
|
+
/**
|
|
1042
|
+
* Planner-internal call for adding a NOT NULL column (no contract default)
|
|
1043
|
+
* using a temporary default value for non-empty tables. Carries all parameters
|
|
1044
|
+
* needed for `buildAddNotNullColumnWithTemporaryDefaultOperation`; the typed
|
|
1045
|
+
* pre/postchecks are lowered at render time via `toOp(lowerer)`. The execute
|
|
1046
|
+
* SQL (`buildAddColumnSql`) is still raw per slice-7 deferral.
|
|
1047
|
+
*
|
|
1048
|
+
* No authored `PostgresMigration` method: this call is only emitted by the
|
|
1049
|
+
* planner, never hand-written by migration authors.
|
|
1050
|
+
*/
|
|
1051
|
+
var AddNotNullColumnWithTempDefaultCall = class extends PostgresOpFactoryCallNode {
|
|
1052
|
+
factoryName = "rawSql";
|
|
1053
|
+
operationClass = "additive";
|
|
1054
|
+
schemaName;
|
|
1055
|
+
tableName;
|
|
1056
|
+
columnName;
|
|
1057
|
+
column;
|
|
1058
|
+
codecHooks;
|
|
1059
|
+
storageTypes;
|
|
1060
|
+
temporaryDefault;
|
|
1061
|
+
label;
|
|
1062
|
+
constructor(options) {
|
|
1063
|
+
super();
|
|
1064
|
+
this.schemaName = options.schemaName;
|
|
1065
|
+
this.tableName = options.tableName;
|
|
1066
|
+
this.columnName = options.columnName;
|
|
1067
|
+
this.column = options.column;
|
|
1068
|
+
this.codecHooks = options.codecHooks;
|
|
1069
|
+
this.storageTypes = options.storageTypes;
|
|
1070
|
+
this.temporaryDefault = options.temporaryDefault;
|
|
1071
|
+
this.label = `Add column ${options.columnName} to ${options.tableName}`;
|
|
1072
|
+
this.freeze();
|
|
1073
|
+
}
|
|
1074
|
+
async toOp(lowerer) {
|
|
1075
|
+
if (lowerer === void 0) throw new Error(`AddNotNullColumnWithTempDefaultCall.toOp: a lowerer is required on the Postgres planner path (column "${this.columnName}" on table "${this.tableName}"). Pass the control adapter to createPostgresMigrationPlanner.`);
|
|
1076
|
+
return buildAddNotNullColumnWithTemporaryDefaultOperation({
|
|
1077
|
+
schema: this.schemaName,
|
|
1078
|
+
tableName: this.tableName,
|
|
1079
|
+
columnName: this.columnName,
|
|
1080
|
+
column: this.column,
|
|
1081
|
+
codecHooks: this.codecHooks,
|
|
1082
|
+
storageTypes: this.storageTypes,
|
|
1083
|
+
temporaryDefault: this.temporaryDefault,
|
|
1084
|
+
lowerer
|
|
1085
|
+
});
|
|
865
1086
|
}
|
|
866
1087
|
renderTypeScript() {
|
|
867
|
-
return `
|
|
1088
|
+
return `rawSql(${jsonToTsSource({
|
|
1089
|
+
id: `column.${this.tableName}.${this.columnName}`,
|
|
1090
|
+
label: this.label,
|
|
1091
|
+
operationClass: "additive"
|
|
1092
|
+
})})`;
|
|
1093
|
+
}
|
|
1094
|
+
importRequirements() {
|
|
1095
|
+
return [];
|
|
868
1096
|
}
|
|
869
1097
|
};
|
|
1098
|
+
function constraintCallOptions(schemaName, tableName, constraintName) {
|
|
1099
|
+
const opts = [];
|
|
1100
|
+
if (schemaName !== UNBOUND_NAMESPACE_ID) opts.push(`schema: ${jsonToTsSource(schemaName)}`);
|
|
1101
|
+
opts.push(`table: ${jsonToTsSource(tableName)}`);
|
|
1102
|
+
opts.push(`constraint: ${jsonToTsSource(constraintName)}`);
|
|
1103
|
+
return opts.join(", ");
|
|
1104
|
+
}
|
|
870
1105
|
var AddPrimaryKeyCall = class extends PostgresOpFactoryCallNode {
|
|
871
1106
|
factoryName = "addPrimaryKey";
|
|
872
1107
|
operationClass = "additive";
|
|
@@ -884,11 +1119,15 @@ var AddPrimaryKeyCall = class extends PostgresOpFactoryCallNode {
|
|
|
884
1119
|
this.label = `Add primary key on "${tableName}"`;
|
|
885
1120
|
this.freeze();
|
|
886
1121
|
}
|
|
887
|
-
toOp() {
|
|
888
|
-
|
|
1122
|
+
async toOp(lowerer) {
|
|
1123
|
+
if (lowerer === void 0) throw new Error(`AddPrimaryKeyCall.toOp: a lowerer is required on the Postgres planner path (constraint "${this.constraintName}" on table "${this.tableName}"). Pass the control adapter to createPostgresMigrationPlanner.`);
|
|
1124
|
+
return addPrimaryKey(this.schemaName, this.tableName, this.constraintName, this.columns, lowerer);
|
|
889
1125
|
}
|
|
890
1126
|
renderTypeScript() {
|
|
891
|
-
return `addPrimaryKey(${
|
|
1127
|
+
return `this.addPrimaryKey({ ${constraintCallOptions(this.schemaName, this.tableName, this.constraintName)}, columns: ${jsonToTsSource(this.columns)} })`;
|
|
1128
|
+
}
|
|
1129
|
+
importRequirements() {
|
|
1130
|
+
return [];
|
|
892
1131
|
}
|
|
893
1132
|
};
|
|
894
1133
|
var AddUniqueCall = class extends PostgresOpFactoryCallNode {
|
|
@@ -908,11 +1147,15 @@ var AddUniqueCall = class extends PostgresOpFactoryCallNode {
|
|
|
908
1147
|
this.label = `Add unique constraint on "${tableName}" (${columns.join(", ")})`;
|
|
909
1148
|
this.freeze();
|
|
910
1149
|
}
|
|
911
|
-
toOp() {
|
|
912
|
-
|
|
1150
|
+
async toOp(lowerer) {
|
|
1151
|
+
if (lowerer === void 0) throw new Error(`AddUniqueCall.toOp: a lowerer is required on the Postgres planner path (constraint "${this.constraintName}" on table "${this.tableName}"). Pass the control adapter to createPostgresMigrationPlanner.`);
|
|
1152
|
+
return addUnique(this.schemaName, this.tableName, this.constraintName, this.columns, lowerer);
|
|
913
1153
|
}
|
|
914
1154
|
renderTypeScript() {
|
|
915
|
-
return `addUnique(${
|
|
1155
|
+
return `this.addUnique({ ${constraintCallOptions(this.schemaName, this.tableName, this.constraintName)}, columns: ${jsonToTsSource(this.columns)} })`;
|
|
1156
|
+
}
|
|
1157
|
+
importRequirements() {
|
|
1158
|
+
return [];
|
|
916
1159
|
}
|
|
917
1160
|
};
|
|
918
1161
|
var AddForeignKeyCall = class extends PostgresOpFactoryCallNode {
|
|
@@ -930,11 +1173,19 @@ var AddForeignKeyCall = class extends PostgresOpFactoryCallNode {
|
|
|
930
1173
|
this.label = `Add foreign key "${fk.name}" on "${tableName}"`;
|
|
931
1174
|
this.freeze();
|
|
932
1175
|
}
|
|
933
|
-
toOp() {
|
|
934
|
-
|
|
1176
|
+
async toOp(lowerer) {
|
|
1177
|
+
if (lowerer === void 0) throw new Error(`AddForeignKeyCall.toOp: a lowerer is required on the Postgres planner path (constraint "${this.fk.name}" on table "${this.tableName}"). Pass the control adapter to createPostgresMigrationPlanner.`);
|
|
1178
|
+
return addForeignKey(this.schemaName, this.tableName, this.fk, lowerer);
|
|
935
1179
|
}
|
|
936
1180
|
renderTypeScript() {
|
|
937
|
-
|
|
1181
|
+
const opts = [];
|
|
1182
|
+
if (this.schemaName !== UNBOUND_NAMESPACE_ID) opts.push(`schema: ${jsonToTsSource(this.schemaName)}`);
|
|
1183
|
+
opts.push(`table: ${jsonToTsSource(this.tableName)}`);
|
|
1184
|
+
opts.push(`foreignKey: ${jsonToTsSource(this.fk)}`);
|
|
1185
|
+
return `this.addForeignKey({ ${opts.join(", ")} })`;
|
|
1186
|
+
}
|
|
1187
|
+
importRequirements() {
|
|
1188
|
+
return [];
|
|
938
1189
|
}
|
|
939
1190
|
};
|
|
940
1191
|
var DropConstraintCall = class extends PostgresOpFactoryCallNode {
|
|
@@ -954,17 +1205,17 @@ var DropConstraintCall = class extends PostgresOpFactoryCallNode {
|
|
|
954
1205
|
this.label = `Drop constraint "${constraintName}" on "${tableName}"`;
|
|
955
1206
|
this.freeze();
|
|
956
1207
|
}
|
|
957
|
-
toOp() {
|
|
958
|
-
|
|
1208
|
+
async toOp(lowerer) {
|
|
1209
|
+
if (lowerer === void 0) throw new Error(`DropConstraintCall.toOp: a lowerer is required on the Postgres planner path (constraint "${this.constraintName}" on table "${this.tableName}"). Pass the control adapter to createPostgresMigrationPlanner.`);
|
|
1210
|
+
return dropConstraint(this.schemaName, this.tableName, this.constraintName, lowerer, this.kind);
|
|
959
1211
|
}
|
|
960
1212
|
renderTypeScript() {
|
|
961
|
-
const
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
return `dropConstraint(${args.join(", ")})`;
|
|
1213
|
+
const opts = [constraintCallOptions(this.schemaName, this.tableName, this.constraintName)];
|
|
1214
|
+
if (this.kind !== "unique") opts.push(`kind: ${jsonToTsSource(this.kind)}`);
|
|
1215
|
+
return `this.dropConstraint({ ${opts.join(", ")} })`;
|
|
1216
|
+
}
|
|
1217
|
+
importRequirements() {
|
|
1218
|
+
return [];
|
|
968
1219
|
}
|
|
969
1220
|
};
|
|
970
1221
|
var AddCheckConstraintCall = class extends PostgresOpFactoryCallNode {
|
|
@@ -986,11 +1237,15 @@ var AddCheckConstraintCall = class extends PostgresOpFactoryCallNode {
|
|
|
986
1237
|
this.label = `Add check constraint "${constraintName}" on "${tableName}"."${column}"`;
|
|
987
1238
|
this.freeze();
|
|
988
1239
|
}
|
|
989
|
-
toOp() {
|
|
990
|
-
|
|
1240
|
+
async toOp(lowerer) {
|
|
1241
|
+
if (lowerer === void 0) throw new Error(`AddCheckConstraintCall.toOp: a lowerer is required on the Postgres planner path (constraint "${this.constraintName}" on table "${this.tableName}"). Pass the control adapter to createPostgresMigrationPlanner.`);
|
|
1242
|
+
return addCheckConstraint(this.schemaName, this.tableName, this.constraintName, this.column, this.values, lowerer);
|
|
991
1243
|
}
|
|
992
1244
|
renderTypeScript() {
|
|
993
|
-
return `addCheckConstraint(${
|
|
1245
|
+
return `this.addCheckConstraint({ ${constraintCallOptions(this.schemaName, this.tableName, this.constraintName)}, column: ${jsonToTsSource(this.column)}, values: ${jsonToTsSource(this.values)} })`;
|
|
1246
|
+
}
|
|
1247
|
+
importRequirements() {
|
|
1248
|
+
return [];
|
|
994
1249
|
}
|
|
995
1250
|
};
|
|
996
1251
|
var DropCheckConstraintCall = class extends PostgresOpFactoryCallNode {
|
|
@@ -1008,11 +1263,15 @@ var DropCheckConstraintCall = class extends PostgresOpFactoryCallNode {
|
|
|
1008
1263
|
this.label = `Drop check constraint "${constraintName}" on "${tableName}"`;
|
|
1009
1264
|
this.freeze();
|
|
1010
1265
|
}
|
|
1011
|
-
toOp() {
|
|
1012
|
-
|
|
1266
|
+
async toOp(lowerer) {
|
|
1267
|
+
if (lowerer === void 0) throw new Error(`DropCheckConstraintCall.toOp: a lowerer is required on the Postgres planner path (constraint "${this.constraintName}" on table "${this.tableName}"). Pass the control adapter to createPostgresMigrationPlanner.`);
|
|
1268
|
+
return dropCheckConstraint(this.schemaName, this.tableName, this.constraintName, lowerer);
|
|
1013
1269
|
}
|
|
1014
1270
|
renderTypeScript() {
|
|
1015
|
-
return `dropCheckConstraint(${
|
|
1271
|
+
return `this.dropCheckConstraint({ ${constraintCallOptions(this.schemaName, this.tableName, this.constraintName)} })`;
|
|
1272
|
+
}
|
|
1273
|
+
importRequirements() {
|
|
1274
|
+
return [];
|
|
1016
1275
|
}
|
|
1017
1276
|
};
|
|
1018
1277
|
var CreateIndexCall = class extends PostgresOpFactoryCallNode {
|
|
@@ -1036,26 +1295,29 @@ var CreateIndexCall = class extends PostgresOpFactoryCallNode {
|
|
|
1036
1295
|
this.label = `Create index "${indexName}" on "${tableName}"`;
|
|
1037
1296
|
this.freeze();
|
|
1038
1297
|
}
|
|
1039
|
-
toOp() {
|
|
1298
|
+
async toOp(lowerer) {
|
|
1299
|
+
if (lowerer === void 0) throw new Error(`CreateIndexCall.toOp: a lowerer is required on the Postgres planner path (index "${this.indexName}" on table "${this.tableName}"). Pass the control adapter to createPostgresMigrationPlanner.`);
|
|
1040
1300
|
const extras = {};
|
|
1041
1301
|
if (this.indexType !== void 0) extras.type = this.indexType;
|
|
1042
1302
|
if (this.options !== void 0) extras.options = this.options;
|
|
1043
|
-
return createIndex(this.schemaName, this.tableName, this.indexName, this.columns, extras);
|
|
1303
|
+
return createIndex(this.schemaName, this.tableName, this.indexName, this.columns, lowerer, extras);
|
|
1044
1304
|
}
|
|
1045
1305
|
renderTypeScript() {
|
|
1046
|
-
const
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
];
|
|
1306
|
+
const opts = [];
|
|
1307
|
+
if (this.schemaName !== UNBOUND_NAMESPACE_ID) opts.push(`schema: ${jsonToTsSource(this.schemaName)}`);
|
|
1308
|
+
opts.push(`table: ${jsonToTsSource(this.tableName)}`);
|
|
1309
|
+
opts.push(`index: ${jsonToTsSource(this.indexName)}`);
|
|
1310
|
+
opts.push(`columns: ${jsonToTsSource(this.columns)}`);
|
|
1052
1311
|
if (this.indexType !== void 0 || this.options !== void 0) {
|
|
1053
1312
|
const extrasParts = [];
|
|
1054
1313
|
if (this.indexType !== void 0) extrasParts.push(`type: ${jsonToTsSource(this.indexType)}`);
|
|
1055
1314
|
if (this.options !== void 0) extrasParts.push(`options: ${jsonToTsSource(this.options)}`);
|
|
1056
|
-
|
|
1315
|
+
opts.push(`extras: { ${extrasParts.join(", ")} }`);
|
|
1057
1316
|
}
|
|
1058
|
-
return `createIndex(${
|
|
1317
|
+
return `this.createIndex({ ${opts.join(", ")} })`;
|
|
1318
|
+
}
|
|
1319
|
+
importRequirements() {
|
|
1320
|
+
return [];
|
|
1059
1321
|
}
|
|
1060
1322
|
};
|
|
1061
1323
|
var DropIndexCall = class extends PostgresOpFactoryCallNode {
|
|
@@ -1073,102 +1335,19 @@ var DropIndexCall = class extends PostgresOpFactoryCallNode {
|
|
|
1073
1335
|
this.label = `Drop index "${indexName}"`;
|
|
1074
1336
|
this.freeze();
|
|
1075
1337
|
}
|
|
1076
|
-
toOp() {
|
|
1077
|
-
|
|
1338
|
+
async toOp(lowerer) {
|
|
1339
|
+
if (lowerer === void 0) throw new Error(`DropIndexCall.toOp: a lowerer is required on the Postgres planner path (index "${this.indexName}" on table "${this.tableName}"). Pass the control adapter to createPostgresMigrationPlanner.`);
|
|
1340
|
+
return dropIndex(this.schemaName, this.tableName, this.indexName, lowerer);
|
|
1078
1341
|
}
|
|
1079
1342
|
renderTypeScript() {
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
};
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
operationClass = "additive";
|
|
1086
|
-
schemaName;
|
|
1087
|
-
typeName;
|
|
1088
|
-
nativeType;
|
|
1089
|
-
values;
|
|
1090
|
-
label;
|
|
1091
|
-
constructor(schemaName, typeName, values, nativeType = typeName) {
|
|
1092
|
-
super();
|
|
1093
|
-
this.schemaName = schemaName;
|
|
1094
|
-
this.typeName = typeName;
|
|
1095
|
-
this.nativeType = nativeType;
|
|
1096
|
-
this.values = values;
|
|
1097
|
-
this.label = `Create enum type "${typeName}"`;
|
|
1098
|
-
this.freeze();
|
|
1099
|
-
}
|
|
1100
|
-
toOp() {
|
|
1101
|
-
return createEnumType(this.schemaName, this.typeName, this.values, this.nativeType);
|
|
1102
|
-
}
|
|
1103
|
-
renderTypeScript() {
|
|
1104
|
-
const nativeArg = this.nativeType === this.typeName ? "" : `, ${jsonToTsSource(this.nativeType)}`;
|
|
1105
|
-
return `createEnumType(${jsonToTsSource(this.schemaName)}, ${jsonToTsSource(this.typeName)}, ${jsonToTsSource(this.values)}${nativeArg})`;
|
|
1106
|
-
}
|
|
1107
|
-
};
|
|
1108
|
-
var AddEnumValuesCall = class extends PostgresOpFactoryCallNode {
|
|
1109
|
-
factoryName = "addEnumValues";
|
|
1110
|
-
operationClass = "additive";
|
|
1111
|
-
schemaName;
|
|
1112
|
-
typeName;
|
|
1113
|
-
nativeType;
|
|
1114
|
-
values;
|
|
1115
|
-
label;
|
|
1116
|
-
constructor(schemaName, typeName, nativeType, values) {
|
|
1117
|
-
super();
|
|
1118
|
-
this.schemaName = schemaName;
|
|
1119
|
-
this.typeName = typeName;
|
|
1120
|
-
this.nativeType = nativeType;
|
|
1121
|
-
this.values = values;
|
|
1122
|
-
this.label = `Add values to enum type "${typeName}": ${values.join(", ")}`;
|
|
1123
|
-
this.freeze();
|
|
1124
|
-
}
|
|
1125
|
-
toOp() {
|
|
1126
|
-
return addEnumValues(this.schemaName, this.typeName, this.nativeType, this.values);
|
|
1127
|
-
}
|
|
1128
|
-
renderTypeScript() {
|
|
1129
|
-
return `addEnumValues(${jsonToTsSource(this.schemaName)}, ${jsonToTsSource(this.typeName)}, ${jsonToTsSource(this.nativeType)}, ${jsonToTsSource(this.values)})`;
|
|
1130
|
-
}
|
|
1131
|
-
};
|
|
1132
|
-
var DropEnumTypeCall = class extends PostgresOpFactoryCallNode {
|
|
1133
|
-
factoryName = "dropEnumType";
|
|
1134
|
-
operationClass = "destructive";
|
|
1135
|
-
schemaName;
|
|
1136
|
-
typeName;
|
|
1137
|
-
label;
|
|
1138
|
-
constructor(schemaName, typeName) {
|
|
1139
|
-
super();
|
|
1140
|
-
this.schemaName = schemaName;
|
|
1141
|
-
this.typeName = typeName;
|
|
1142
|
-
this.label = `Drop enum type "${typeName}"`;
|
|
1143
|
-
this.freeze();
|
|
1144
|
-
}
|
|
1145
|
-
toOp() {
|
|
1146
|
-
return dropEnumType(this.schemaName, this.typeName);
|
|
1147
|
-
}
|
|
1148
|
-
renderTypeScript() {
|
|
1149
|
-
return `dropEnumType(${jsonToTsSource(this.schemaName)}, ${jsonToTsSource(this.typeName)})`;
|
|
1150
|
-
}
|
|
1151
|
-
};
|
|
1152
|
-
var RenameTypeCall = class extends PostgresOpFactoryCallNode {
|
|
1153
|
-
factoryName = "renameType";
|
|
1154
|
-
operationClass = "destructive";
|
|
1155
|
-
schemaName;
|
|
1156
|
-
fromName;
|
|
1157
|
-
toName;
|
|
1158
|
-
label;
|
|
1159
|
-
constructor(schemaName, fromName, toName) {
|
|
1160
|
-
super();
|
|
1161
|
-
this.schemaName = schemaName;
|
|
1162
|
-
this.fromName = fromName;
|
|
1163
|
-
this.toName = toName;
|
|
1164
|
-
this.label = `Rename type "${fromName}" to "${toName}"`;
|
|
1165
|
-
this.freeze();
|
|
1166
|
-
}
|
|
1167
|
-
toOp() {
|
|
1168
|
-
return renameType(this.schemaName, this.fromName, this.toName);
|
|
1343
|
+
const opts = [];
|
|
1344
|
+
if (this.schemaName !== UNBOUND_NAMESPACE_ID) opts.push(`schema: ${jsonToTsSource(this.schemaName)}`);
|
|
1345
|
+
opts.push(`table: ${jsonToTsSource(this.tableName)}`);
|
|
1346
|
+
opts.push(`index: ${jsonToTsSource(this.indexName)}`);
|
|
1347
|
+
return `this.dropIndex({ ${opts.join(", ")} })`;
|
|
1169
1348
|
}
|
|
1170
|
-
|
|
1171
|
-
return
|
|
1349
|
+
importRequirements() {
|
|
1350
|
+
return [];
|
|
1172
1351
|
}
|
|
1173
1352
|
};
|
|
1174
1353
|
/**
|
|
@@ -1232,13 +1411,13 @@ var CreateSchemaCall = class extends PostgresOpFactoryCallNode {
|
|
|
1232
1411
|
this.label = `Create schema "${schemaName}"`;
|
|
1233
1412
|
this.freeze();
|
|
1234
1413
|
}
|
|
1235
|
-
toOp(lowerer) {
|
|
1414
|
+
async toOp(lowerer) {
|
|
1236
1415
|
if (lowerer === void 0) throw new Error(`CreateSchemaCall.toOp: a DDL lowerer is required on the Postgres planner path (schema "${this.schemaName}"). Pass the control adapter to createPostgresMigrationPlanner.`);
|
|
1237
1416
|
const ddlNode = createSchema({
|
|
1238
1417
|
schema: this.schemaName,
|
|
1239
1418
|
ifNotExists: true
|
|
1240
1419
|
});
|
|
1241
|
-
const
|
|
1420
|
+
const statement = await lowerer.lowerToExecuteRequest(ddlNode);
|
|
1242
1421
|
const schemaName = this.schemaName;
|
|
1243
1422
|
return {
|
|
1244
1423
|
id: `schema.${schemaName}`,
|
|
@@ -1246,7 +1425,11 @@ var CreateSchemaCall = class extends PostgresOpFactoryCallNode {
|
|
|
1246
1425
|
operationClass: "additive",
|
|
1247
1426
|
target: { id: "postgres" },
|
|
1248
1427
|
precheck: [],
|
|
1249
|
-
execute: [
|
|
1428
|
+
execute: [{
|
|
1429
|
+
description: `Create schema "${schemaName}"`,
|
|
1430
|
+
sql: statement.sql,
|
|
1431
|
+
params: statement.params ?? []
|
|
1432
|
+
}],
|
|
1250
1433
|
postcheck: []
|
|
1251
1434
|
};
|
|
1252
1435
|
}
|
|
@@ -1302,6 +1485,6 @@ var DataTransformCall = class extends PostgresOpFactoryCallNode {
|
|
|
1302
1485
|
}
|
|
1303
1486
|
};
|
|
1304
1487
|
//#endregion
|
|
1305
|
-
export {
|
|
1488
|
+
export { SetNotNullCall as C, installExtension as D, createExtension as E, SetDefaultCall as S, buildTargetDetails as T, DropDefaultCall as _, AddNotNullColumnWithTempDefaultCall as a, DropTableCall as b, AlterColumnTypeCall as c, CreateSchemaCall as d, CreateTableCall as f, DropConstraintCall as g, DropColumnCall as h, AddNotNullColumnDirectCall as i, CreateExtensionCall as l, DropCheckConstraintCall as m, AddColumnCall as n, AddPrimaryKeyCall as o, DataTransformCall as p, AddForeignKeyCall as r, AddUniqueCall as s, AddCheckConstraintCall as t, CreateIndexCall as u, DropIndexCall as v, postgresDefaultToDdlColumnDefault as w, RawSqlCall as x, DropNotNullCall as y };
|
|
1306
1489
|
|
|
1307
|
-
//# sourceMappingURL=op-factory-call-
|
|
1490
|
+
//# sourceMappingURL=op-factory-call-D_p5vxwt.mjs.map
|