@prisma-next/target-postgres 0.13.0-dev.35 → 0.13.0-dev.36
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/contract-free.d.mts +147 -14
- package/dist/contract-free.d.mts.map +1 -1
- package/dist/contract-free.mjs +3 -16
- package/dist/contract-free.mjs.map +1 -1
- package/dist/control.mjs +2 -2
- package/dist/ddl-QDyOSeLc.mjs +251 -0
- package/dist/ddl-QDyOSeLc.mjs.map +1 -0
- package/dist/{issue-planner-9AVUEL74.mjs → issue-planner-CoI_0uM1.mjs} +8 -118
- package/dist/issue-planner-CoI_0uM1.mjs.map +1 -0
- package/dist/issue-planner.d.mts +1 -1
- package/dist/issue-planner.d.mts.map +1 -1
- package/dist/issue-planner.mjs +1 -1
- package/dist/migration.d.mts +4 -80
- package/dist/migration.d.mts.map +1 -1
- package/dist/migration.mjs +3 -3
- package/dist/{op-factory-call-CvDOetGa.mjs → op-factory-call-B1bXWtfa.mjs} +551 -241
- package/dist/op-factory-call-B1bXWtfa.mjs.map +1 -0
- package/dist/{op-factory-call-CdtMyrlU.d.mts → op-factory-call-DmQEc3XV.d.mts} +111 -20
- package/dist/op-factory-call-DmQEc3XV.d.mts.map +1 -0
- package/dist/op-factory-call.d.mts +1 -1
- package/dist/op-factory-call.mjs +1 -1
- package/dist/{planner-BZxjjT8T.mjs → planner-DS5XBhmi.mjs} +4 -4
- package/dist/{planner-BZxjjT8T.mjs.map → planner-DS5XBhmi.mjs.map} +1 -1
- package/dist/{planner-produced-postgres-migration-CkECqqTy.mjs → planner-produced-postgres-migration-DTwCCek_.mjs} +2 -2
- package/dist/{planner-produced-postgres-migration-CkECqqTy.mjs.map → planner-produced-postgres-migration-DTwCCek_.mjs.map} +1 -1
- package/dist/{planner-produced-postgres-migration-wLhnJMMA.d.mts → planner-produced-postgres-migration-QqHa2C2l.d.mts} +2 -2
- package/dist/{planner-produced-postgres-migration-wLhnJMMA.d.mts.map → planner-produced-postgres-migration-QqHa2C2l.d.mts.map} +1 -1
- 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 +1 -47
- package/dist/planner-sql-checks.d.mts.map +1 -1
- package/dist/planner-sql-checks.mjs +2 -2
- package/dist/planner.d.mts +1 -1
- package/dist/planner.mjs +1 -1
- package/dist/{postgres-contract-serializer-sdg1B6Og.mjs → postgres-contract-serializer-E92REOFk.mjs} +2 -2
- package/dist/{postgres-contract-serializer-sdg1B6Og.mjs.map → postgres-contract-serializer-E92REOFk.mjs.map} +1 -1
- package/dist/postgres-migration-Y4YBJqkS.d.mts +181 -0
- package/dist/postgres-migration-Y4YBJqkS.d.mts.map +1 -0
- package/dist/postgres-migration-otiaw3Ru.mjs +145 -0
- package/dist/postgres-migration-otiaw3Ru.mjs.map +1 -0
- package/dist/{postgres-schema-CDaLWZwd.mjs → postgres-schema-COGZ1ark.mjs} +61 -8
- package/dist/postgres-schema-COGZ1ark.mjs.map +1 -0
- package/dist/runtime.mjs +1 -1
- package/dist/table-source-BvFo7gVs.d.mts +15 -0
- package/dist/table-source-BvFo7gVs.d.mts.map +1 -0
- package/dist/types.d.mts +26 -6
- package/dist/types.d.mts.map +1 -1
- package/dist/types.mjs +1 -1
- package/package.json +17 -17
- package/src/contract-free/checks.ts +363 -0
- package/src/core/migrations/op-factory-call.ts +417 -94
- package/src/core/migrations/operations/columns.ts +175 -140
- package/src/core/migrations/operations/constraints.ts +79 -108
- 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-recipes.ts +42 -33
- package/src/core/migrations/planner-sql-checks.ts +1 -172
- package/src/core/migrations/planner-strategies.ts +25 -73
- package/src/core/migrations/postgres-migration.ts +272 -7
- package/src/core/postgres-schema.ts +47 -6
- package/src/exports/contract-free.ts +21 -0
- package/src/exports/migration.ts +1 -22
- package/src/exports/planner-sql-checks.ts +0 -7
- package/dist/ddl-DY2R_Yqz.mjs +0 -45
- package/dist/ddl-DY2R_Yqz.mjs.map +0 -1
- package/dist/issue-planner-9AVUEL74.mjs.map +0 -1
- package/dist/op-factory-call-CdtMyrlU.d.mts.map +0 -1
- package/dist/op-factory-call-CvDOetGa.mjs.map +0 -1
- package/dist/planner-sql-checks-Bj4G0_gO.mjs +0 -272
- package/dist/planner-sql-checks-Bj4G0_gO.mjs.map +0 -1
- package/dist/postgres-migration-DLXL0GBf.d.mts +0 -77
- package/dist/postgres-migration-DLXL0GBf.d.mts.map +0 -1
- package/dist/postgres-migration-DMnWjdni.mjs +0 -75
- package/dist/postgres-migration-DMnWjdni.mjs.map +0 -1
- package/dist/postgres-schema-CDaLWZwd.mjs.map +0 -1
- package/dist/shared-jcsbXxiW.d.mts +0 -25
- package/dist/shared-jcsbXxiW.d.mts.map +0 -1
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { i as quoteIdentifier, n as escapeLiteral } from "./sql-utils-DcfMz4MQ.mjs";
|
|
2
|
-
import { i as createTable, n as alterTable, r as createSchema, t as addColumnAction } from "./ddl-
|
|
3
|
-
import {
|
|
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";
|
|
5
6
|
import { blindCast } from "@prisma-next/utils/casts";
|
|
6
7
|
import { ifDefined } from "@prisma-next/utils/defined";
|
|
@@ -9,10 +10,11 @@ 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,25 +30,28 @@ function targetDetails(objectType, name, schema, table) {
|
|
|
28
30
|
}
|
|
29
31
|
//#endregion
|
|
30
32
|
//#region src/core/migrations/operations/columns.ts
|
|
31
|
-
function
|
|
33
|
+
async function columnExistsSteps(lowerer, options) {
|
|
34
|
+
const checks = columnExistsAst(options);
|
|
35
|
+
return {
|
|
36
|
+
present: await lowerer.lowerToExecuteRequest(checks.columnPresent()),
|
|
37
|
+
absent: await lowerer.lowerToExecuteRequest(checks.columnAbsent())
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
async function dropColumn(schemaName, tableName, columnName, lowerer) {
|
|
32
41
|
const qualified = qualifyTableName(schemaName, tableName);
|
|
42
|
+
const { present, absent } = await columnExistsSteps(lowerer, {
|
|
43
|
+
schema: schemaName,
|
|
44
|
+
table: tableName,
|
|
45
|
+
column: columnName
|
|
46
|
+
});
|
|
33
47
|
return {
|
|
34
48
|
id: `dropColumn.${tableName}.${columnName}`,
|
|
35
49
|
label: `Drop column "${columnName}" from "${tableName}"`,
|
|
36
50
|
operationClass: "destructive",
|
|
37
51
|
target: targetDetails("column", columnName, schemaName, tableName),
|
|
38
|
-
precheck: [step(`ensure column "${columnName}" exists`,
|
|
39
|
-
schema: schemaName,
|
|
40
|
-
table: tableName,
|
|
41
|
-
column: columnName
|
|
42
|
-
}))],
|
|
52
|
+
precheck: [step(`ensure column "${columnName}" exists`, present.sql, present.params)],
|
|
43
53
|
execute: [step(`drop column "${columnName}"`, `ALTER TABLE ${qualified} DROP COLUMN ${quoteIdentifier(columnName)}`)],
|
|
44
|
-
postcheck: [step(`verify column "${columnName}" does not exist`,
|
|
45
|
-
schema: schemaName,
|
|
46
|
-
table: tableName,
|
|
47
|
-
column: columnName,
|
|
48
|
-
exists: false
|
|
49
|
-
}))]
|
|
54
|
+
postcheck: [step(`verify column "${columnName}" does not exist`, absent.sql, absent.params)]
|
|
50
55
|
};
|
|
51
56
|
}
|
|
52
57
|
/**
|
|
@@ -57,69 +62,80 @@ function dropColumn(schemaName, tableName, columnName) {
|
|
|
57
62
|
* string appearing in the human-readable label (typically `toType` when
|
|
58
63
|
* explicit, else the column's native type).
|
|
59
64
|
*/
|
|
60
|
-
function alterColumnType(schemaName, tableName, columnName, options) {
|
|
65
|
+
async function alterColumnType(schemaName, tableName, columnName, options, lowerer) {
|
|
61
66
|
const qualified = qualifyTableName(schemaName, tableName);
|
|
62
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
|
+
}));
|
|
63
79
|
return {
|
|
64
80
|
id: `alterType.${tableName}.${columnName}`,
|
|
65
81
|
label: `Alter type of "${tableName}"."${columnName}" to ${options.rawTargetTypeForLabel}`,
|
|
66
82
|
operationClass: "destructive",
|
|
67
83
|
target: targetDetails("column", columnName, schemaName, tableName),
|
|
68
|
-
precheck: [step(`ensure column "${columnName}" exists`,
|
|
69
|
-
schema: schemaName,
|
|
70
|
-
table: tableName,
|
|
71
|
-
column: columnName
|
|
72
|
-
}))],
|
|
84
|
+
precheck: [step(`ensure column "${columnName}" exists`, present.sql, present.params)],
|
|
73
85
|
execute: [step(`alter type of "${columnName}"`, `ALTER TABLE ${qualified} ALTER COLUMN ${quoteIdentifier(columnName)} TYPE ${options.qualifiedTargetType}${usingClause}`)],
|
|
74
|
-
postcheck: [step(`verify column "${columnName}" has type "${options.formatTypeExpected}"`,
|
|
75
|
-
schema: schemaName,
|
|
76
|
-
table: tableName,
|
|
77
|
-
column: columnName,
|
|
78
|
-
expectedType: options.formatTypeExpected
|
|
79
|
-
}))],
|
|
86
|
+
postcheck: [step(`verify column "${columnName}" has type "${options.formatTypeExpected}"`, typeCheck.sql, typeCheck.params)],
|
|
80
87
|
meta: { warning: "TABLE_REWRITE" }
|
|
81
88
|
};
|
|
82
89
|
}
|
|
83
|
-
function setNotNull(schemaName, tableName, columnName) {
|
|
90
|
+
async function setNotNull(schemaName, tableName, columnName, lowerer) {
|
|
84
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
|
+
}));
|
|
85
108
|
return {
|
|
86
109
|
id: `alterNullability.setNotNull.${tableName}.${columnName}`,
|
|
87
110
|
label: `Set NOT NULL on "${tableName}"."${columnName}"`,
|
|
88
111
|
operationClass: "destructive",
|
|
89
112
|
target: targetDetails("column", columnName, schemaName, tableName),
|
|
90
|
-
precheck: [step(`ensure column "${columnName}" exists`,
|
|
91
|
-
schema: schemaName,
|
|
92
|
-
table: tableName,
|
|
93
|
-
column: columnName
|
|
94
|
-
})), 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)],
|
|
95
114
|
execute: [step(`set NOT NULL on "${columnName}"`, `ALTER TABLE ${qualified} ALTER COLUMN ${quoteIdentifier(columnName)} SET NOT NULL`)],
|
|
96
|
-
postcheck: [step(`verify column "${columnName}" is NOT NULL`,
|
|
97
|
-
schema: schemaName,
|
|
98
|
-
table: tableName,
|
|
99
|
-
column: columnName,
|
|
100
|
-
nullable: false
|
|
101
|
-
}))]
|
|
115
|
+
postcheck: [step(`verify column "${columnName}" is NOT NULL`, notNullable.sql, notNullable.params)]
|
|
102
116
|
};
|
|
103
117
|
}
|
|
104
|
-
function dropNotNull(schemaName, tableName, columnName) {
|
|
118
|
+
async function dropNotNull(schemaName, tableName, columnName, lowerer) {
|
|
105
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
|
+
}));
|
|
106
131
|
return {
|
|
107
132
|
id: `alterNullability.dropNotNull.${tableName}.${columnName}`,
|
|
108
133
|
label: `Drop NOT NULL on "${tableName}"."${columnName}"`,
|
|
109
134
|
operationClass: "widening",
|
|
110
135
|
target: targetDetails("column", columnName, schemaName, tableName),
|
|
111
|
-
precheck: [step(`ensure column "${columnName}" exists`,
|
|
112
|
-
schema: schemaName,
|
|
113
|
-
table: tableName,
|
|
114
|
-
column: columnName
|
|
115
|
-
}))],
|
|
136
|
+
precheck: [step(`ensure column "${columnName}" exists`, present.sql, present.params)],
|
|
116
137
|
execute: [step(`drop NOT NULL on "${columnName}"`, `ALTER TABLE ${qualified} ALTER COLUMN ${quoteIdentifier(columnName)} DROP NOT NULL`)],
|
|
117
|
-
postcheck: [step(`verify column "${columnName}" is nullable`,
|
|
118
|
-
schema: schemaName,
|
|
119
|
-
table: tableName,
|
|
120
|
-
column: columnName,
|
|
121
|
-
nullable: true
|
|
122
|
-
}))]
|
|
138
|
+
postcheck: [step(`verify column "${columnName}" is nullable`, nullable.sql, nullable.params)]
|
|
123
139
|
};
|
|
124
140
|
}
|
|
125
141
|
/**
|
|
@@ -132,50 +148,94 @@ function dropNotNull(schemaName, tableName, columnName) {
|
|
|
132
148
|
* when the column already has a different default — policy enforcement
|
|
133
149
|
* treats that as a widening change rather than an additive one.
|
|
134
150
|
*/
|
|
135
|
-
function setDefault(schemaName, tableName, columnName, defaultSql, operationClass = "additive") {
|
|
151
|
+
async function setDefault(schemaName, tableName, columnName, defaultSql, lowerer, operationClass = "additive") {
|
|
136
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());
|
|
137
163
|
return {
|
|
138
164
|
id: `setDefault.${tableName}.${columnName}`,
|
|
139
165
|
label: `Set default on "${tableName}"."${columnName}"`,
|
|
140
166
|
operationClass,
|
|
141
167
|
target: targetDetails("column", columnName, schemaName, tableName),
|
|
142
|
-
precheck: [step(`ensure column "${columnName}" exists`,
|
|
143
|
-
schema: schemaName,
|
|
144
|
-
table: tableName,
|
|
145
|
-
column: columnName
|
|
146
|
-
}))],
|
|
168
|
+
precheck: [step(`ensure column "${columnName}" exists`, present.sql, present.params)],
|
|
147
169
|
execute: [step(`set default on "${columnName}"`, `ALTER TABLE ${qualified} ALTER COLUMN ${quoteIdentifier(columnName)} SET ${defaultSql}`)],
|
|
148
|
-
postcheck: [step(`verify column "${columnName}" has a default`,
|
|
149
|
-
schema: schemaName,
|
|
150
|
-
table: tableName,
|
|
151
|
-
column: columnName,
|
|
152
|
-
exists: true
|
|
153
|
-
}))]
|
|
170
|
+
postcheck: [step(`verify column "${columnName}" has a default`, hasDefault.sql, hasDefault.params)]
|
|
154
171
|
};
|
|
155
172
|
}
|
|
156
|
-
function dropDefault(schemaName, tableName, columnName) {
|
|
173
|
+
async function dropDefault(schemaName, tableName, columnName, lowerer) {
|
|
157
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());
|
|
158
185
|
return {
|
|
159
186
|
id: `dropDefault.${tableName}.${columnName}`,
|
|
160
187
|
label: `Drop default on "${tableName}"."${columnName}"`,
|
|
161
188
|
operationClass: "destructive",
|
|
162
189
|
target: targetDetails("column", columnName, schemaName, tableName),
|
|
163
|
-
precheck: [step(`ensure column "${columnName}" exists`,
|
|
164
|
-
schema: schemaName,
|
|
165
|
-
table: tableName,
|
|
166
|
-
column: columnName
|
|
167
|
-
}))],
|
|
190
|
+
precheck: [step(`ensure column "${columnName}" exists`, present.sql, present.params)],
|
|
168
191
|
execute: [step(`drop default on "${columnName}"`, `ALTER TABLE ${qualified} ALTER COLUMN ${quoteIdentifier(columnName)} DROP DEFAULT`)],
|
|
169
|
-
postcheck: [step(`verify column "${columnName}" has no default`,
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
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)]
|
|
175
228
|
};
|
|
176
229
|
}
|
|
177
230
|
//#endregion
|
|
178
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
|
+
}
|
|
179
239
|
function renderForeignKeySql(schemaName, tableName, fk) {
|
|
180
240
|
let sql = `ALTER TABLE ${qualifyTableName(schemaName, tableName)}
|
|
181
241
|
ADD CONSTRAINT ${quoteIdentifier(fk.name)}
|
|
@@ -193,111 +253,91 @@ REFERENCES ${qualifyTableName(fk.references.schema, fk.references.table)} (${fk.
|
|
|
193
253
|
}
|
|
194
254
|
return sql;
|
|
195
255
|
}
|
|
196
|
-
function addPrimaryKey(schemaName, tableName, constraintName, columns) {
|
|
256
|
+
async function addPrimaryKey(schemaName, tableName, constraintName, columns, lowerer) {
|
|
197
257
|
const qualified = qualifyTableName(schemaName, tableName);
|
|
198
258
|
const columnList = columns.map(quoteIdentifier).join(", ");
|
|
259
|
+
const { absent, present } = await constraintCheckSteps(lowerer, {
|
|
260
|
+
constraintName,
|
|
261
|
+
schema: schemaName,
|
|
262
|
+
table: tableName
|
|
263
|
+
});
|
|
199
264
|
return {
|
|
200
265
|
id: `primaryKey.${tableName}.${constraintName}`,
|
|
201
266
|
label: `Add primary key on "${tableName}"`,
|
|
202
267
|
operationClass: "additive",
|
|
203
268
|
target: targetDetails("primaryKey", constraintName, schemaName, tableName),
|
|
204
|
-
precheck: [step(`ensure primary key "${constraintName}" does not exist`,
|
|
205
|
-
constraintName,
|
|
206
|
-
schema: schemaName,
|
|
207
|
-
table: tableName,
|
|
208
|
-
exists: false
|
|
209
|
-
}))],
|
|
269
|
+
precheck: [step(`ensure primary key "${constraintName}" does not exist`, absent.sql, absent.params)],
|
|
210
270
|
execute: [step(`add primary key "${constraintName}"`, `ALTER TABLE ${qualified} ADD CONSTRAINT ${quoteIdentifier(constraintName)} PRIMARY KEY (${columnList})`)],
|
|
211
|
-
postcheck: [step(`verify primary key "${constraintName}" exists`,
|
|
212
|
-
constraintName,
|
|
213
|
-
schema: schemaName,
|
|
214
|
-
table: tableName
|
|
215
|
-
}))]
|
|
271
|
+
postcheck: [step(`verify primary key "${constraintName}" exists`, present.sql, present.params)]
|
|
216
272
|
};
|
|
217
273
|
}
|
|
218
|
-
function addUnique(schemaName, tableName, constraintName, columns) {
|
|
274
|
+
async function addUnique(schemaName, tableName, constraintName, columns, lowerer) {
|
|
219
275
|
const qualified = qualifyTableName(schemaName, tableName);
|
|
220
276
|
const columnList = columns.map(quoteIdentifier).join(", ");
|
|
277
|
+
const { absent, present } = await constraintCheckSteps(lowerer, {
|
|
278
|
+
constraintName,
|
|
279
|
+
schema: schemaName,
|
|
280
|
+
table: tableName
|
|
281
|
+
});
|
|
221
282
|
return {
|
|
222
283
|
id: `unique.${tableName}.${constraintName}`,
|
|
223
284
|
label: `Add unique constraint on "${tableName}" (${columns.join(", ")})`,
|
|
224
285
|
operationClass: "additive",
|
|
225
286
|
target: targetDetails("unique", constraintName, schemaName, tableName),
|
|
226
|
-
precheck: [step(`ensure constraint "${constraintName}" does not exist`,
|
|
227
|
-
constraintName,
|
|
228
|
-
schema: schemaName,
|
|
229
|
-
table: tableName,
|
|
230
|
-
exists: false
|
|
231
|
-
}))],
|
|
287
|
+
precheck: [step(`ensure constraint "${constraintName}" does not exist`, absent.sql, absent.params)],
|
|
232
288
|
execute: [step(`add unique constraint "${constraintName}"`, `ALTER TABLE ${qualified} ADD CONSTRAINT ${quoteIdentifier(constraintName)} UNIQUE (${columnList})`)],
|
|
233
|
-
postcheck: [step(`verify constraint "${constraintName}" exists`,
|
|
234
|
-
constraintName,
|
|
235
|
-
schema: schemaName,
|
|
236
|
-
table: tableName
|
|
237
|
-
}))]
|
|
289
|
+
postcheck: [step(`verify constraint "${constraintName}" exists`, present.sql, present.params)]
|
|
238
290
|
};
|
|
239
291
|
}
|
|
240
|
-
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
|
+
});
|
|
241
298
|
return {
|
|
242
299
|
id: `foreignKey.${tableName}.${fk.name}`,
|
|
243
300
|
label: `Add foreign key "${fk.name}" on "${tableName}"`,
|
|
244
301
|
operationClass: "additive",
|
|
245
302
|
target: targetDetails("foreignKey", fk.name, schemaName, tableName),
|
|
246
|
-
precheck: [step(`ensure FK "${fk.name}" does not exist`,
|
|
247
|
-
constraintName: fk.name,
|
|
248
|
-
schema: schemaName,
|
|
249
|
-
table: tableName,
|
|
250
|
-
exists: false
|
|
251
|
-
}))],
|
|
303
|
+
precheck: [step(`ensure FK "${fk.name}" does not exist`, absent.sql, absent.params)],
|
|
252
304
|
execute: [step(`add FK "${fk.name}"`, renderForeignKeySql(schemaName, tableName, fk))],
|
|
253
|
-
postcheck: [step(`verify FK "${fk.name}" exists`,
|
|
254
|
-
constraintName: fk.name,
|
|
255
|
-
schema: schemaName,
|
|
256
|
-
table: tableName
|
|
257
|
-
}))]
|
|
305
|
+
postcheck: [step(`verify FK "${fk.name}" exists`, present.sql, present.params)]
|
|
258
306
|
};
|
|
259
307
|
}
|
|
260
|
-
function addCheckConstraint(schemaName, tableName, constraintName, column, values) {
|
|
308
|
+
async function addCheckConstraint(schemaName, tableName, constraintName, column, values, lowerer) {
|
|
261
309
|
const qualified = qualifyTableName(schemaName, tableName);
|
|
262
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
|
+
});
|
|
263
316
|
return {
|
|
264
317
|
id: `checkConstraint.${tableName}.${constraintName}`,
|
|
265
318
|
label: `Add check constraint "${constraintName}" on "${tableName}"."${column}"`,
|
|
266
319
|
operationClass: "additive",
|
|
267
320
|
target: targetDetails("checkConstraint", constraintName, schemaName, tableName),
|
|
268
|
-
precheck: [step(`ensure constraint "${constraintName}" does not exist`,
|
|
269
|
-
constraintName,
|
|
270
|
-
schema: schemaName,
|
|
271
|
-
table: tableName,
|
|
272
|
-
exists: false
|
|
273
|
-
}))],
|
|
321
|
+
precheck: [step(`ensure constraint "${constraintName}" does not exist`, absent.sql, absent.params)],
|
|
274
322
|
execute: [step(`add check constraint "${constraintName}"`, `ALTER TABLE ${qualified} ADD CONSTRAINT ${quoteIdentifier(constraintName)} CHECK (${quoteIdentifier(column)} IN (${valueList}))`)],
|
|
275
|
-
postcheck: [step(`verify constraint "${constraintName}" exists`,
|
|
276
|
-
constraintName,
|
|
277
|
-
schema: schemaName,
|
|
278
|
-
table: tableName
|
|
279
|
-
}))]
|
|
323
|
+
postcheck: [step(`verify constraint "${constraintName}" exists`, present.sql, present.params)]
|
|
280
324
|
};
|
|
281
325
|
}
|
|
282
|
-
function dropCheckConstraint(schemaName, tableName, constraintName) {
|
|
326
|
+
async function dropCheckConstraint(schemaName, tableName, constraintName, lowerer) {
|
|
283
327
|
const qualified = qualifyTableName(schemaName, tableName);
|
|
328
|
+
const { absent, present } = await constraintCheckSteps(lowerer, {
|
|
329
|
+
constraintName,
|
|
330
|
+
schema: schemaName,
|
|
331
|
+
table: tableName
|
|
332
|
+
});
|
|
284
333
|
return {
|
|
285
334
|
id: `dropCheckConstraint.${tableName}.${constraintName}`,
|
|
286
335
|
label: `Drop check constraint "${constraintName}" on "${tableName}"`,
|
|
287
336
|
operationClass: "destructive",
|
|
288
337
|
target: targetDetails("checkConstraint", constraintName, schemaName, tableName),
|
|
289
|
-
precheck: [step(`ensure constraint "${constraintName}" exists`,
|
|
290
|
-
constraintName,
|
|
291
|
-
schema: schemaName,
|
|
292
|
-
table: tableName
|
|
293
|
-
}))],
|
|
338
|
+
precheck: [step(`ensure constraint "${constraintName}" exists`, present.sql, present.params)],
|
|
294
339
|
execute: [step(`drop check constraint "${constraintName}"`, `ALTER TABLE ${qualified} DROP CONSTRAINT ${quoteIdentifier(constraintName)}`)],
|
|
295
|
-
postcheck: [step(`verify constraint "${constraintName}" does not exist`,
|
|
296
|
-
constraintName,
|
|
297
|
-
schema: schemaName,
|
|
298
|
-
table: tableName,
|
|
299
|
-
exists: false
|
|
300
|
-
}))]
|
|
340
|
+
postcheck: [step(`verify constraint "${constraintName}" does not exist`, absent.sql, absent.params)]
|
|
301
341
|
};
|
|
302
342
|
}
|
|
303
343
|
/**
|
|
@@ -307,25 +347,21 @@ function dropCheckConstraint(schemaName, tableName, constraintName) {
|
|
|
307
347
|
* (`'foreignKey'`, `'primaryKey'`, or `'unique'`) based on the `SchemaIssue`
|
|
308
348
|
* that produced the drop.
|
|
309
349
|
*/
|
|
310
|
-
function dropConstraint(schemaName, tableName, constraintName, kind = "unique") {
|
|
350
|
+
async function dropConstraint(schemaName, tableName, constraintName, lowerer, kind = "unique") {
|
|
311
351
|
const qualified = qualifyTableName(schemaName, tableName);
|
|
352
|
+
const { absent, present } = await constraintCheckSteps(lowerer, {
|
|
353
|
+
constraintName,
|
|
354
|
+
schema: schemaName,
|
|
355
|
+
table: tableName
|
|
356
|
+
});
|
|
312
357
|
return {
|
|
313
358
|
id: `dropConstraint.${tableName}.${constraintName}`,
|
|
314
359
|
label: `Drop constraint "${constraintName}" on "${tableName}"`,
|
|
315
360
|
operationClass: "destructive",
|
|
316
361
|
target: targetDetails(kind, constraintName, schemaName, tableName),
|
|
317
|
-
precheck: [step(`ensure constraint "${constraintName}" exists`,
|
|
318
|
-
constraintName,
|
|
319
|
-
schema: schemaName,
|
|
320
|
-
table: tableName
|
|
321
|
-
}))],
|
|
362
|
+
precheck: [step(`ensure constraint "${constraintName}" exists`, present.sql, present.params)],
|
|
322
363
|
execute: [step(`drop constraint "${constraintName}"`, `ALTER TABLE ${qualified} DROP CONSTRAINT ${quoteIdentifier(constraintName)}`)],
|
|
323
|
-
postcheck: [step(`verify constraint "${constraintName}" does not exist`,
|
|
324
|
-
constraintName,
|
|
325
|
-
schema: schemaName,
|
|
326
|
-
table: tableName,
|
|
327
|
-
exists: false
|
|
328
|
-
}))]
|
|
364
|
+
postcheck: [step(`verify constraint "${constraintName}" does not exist`, absent.sql, absent.params)]
|
|
329
365
|
};
|
|
330
366
|
}
|
|
331
367
|
//#endregion
|
|
@@ -355,11 +391,15 @@ function createExtension(extensionName) {
|
|
|
355
391
|
* use the bare {@link createExtension} for planner-emitted ops where the
|
|
356
392
|
* caller already controls idempotency through the surrounding plan.
|
|
357
393
|
*/
|
|
358
|
-
function installExtension(options) {
|
|
394
|
+
async function installExtension(options, lowerer) {
|
|
359
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());
|
|
360
400
|
return {
|
|
361
401
|
id,
|
|
362
|
-
label
|
|
402
|
+
label,
|
|
363
403
|
operationClass: "additive",
|
|
364
404
|
invariantId,
|
|
365
405
|
target: {
|
|
@@ -370,13 +410,20 @@ function installExtension(options) {
|
|
|
370
410
|
name: extensionName
|
|
371
411
|
}
|
|
372
412
|
},
|
|
373
|
-
precheck: [step(`verify extension "${extensionName}" is not already enabled`,
|
|
413
|
+
precheck: [step(`verify extension "${extensionName}" is not already enabled`, absent.sql, absent.params)],
|
|
374
414
|
execute: [step(`create extension "${extensionName}"`, `CREATE EXTENSION IF NOT EXISTS ${extensionName}`)],
|
|
375
|
-
postcheck: [step(`confirm extension "${extensionName}" is enabled`,
|
|
415
|
+
postcheck: [step(`confirm extension "${extensionName}" is enabled`, present.sql, present.params)]
|
|
376
416
|
};
|
|
377
417
|
}
|
|
378
418
|
//#endregion
|
|
379
419
|
//#region src/core/migrations/operations/indexes.ts
|
|
420
|
+
async function indexExistsSteps(lowerer, schemaName, indexName) {
|
|
421
|
+
const checks = indexExistsAst(schemaName, indexName);
|
|
422
|
+
return {
|
|
423
|
+
present: await lowerer.lowerToExecuteRequest(checks.indexPresent()),
|
|
424
|
+
absent: await lowerer.lowerToExecuteRequest(checks.indexAbsent())
|
|
425
|
+
};
|
|
426
|
+
}
|
|
380
427
|
function renderIndexOptionValue(key, value) {
|
|
381
428
|
if (typeof value === "string") return `'${escapeLiteral(value)}'`;
|
|
382
429
|
if (typeof value === "number" && Number.isFinite(value)) return String(value);
|
|
@@ -386,45 +433,115 @@ function renderIndexOptionValue(key, value) {
|
|
|
386
433
|
function renderIndexOptions(options) {
|
|
387
434
|
return Object.entries(options).map(([key, value]) => `${quoteIdentifier(key)} = ${renderIndexOptionValue(key, value)}`).join(", ");
|
|
388
435
|
}
|
|
389
|
-
function createIndex(schemaName, tableName, indexName, columns, extras) {
|
|
436
|
+
async function createIndex(schemaName, tableName, indexName, columns, lowerer, extras) {
|
|
390
437
|
const qualified = qualifyTableName(schemaName, tableName);
|
|
391
438
|
const columnList = columns.map(quoteIdentifier).join(", ");
|
|
392
439
|
const using = extras?.type ? ` USING ${quoteIdentifier(extras.type)}` : "";
|
|
393
440
|
const options = extras?.options;
|
|
394
441
|
const withClause = options && Object.keys(options).length > 0 ? ` WITH (${renderIndexOptions(options)})` : "";
|
|
442
|
+
const { present, absent } = await indexExistsSteps(lowerer, schemaName, indexName);
|
|
395
443
|
return {
|
|
396
444
|
id: `index.${tableName}.${indexName}`,
|
|
397
445
|
label: `Create index "${indexName}" on "${tableName}"`,
|
|
398
446
|
operationClass: "additive",
|
|
399
447
|
target: targetDetails("index", indexName, schemaName, tableName),
|
|
400
|
-
precheck: [step(`ensure index "${indexName}" does not exist`,
|
|
448
|
+
precheck: [step(`ensure index "${indexName}" does not exist`, absent.sql, absent.params)],
|
|
401
449
|
execute: [step(`create index "${indexName}"`, `CREATE INDEX ${quoteIdentifier(indexName)} ON ${qualified}${using} (${columnList})${withClause}`)],
|
|
402
|
-
postcheck: [step(`verify index "${indexName}" exists`,
|
|
450
|
+
postcheck: [step(`verify index "${indexName}" exists`, present.sql, present.params)]
|
|
403
451
|
};
|
|
404
452
|
}
|
|
405
|
-
function dropIndex(schemaName, tableName, indexName) {
|
|
453
|
+
async function dropIndex(schemaName, tableName, indexName, lowerer) {
|
|
454
|
+
const { present, absent } = await indexExistsSteps(lowerer, schemaName, indexName);
|
|
406
455
|
return {
|
|
407
456
|
id: `dropIndex.${tableName}.${indexName}`,
|
|
408
457
|
label: `Drop index "${indexName}"`,
|
|
409
458
|
operationClass: "destructive",
|
|
410
459
|
target: targetDetails("index", indexName, schemaName, tableName),
|
|
411
|
-
precheck: [step(`ensure index "${indexName}" exists`,
|
|
460
|
+
precheck: [step(`ensure index "${indexName}" exists`, present.sql, present.params)],
|
|
412
461
|
execute: [step(`drop index "${indexName}"`, `DROP INDEX ${qualifyTableName(schemaName, indexName)}`)],
|
|
413
|
-
postcheck: [step(`verify index "${indexName}" does not exist`,
|
|
462
|
+
postcheck: [step(`verify index "${indexName}" does not exist`, absent.sql, absent.params)]
|
|
414
463
|
};
|
|
415
464
|
}
|
|
416
465
|
//#endregion
|
|
417
466
|
//#region src/core/migrations/operations/tables.ts
|
|
418
|
-
function dropTable(schemaName, tableName) {
|
|
467
|
+
async function dropTable(schemaName, tableName, lowerer) {
|
|
419
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());
|
|
420
472
|
return {
|
|
421
473
|
id: `dropTable.${tableName}`,
|
|
422
474
|
label: `Drop table "${tableName}"`,
|
|
423
475
|
operationClass: "destructive",
|
|
424
476
|
target: targetDetails("table", tableName, schemaName),
|
|
425
|
-
precheck: [step(`ensure table "${tableName}" exists`,
|
|
477
|
+
precheck: [step(`ensure table "${tableName}" exists`, present.sql, present.params)],
|
|
426
478
|
execute: [step(`drop table "${tableName}"`, `DROP TABLE ${qualified}`)],
|
|
427
|
-
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
|
+
]
|
|
428
545
|
};
|
|
429
546
|
}
|
|
430
547
|
//#endregion
|
|
@@ -554,19 +671,22 @@ var CreateTableCall = class extends PostgresOpFactoryCallNode {
|
|
|
554
671
|
const statement = await lowerer.lowerToExecuteRequest(ddlNode);
|
|
555
672
|
const schemaName = this.schemaName;
|
|
556
673
|
const tableName = this.tableName;
|
|
674
|
+
const checks = tableExistsAst(schemaName, tableName);
|
|
675
|
+
const absent = await lowerer.lowerToExecuteRequest(checks.tableAbsent());
|
|
676
|
+
const present = await lowerer.lowerToExecuteRequest(checks.tablePresent());
|
|
557
677
|
return {
|
|
558
678
|
id: `table.${tableName}`,
|
|
559
679
|
label: `Create table "${tableName}"`,
|
|
560
680
|
summary: `Creates table "${tableName}"`,
|
|
561
681
|
operationClass: "additive",
|
|
562
682
|
target: targetDetails("table", tableName, schemaName),
|
|
563
|
-
precheck: [step(`ensure table "${tableName}" does not exist`,
|
|
683
|
+
precheck: [step(`ensure table "${tableName}" does not exist`, absent.sql, absent.params)],
|
|
564
684
|
execute: [{
|
|
565
685
|
description: `create table "${tableName}"`,
|
|
566
686
|
sql: statement.sql,
|
|
567
687
|
params: statement.params ?? []
|
|
568
688
|
}],
|
|
569
|
-
postcheck: [step(`verify table "${tableName}" exists`,
|
|
689
|
+
postcheck: [step(`verify table "${tableName}" exists`, present.sql, present.params)]
|
|
570
690
|
};
|
|
571
691
|
}
|
|
572
692
|
renderTypeScript() {
|
|
@@ -611,11 +731,18 @@ var DropTableCall = class extends PostgresOpFactoryCallNode {
|
|
|
611
731
|
this.label = `Drop table "${tableName}"`;
|
|
612
732
|
this.freeze();
|
|
613
733
|
}
|
|
614
|
-
toOp() {
|
|
615
|
-
|
|
734
|
+
async toOp(lowerer) {
|
|
735
|
+
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.`);
|
|
736
|
+
return dropTable(this.schemaName, this.tableName, lowerer);
|
|
616
737
|
}
|
|
617
738
|
renderTypeScript() {
|
|
618
|
-
|
|
739
|
+
const opts = [];
|
|
740
|
+
if (this.schemaName !== UNBOUND_NAMESPACE_ID) opts.push(`schema: ${jsonToTsSource(this.schemaName)}`);
|
|
741
|
+
opts.push(`table: ${jsonToTsSource(this.tableName)}`);
|
|
742
|
+
return `this.dropTable({ ${opts.join(", ")} })`;
|
|
743
|
+
}
|
|
744
|
+
importRequirements() {
|
|
745
|
+
return [];
|
|
619
746
|
}
|
|
620
747
|
};
|
|
621
748
|
var AddColumnCall = class extends PostgresOpFactoryCallNode {
|
|
@@ -644,23 +771,21 @@ var AddColumnCall = class extends PostgresOpFactoryCallNode {
|
|
|
644
771
|
const schemaName = this.schemaName;
|
|
645
772
|
const tableName = this.tableName;
|
|
646
773
|
const columnName = this.column.name;
|
|
774
|
+
const colChecks = columnExistsAst({
|
|
775
|
+
schema: schemaName,
|
|
776
|
+
table: tableName,
|
|
777
|
+
column: columnName
|
|
778
|
+
});
|
|
779
|
+
const absent = await lowerer.lowerToExecuteRequest(colChecks.columnAbsent());
|
|
780
|
+
const present = await lowerer.lowerToExecuteRequest(colChecks.columnPresent());
|
|
647
781
|
return {
|
|
648
782
|
id: `column.${tableName}.${columnName}`,
|
|
649
783
|
label: `Add column "${columnName}" to "${tableName}"`,
|
|
650
784
|
operationClass: "additive",
|
|
651
785
|
target: targetDetails("column", columnName, schemaName, tableName),
|
|
652
|
-
precheck: [step(`ensure column "${columnName}" is missing`,
|
|
653
|
-
schema: schemaName,
|
|
654
|
-
table: tableName,
|
|
655
|
-
column: columnName,
|
|
656
|
-
exists: false
|
|
657
|
-
}))],
|
|
786
|
+
precheck: [step(`ensure column "${columnName}" is missing`, absent.sql, absent.params)],
|
|
658
787
|
execute: [step(`add column "${columnName}"`, statement.sql)],
|
|
659
|
-
postcheck: [step(`verify column "${columnName}" exists`,
|
|
660
|
-
schema: schemaName,
|
|
661
|
-
table: tableName,
|
|
662
|
-
column: columnName
|
|
663
|
-
}))]
|
|
788
|
+
postcheck: [step(`verify column "${columnName}" exists`, present.sql, present.params)]
|
|
664
789
|
};
|
|
665
790
|
}
|
|
666
791
|
renderTypeScript() {
|
|
@@ -697,11 +822,19 @@ var DropColumnCall = class extends PostgresOpFactoryCallNode {
|
|
|
697
822
|
this.label = `Drop column "${columnName}" from "${tableName}"`;
|
|
698
823
|
this.freeze();
|
|
699
824
|
}
|
|
700
|
-
toOp() {
|
|
701
|
-
|
|
825
|
+
async toOp(lowerer) {
|
|
826
|
+
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.`);
|
|
827
|
+
return dropColumn(this.schemaName, this.tableName, this.columnName, lowerer);
|
|
702
828
|
}
|
|
703
829
|
renderTypeScript() {
|
|
704
|
-
|
|
830
|
+
const opts = [];
|
|
831
|
+
if (this.schemaName !== UNBOUND_NAMESPACE_ID) opts.push(`schema: ${jsonToTsSource(this.schemaName)}`);
|
|
832
|
+
opts.push(`table: ${jsonToTsSource(this.tableName)}`);
|
|
833
|
+
opts.push(`column: ${jsonToTsSource(this.columnName)}`);
|
|
834
|
+
return `this.dropColumn({ ${opts.join(", ")} })`;
|
|
835
|
+
}
|
|
836
|
+
importRequirements() {
|
|
837
|
+
return [];
|
|
705
838
|
}
|
|
706
839
|
};
|
|
707
840
|
var AlterColumnTypeCall = class extends PostgresOpFactoryCallNode {
|
|
@@ -721,11 +854,20 @@ var AlterColumnTypeCall = class extends PostgresOpFactoryCallNode {
|
|
|
721
854
|
this.label = `Alter type of "${tableName}"."${columnName}" to ${options.rawTargetTypeForLabel}`;
|
|
722
855
|
this.freeze();
|
|
723
856
|
}
|
|
724
|
-
toOp() {
|
|
725
|
-
|
|
857
|
+
async toOp(lowerer) {
|
|
858
|
+
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.`);
|
|
859
|
+
return alterColumnType(this.schemaName, this.tableName, this.columnName, this.options, lowerer);
|
|
726
860
|
}
|
|
727
861
|
renderTypeScript() {
|
|
728
|
-
|
|
862
|
+
const opts = [];
|
|
863
|
+
if (this.schemaName !== UNBOUND_NAMESPACE_ID) opts.push(`schema: ${jsonToTsSource(this.schemaName)}`);
|
|
864
|
+
opts.push(`table: ${jsonToTsSource(this.tableName)}`);
|
|
865
|
+
opts.push(`column: ${jsonToTsSource(this.columnName)}`);
|
|
866
|
+
opts.push(`options: ${jsonToTsSource(this.options)}`);
|
|
867
|
+
return `this.alterColumnType({ ${opts.join(", ")} })`;
|
|
868
|
+
}
|
|
869
|
+
importRequirements() {
|
|
870
|
+
return [];
|
|
729
871
|
}
|
|
730
872
|
};
|
|
731
873
|
var SetNotNullCall = class extends PostgresOpFactoryCallNode {
|
|
@@ -743,11 +885,19 @@ var SetNotNullCall = class extends PostgresOpFactoryCallNode {
|
|
|
743
885
|
this.label = `Set NOT NULL on "${tableName}"."${columnName}"`;
|
|
744
886
|
this.freeze();
|
|
745
887
|
}
|
|
746
|
-
toOp() {
|
|
747
|
-
|
|
888
|
+
async toOp(lowerer) {
|
|
889
|
+
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.`);
|
|
890
|
+
return setNotNull(this.schemaName, this.tableName, this.columnName, lowerer);
|
|
748
891
|
}
|
|
749
892
|
renderTypeScript() {
|
|
750
|
-
|
|
893
|
+
const opts = [];
|
|
894
|
+
if (this.schemaName !== UNBOUND_NAMESPACE_ID) opts.push(`schema: ${jsonToTsSource(this.schemaName)}`);
|
|
895
|
+
opts.push(`table: ${jsonToTsSource(this.tableName)}`);
|
|
896
|
+
opts.push(`column: ${jsonToTsSource(this.columnName)}`);
|
|
897
|
+
return `this.setNotNull({ ${opts.join(", ")} })`;
|
|
898
|
+
}
|
|
899
|
+
importRequirements() {
|
|
900
|
+
return [];
|
|
751
901
|
}
|
|
752
902
|
};
|
|
753
903
|
var DropNotNullCall = class extends PostgresOpFactoryCallNode {
|
|
@@ -765,11 +915,19 @@ var DropNotNullCall = class extends PostgresOpFactoryCallNode {
|
|
|
765
915
|
this.label = `Drop NOT NULL on "${tableName}"."${columnName}"`;
|
|
766
916
|
this.freeze();
|
|
767
917
|
}
|
|
768
|
-
toOp() {
|
|
769
|
-
|
|
918
|
+
async toOp(lowerer) {
|
|
919
|
+
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.`);
|
|
920
|
+
return dropNotNull(this.schemaName, this.tableName, this.columnName, lowerer);
|
|
770
921
|
}
|
|
771
922
|
renderTypeScript() {
|
|
772
|
-
|
|
923
|
+
const opts = [];
|
|
924
|
+
if (this.schemaName !== UNBOUND_NAMESPACE_ID) opts.push(`schema: ${jsonToTsSource(this.schemaName)}`);
|
|
925
|
+
opts.push(`table: ${jsonToTsSource(this.tableName)}`);
|
|
926
|
+
opts.push(`column: ${jsonToTsSource(this.columnName)}`);
|
|
927
|
+
return `this.dropNotNull({ ${opts.join(", ")} })`;
|
|
928
|
+
}
|
|
929
|
+
importRequirements() {
|
|
930
|
+
return [];
|
|
773
931
|
}
|
|
774
932
|
};
|
|
775
933
|
var SetDefaultCall = class extends PostgresOpFactoryCallNode {
|
|
@@ -790,18 +948,21 @@ var SetDefaultCall = class extends PostgresOpFactoryCallNode {
|
|
|
790
948
|
this.label = `Set default on "${tableName}"."${columnName}"`;
|
|
791
949
|
this.freeze();
|
|
792
950
|
}
|
|
793
|
-
toOp() {
|
|
794
|
-
|
|
951
|
+
async toOp(lowerer) {
|
|
952
|
+
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.`);
|
|
953
|
+
return setDefault(this.schemaName, this.tableName, this.columnName, this.defaultSql, lowerer, this.operationClass);
|
|
795
954
|
}
|
|
796
955
|
renderTypeScript() {
|
|
797
|
-
const
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
956
|
+
const opts = [];
|
|
957
|
+
if (this.schemaName !== UNBOUND_NAMESPACE_ID) opts.push(`schema: ${jsonToTsSource(this.schemaName)}`);
|
|
958
|
+
opts.push(`table: ${jsonToTsSource(this.tableName)}`);
|
|
959
|
+
opts.push(`column: ${jsonToTsSource(this.columnName)}`);
|
|
960
|
+
opts.push(`defaultSql: ${jsonToTsSource(this.defaultSql)}`);
|
|
961
|
+
if (this.operationClass !== "additive") opts.push(`operationClass: ${jsonToTsSource(this.operationClass)}`);
|
|
962
|
+
return `this.setDefault({ ${opts.join(", ")} })`;
|
|
963
|
+
}
|
|
964
|
+
importRequirements() {
|
|
965
|
+
return [];
|
|
805
966
|
}
|
|
806
967
|
};
|
|
807
968
|
var DropDefaultCall = class extends PostgresOpFactoryCallNode {
|
|
@@ -819,13 +980,127 @@ var DropDefaultCall = class extends PostgresOpFactoryCallNode {
|
|
|
819
980
|
this.label = `Drop default on "${tableName}"."${columnName}"`;
|
|
820
981
|
this.freeze();
|
|
821
982
|
}
|
|
822
|
-
toOp() {
|
|
823
|
-
|
|
983
|
+
async toOp(lowerer) {
|
|
984
|
+
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.`);
|
|
985
|
+
return dropDefault(this.schemaName, this.tableName, this.columnName, lowerer);
|
|
986
|
+
}
|
|
987
|
+
renderTypeScript() {
|
|
988
|
+
const opts = [];
|
|
989
|
+
if (this.schemaName !== UNBOUND_NAMESPACE_ID) opts.push(`schema: ${jsonToTsSource(this.schemaName)}`);
|
|
990
|
+
opts.push(`table: ${jsonToTsSource(this.tableName)}`);
|
|
991
|
+
opts.push(`column: ${jsonToTsSource(this.columnName)}`);
|
|
992
|
+
return `this.dropDefault({ ${opts.join(", ")} })`;
|
|
993
|
+
}
|
|
994
|
+
importRequirements() {
|
|
995
|
+
return [];
|
|
996
|
+
}
|
|
997
|
+
};
|
|
998
|
+
/**
|
|
999
|
+
* Planner-internal call for adding a NOT NULL column (no contract default) to
|
|
1000
|
+
* a table that must be empty at migration time. Carries the raw ADD COLUMN SQL
|
|
1001
|
+
* (produced by `buildAddColumnSql` at plan time — deferred from slice-7 typed
|
|
1002
|
+
* DDL) plus the parameters needed to lower the typed pre/postchecks at render
|
|
1003
|
+
* time.
|
|
1004
|
+
*
|
|
1005
|
+
* No authored `PostgresMigration` method: this call is only emitted by the
|
|
1006
|
+
* planner, never hand-written by migration authors.
|
|
1007
|
+
*/
|
|
1008
|
+
var AddNotNullColumnDirectCall = class extends PostgresOpFactoryCallNode {
|
|
1009
|
+
factoryName = "rawSql";
|
|
1010
|
+
operationClass = "additive";
|
|
1011
|
+
schemaName;
|
|
1012
|
+
tableName;
|
|
1013
|
+
columnName;
|
|
1014
|
+
executeStepSql;
|
|
1015
|
+
label;
|
|
1016
|
+
constructor(schemaName, tableName, columnName, executeStepSql) {
|
|
1017
|
+
super();
|
|
1018
|
+
this.schemaName = schemaName;
|
|
1019
|
+
this.tableName = tableName;
|
|
1020
|
+
this.columnName = columnName;
|
|
1021
|
+
this.executeStepSql = executeStepSql;
|
|
1022
|
+
this.label = `Add column ${columnName} to ${tableName}`;
|
|
1023
|
+
this.freeze();
|
|
1024
|
+
}
|
|
1025
|
+
async toOp(lowerer) {
|
|
1026
|
+
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.`);
|
|
1027
|
+
return addNotNullColumnDirect(this.schemaName, this.tableName, this.columnName, this.executeStepSql, lowerer);
|
|
1028
|
+
}
|
|
1029
|
+
renderTypeScript() {
|
|
1030
|
+
return `rawSql(${jsonToTsSource({
|
|
1031
|
+
id: `column.${this.tableName}.${this.columnName}`,
|
|
1032
|
+
label: this.label,
|
|
1033
|
+
operationClass: "additive"
|
|
1034
|
+
})})`;
|
|
1035
|
+
}
|
|
1036
|
+
importRequirements() {
|
|
1037
|
+
return [];
|
|
1038
|
+
}
|
|
1039
|
+
};
|
|
1040
|
+
/**
|
|
1041
|
+
* Planner-internal call for adding a NOT NULL column (no contract default)
|
|
1042
|
+
* using a temporary default value for non-empty tables. Carries all parameters
|
|
1043
|
+
* needed for `buildAddNotNullColumnWithTemporaryDefaultOperation`; the typed
|
|
1044
|
+
* pre/postchecks are lowered at render time via `toOp(lowerer)`. The execute
|
|
1045
|
+
* SQL (`buildAddColumnSql`) is still raw per slice-7 deferral.
|
|
1046
|
+
*
|
|
1047
|
+
* No authored `PostgresMigration` method: this call is only emitted by the
|
|
1048
|
+
* planner, never hand-written by migration authors.
|
|
1049
|
+
*/
|
|
1050
|
+
var AddNotNullColumnWithTempDefaultCall = class extends PostgresOpFactoryCallNode {
|
|
1051
|
+
factoryName = "rawSql";
|
|
1052
|
+
operationClass = "additive";
|
|
1053
|
+
schemaName;
|
|
1054
|
+
tableName;
|
|
1055
|
+
columnName;
|
|
1056
|
+
column;
|
|
1057
|
+
codecHooks;
|
|
1058
|
+
storageTypes;
|
|
1059
|
+
temporaryDefault;
|
|
1060
|
+
label;
|
|
1061
|
+
constructor(options) {
|
|
1062
|
+
super();
|
|
1063
|
+
this.schemaName = options.schemaName;
|
|
1064
|
+
this.tableName = options.tableName;
|
|
1065
|
+
this.columnName = options.columnName;
|
|
1066
|
+
this.column = options.column;
|
|
1067
|
+
this.codecHooks = options.codecHooks;
|
|
1068
|
+
this.storageTypes = options.storageTypes;
|
|
1069
|
+
this.temporaryDefault = options.temporaryDefault;
|
|
1070
|
+
this.label = `Add column ${options.columnName} to ${options.tableName}`;
|
|
1071
|
+
this.freeze();
|
|
1072
|
+
}
|
|
1073
|
+
async toOp(lowerer) {
|
|
1074
|
+
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.`);
|
|
1075
|
+
return buildAddNotNullColumnWithTemporaryDefaultOperation({
|
|
1076
|
+
schema: this.schemaName,
|
|
1077
|
+
tableName: this.tableName,
|
|
1078
|
+
columnName: this.columnName,
|
|
1079
|
+
column: this.column,
|
|
1080
|
+
codecHooks: this.codecHooks,
|
|
1081
|
+
storageTypes: this.storageTypes,
|
|
1082
|
+
temporaryDefault: this.temporaryDefault,
|
|
1083
|
+
lowerer
|
|
1084
|
+
});
|
|
824
1085
|
}
|
|
825
1086
|
renderTypeScript() {
|
|
826
|
-
return `
|
|
1087
|
+
return `rawSql(${jsonToTsSource({
|
|
1088
|
+
id: `column.${this.tableName}.${this.columnName}`,
|
|
1089
|
+
label: this.label,
|
|
1090
|
+
operationClass: "additive"
|
|
1091
|
+
})})`;
|
|
1092
|
+
}
|
|
1093
|
+
importRequirements() {
|
|
1094
|
+
return [];
|
|
827
1095
|
}
|
|
828
1096
|
};
|
|
1097
|
+
function constraintCallOptions(schemaName, tableName, constraintName) {
|
|
1098
|
+
const opts = [];
|
|
1099
|
+
if (schemaName !== UNBOUND_NAMESPACE_ID) opts.push(`schema: ${jsonToTsSource(schemaName)}`);
|
|
1100
|
+
opts.push(`table: ${jsonToTsSource(tableName)}`);
|
|
1101
|
+
opts.push(`constraint: ${jsonToTsSource(constraintName)}`);
|
|
1102
|
+
return opts.join(", ");
|
|
1103
|
+
}
|
|
829
1104
|
var AddPrimaryKeyCall = class extends PostgresOpFactoryCallNode {
|
|
830
1105
|
factoryName = "addPrimaryKey";
|
|
831
1106
|
operationClass = "additive";
|
|
@@ -843,11 +1118,15 @@ var AddPrimaryKeyCall = class extends PostgresOpFactoryCallNode {
|
|
|
843
1118
|
this.label = `Add primary key on "${tableName}"`;
|
|
844
1119
|
this.freeze();
|
|
845
1120
|
}
|
|
846
|
-
toOp() {
|
|
847
|
-
|
|
1121
|
+
async toOp(lowerer) {
|
|
1122
|
+
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.`);
|
|
1123
|
+
return addPrimaryKey(this.schemaName, this.tableName, this.constraintName, this.columns, lowerer);
|
|
848
1124
|
}
|
|
849
1125
|
renderTypeScript() {
|
|
850
|
-
return `addPrimaryKey(${
|
|
1126
|
+
return `this.addPrimaryKey({ ${constraintCallOptions(this.schemaName, this.tableName, this.constraintName)}, columns: ${jsonToTsSource(this.columns)} })`;
|
|
1127
|
+
}
|
|
1128
|
+
importRequirements() {
|
|
1129
|
+
return [];
|
|
851
1130
|
}
|
|
852
1131
|
};
|
|
853
1132
|
var AddUniqueCall = class extends PostgresOpFactoryCallNode {
|
|
@@ -867,11 +1146,15 @@ var AddUniqueCall = class extends PostgresOpFactoryCallNode {
|
|
|
867
1146
|
this.label = `Add unique constraint on "${tableName}" (${columns.join(", ")})`;
|
|
868
1147
|
this.freeze();
|
|
869
1148
|
}
|
|
870
|
-
toOp() {
|
|
871
|
-
|
|
1149
|
+
async toOp(lowerer) {
|
|
1150
|
+
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.`);
|
|
1151
|
+
return addUnique(this.schemaName, this.tableName, this.constraintName, this.columns, lowerer);
|
|
872
1152
|
}
|
|
873
1153
|
renderTypeScript() {
|
|
874
|
-
return `addUnique(${
|
|
1154
|
+
return `this.addUnique({ ${constraintCallOptions(this.schemaName, this.tableName, this.constraintName)}, columns: ${jsonToTsSource(this.columns)} })`;
|
|
1155
|
+
}
|
|
1156
|
+
importRequirements() {
|
|
1157
|
+
return [];
|
|
875
1158
|
}
|
|
876
1159
|
};
|
|
877
1160
|
var AddForeignKeyCall = class extends PostgresOpFactoryCallNode {
|
|
@@ -889,11 +1172,19 @@ var AddForeignKeyCall = class extends PostgresOpFactoryCallNode {
|
|
|
889
1172
|
this.label = `Add foreign key "${fk.name}" on "${tableName}"`;
|
|
890
1173
|
this.freeze();
|
|
891
1174
|
}
|
|
892
|
-
toOp() {
|
|
893
|
-
|
|
1175
|
+
async toOp(lowerer) {
|
|
1176
|
+
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.`);
|
|
1177
|
+
return addForeignKey(this.schemaName, this.tableName, this.fk, lowerer);
|
|
894
1178
|
}
|
|
895
1179
|
renderTypeScript() {
|
|
896
|
-
|
|
1180
|
+
const opts = [];
|
|
1181
|
+
if (this.schemaName !== UNBOUND_NAMESPACE_ID) opts.push(`schema: ${jsonToTsSource(this.schemaName)}`);
|
|
1182
|
+
opts.push(`table: ${jsonToTsSource(this.tableName)}`);
|
|
1183
|
+
opts.push(`foreignKey: ${jsonToTsSource(this.fk)}`);
|
|
1184
|
+
return `this.addForeignKey({ ${opts.join(", ")} })`;
|
|
1185
|
+
}
|
|
1186
|
+
importRequirements() {
|
|
1187
|
+
return [];
|
|
897
1188
|
}
|
|
898
1189
|
};
|
|
899
1190
|
var DropConstraintCall = class extends PostgresOpFactoryCallNode {
|
|
@@ -913,17 +1204,17 @@ var DropConstraintCall = class extends PostgresOpFactoryCallNode {
|
|
|
913
1204
|
this.label = `Drop constraint "${constraintName}" on "${tableName}"`;
|
|
914
1205
|
this.freeze();
|
|
915
1206
|
}
|
|
916
|
-
toOp() {
|
|
917
|
-
|
|
1207
|
+
async toOp(lowerer) {
|
|
1208
|
+
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.`);
|
|
1209
|
+
return dropConstraint(this.schemaName, this.tableName, this.constraintName, lowerer, this.kind);
|
|
918
1210
|
}
|
|
919
1211
|
renderTypeScript() {
|
|
920
|
-
const
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
return `dropConstraint(${args.join(", ")})`;
|
|
1212
|
+
const opts = [constraintCallOptions(this.schemaName, this.tableName, this.constraintName)];
|
|
1213
|
+
if (this.kind !== "unique") opts.push(`kind: ${jsonToTsSource(this.kind)}`);
|
|
1214
|
+
return `this.dropConstraint({ ${opts.join(", ")} })`;
|
|
1215
|
+
}
|
|
1216
|
+
importRequirements() {
|
|
1217
|
+
return [];
|
|
927
1218
|
}
|
|
928
1219
|
};
|
|
929
1220
|
var AddCheckConstraintCall = class extends PostgresOpFactoryCallNode {
|
|
@@ -945,11 +1236,15 @@ var AddCheckConstraintCall = class extends PostgresOpFactoryCallNode {
|
|
|
945
1236
|
this.label = `Add check constraint "${constraintName}" on "${tableName}"."${column}"`;
|
|
946
1237
|
this.freeze();
|
|
947
1238
|
}
|
|
948
|
-
toOp() {
|
|
949
|
-
|
|
1239
|
+
async toOp(lowerer) {
|
|
1240
|
+
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.`);
|
|
1241
|
+
return addCheckConstraint(this.schemaName, this.tableName, this.constraintName, this.column, this.values, lowerer);
|
|
950
1242
|
}
|
|
951
1243
|
renderTypeScript() {
|
|
952
|
-
return `addCheckConstraint(${
|
|
1244
|
+
return `this.addCheckConstraint({ ${constraintCallOptions(this.schemaName, this.tableName, this.constraintName)}, column: ${jsonToTsSource(this.column)}, values: ${jsonToTsSource(this.values)} })`;
|
|
1245
|
+
}
|
|
1246
|
+
importRequirements() {
|
|
1247
|
+
return [];
|
|
953
1248
|
}
|
|
954
1249
|
};
|
|
955
1250
|
var DropCheckConstraintCall = class extends PostgresOpFactoryCallNode {
|
|
@@ -967,11 +1262,15 @@ var DropCheckConstraintCall = class extends PostgresOpFactoryCallNode {
|
|
|
967
1262
|
this.label = `Drop check constraint "${constraintName}" on "${tableName}"`;
|
|
968
1263
|
this.freeze();
|
|
969
1264
|
}
|
|
970
|
-
toOp() {
|
|
971
|
-
|
|
1265
|
+
async toOp(lowerer) {
|
|
1266
|
+
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.`);
|
|
1267
|
+
return dropCheckConstraint(this.schemaName, this.tableName, this.constraintName, lowerer);
|
|
972
1268
|
}
|
|
973
1269
|
renderTypeScript() {
|
|
974
|
-
return `dropCheckConstraint(${
|
|
1270
|
+
return `this.dropCheckConstraint({ ${constraintCallOptions(this.schemaName, this.tableName, this.constraintName)} })`;
|
|
1271
|
+
}
|
|
1272
|
+
importRequirements() {
|
|
1273
|
+
return [];
|
|
975
1274
|
}
|
|
976
1275
|
};
|
|
977
1276
|
var CreateIndexCall = class extends PostgresOpFactoryCallNode {
|
|
@@ -995,26 +1294,29 @@ var CreateIndexCall = class extends PostgresOpFactoryCallNode {
|
|
|
995
1294
|
this.label = `Create index "${indexName}" on "${tableName}"`;
|
|
996
1295
|
this.freeze();
|
|
997
1296
|
}
|
|
998
|
-
toOp() {
|
|
1297
|
+
async toOp(lowerer) {
|
|
1298
|
+
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.`);
|
|
999
1299
|
const extras = {};
|
|
1000
1300
|
if (this.indexType !== void 0) extras.type = this.indexType;
|
|
1001
1301
|
if (this.options !== void 0) extras.options = this.options;
|
|
1002
|
-
return createIndex(this.schemaName, this.tableName, this.indexName, this.columns, extras);
|
|
1302
|
+
return createIndex(this.schemaName, this.tableName, this.indexName, this.columns, lowerer, extras);
|
|
1003
1303
|
}
|
|
1004
1304
|
renderTypeScript() {
|
|
1005
|
-
const
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
];
|
|
1305
|
+
const opts = [];
|
|
1306
|
+
if (this.schemaName !== UNBOUND_NAMESPACE_ID) opts.push(`schema: ${jsonToTsSource(this.schemaName)}`);
|
|
1307
|
+
opts.push(`table: ${jsonToTsSource(this.tableName)}`);
|
|
1308
|
+
opts.push(`index: ${jsonToTsSource(this.indexName)}`);
|
|
1309
|
+
opts.push(`columns: ${jsonToTsSource(this.columns)}`);
|
|
1011
1310
|
if (this.indexType !== void 0 || this.options !== void 0) {
|
|
1012
1311
|
const extrasParts = [];
|
|
1013
1312
|
if (this.indexType !== void 0) extrasParts.push(`type: ${jsonToTsSource(this.indexType)}`);
|
|
1014
1313
|
if (this.options !== void 0) extrasParts.push(`options: ${jsonToTsSource(this.options)}`);
|
|
1015
|
-
|
|
1314
|
+
opts.push(`extras: { ${extrasParts.join(", ")} }`);
|
|
1016
1315
|
}
|
|
1017
|
-
return `createIndex(${
|
|
1316
|
+
return `this.createIndex({ ${opts.join(", ")} })`;
|
|
1317
|
+
}
|
|
1318
|
+
importRequirements() {
|
|
1319
|
+
return [];
|
|
1018
1320
|
}
|
|
1019
1321
|
};
|
|
1020
1322
|
var DropIndexCall = class extends PostgresOpFactoryCallNode {
|
|
@@ -1032,11 +1334,19 @@ var DropIndexCall = class extends PostgresOpFactoryCallNode {
|
|
|
1032
1334
|
this.label = `Drop index "${indexName}"`;
|
|
1033
1335
|
this.freeze();
|
|
1034
1336
|
}
|
|
1035
|
-
toOp() {
|
|
1036
|
-
|
|
1337
|
+
async toOp(lowerer) {
|
|
1338
|
+
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.`);
|
|
1339
|
+
return dropIndex(this.schemaName, this.tableName, this.indexName, lowerer);
|
|
1037
1340
|
}
|
|
1038
1341
|
renderTypeScript() {
|
|
1039
|
-
|
|
1342
|
+
const opts = [];
|
|
1343
|
+
if (this.schemaName !== UNBOUND_NAMESPACE_ID) opts.push(`schema: ${jsonToTsSource(this.schemaName)}`);
|
|
1344
|
+
opts.push(`table: ${jsonToTsSource(this.tableName)}`);
|
|
1345
|
+
opts.push(`index: ${jsonToTsSource(this.indexName)}`);
|
|
1346
|
+
return `this.dropIndex({ ${opts.join(", ")} })`;
|
|
1347
|
+
}
|
|
1348
|
+
importRequirements() {
|
|
1349
|
+
return [];
|
|
1040
1350
|
}
|
|
1041
1351
|
};
|
|
1042
1352
|
/**
|
|
@@ -1174,6 +1484,6 @@ var DataTransformCall = class extends PostgresOpFactoryCallNode {
|
|
|
1174
1484
|
}
|
|
1175
1485
|
};
|
|
1176
1486
|
//#endregion
|
|
1177
|
-
export {
|
|
1487
|
+
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 };
|
|
1178
1488
|
|
|
1179
|
-
//# sourceMappingURL=op-factory-call-
|
|
1489
|
+
//# sourceMappingURL=op-factory-call-B1bXWtfa.mjs.map
|