@prisma/orm-target-postgres 8.0.0-rc.16-dev.6 → 8.0.0-rc.16-dev.8
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/{adapter-RtS8vD8U-BnPjAiLV.mjs → adapter-RtS8vD8U-CkJSaICZ.mjs} +2 -2
- package/dist/{adapter-RtS8vD8U-BnPjAiLV.mjs.map → adapter-RtS8vD8U-CkJSaICZ.mjs.map} +1 -1
- package/dist/adapter.mjs +2 -2
- package/dist/adapter__adapter.mjs +2 -2
- package/dist/adapter__control.mjs +4 -4
- package/dist/adapter__runtime.mjs +3 -3
- package/dist/{authoring-B2hHIzvd-D5NgHs0e.mjs → authoring-_2G2lsLt-VmVbrMPn.mjs} +3 -3
- package/dist/{authoring-B2hHIzvd-D5NgHs0e.mjs.map → authoring-_2G2lsLt-VmVbrMPn.mjs.map} +1 -1
- package/dist/{contract-free-DaK6wmmo.mjs → contract-free-BMKFjlIG.mjs} +3 -3
- package/dist/{contract-free-DaK6wmmo.mjs.map → contract-free-BMKFjlIG.mjs.map} +1 -1
- package/dist/{control-Bpd77Aeq.mjs → control-M3kIGGHk.mjs} +9 -9
- package/dist/{control-Bpd77Aeq.mjs.map → control-M3kIGGHk.mjs.map} +1 -1
- package/dist/{control-adapter-Co30P4lH-e6oCFCC2.mjs → control-adapter-Co30P4lH-CpxXk5cz.mjs} +2 -2
- package/dist/{control-adapter-Co30P4lH-e6oCFCC2.mjs.map → control-adapter-Co30P4lH-CpxXk5cz.mjs.map} +1 -1
- package/dist/{control-policy-B7t5CB1S-CotIwNO4.mjs → control-policy-C0KC3-Gw-DseKgAtX.mjs} +54 -33
- package/dist/control-policy-C0KC3-Gw-DseKgAtX.mjs.map +1 -0
- package/dist/{ddl-C_vTj7b5-vyGLBKLo.mjs → ddl-D5hYRCTf-DRSajCVT.mjs} +3 -3
- package/dist/{ddl-C_vTj7b5-vyGLBKLo.mjs.map → ddl-D5hYRCTf-DRSajCVT.mjs.map} +1 -1
- package/dist/{descriptor-meta-ARufwwWW-C5hsT7UQ.mjs → descriptor-meta-ARufwwWW-ChZm5Hg5.mjs} +2 -2
- package/dist/{descriptor-meta-ARufwwWW-C5hsT7UQ.mjs.map → descriptor-meta-ARufwwWW-ChZm5Hg5.mjs.map} +1 -1
- package/dist/{descriptor-meta-C8lkQFHe-Cluy19Tk.mjs → descriptor-meta-WHc6Kv-m-BLzsaP0M.mjs} +4 -4
- package/dist/{descriptor-meta-C8lkQFHe-Cluy19Tk.mjs.map → descriptor-meta-WHc6Kv-m-BLzsaP0M.mjs.map} +1 -1
- package/dist/{diff-database-schema-KGNaKzKp-Bt2yYSIt.mjs → diff-database-schema-D9YbaVKX-DZ5wOErP.mjs} +5 -5
- package/dist/{diff-database-schema-KGNaKzKp-Bt2yYSIt.mjs.map → diff-database-schema-D9YbaVKX-DZ5wOErP.mjs.map} +1 -1
- package/dist/{infer-psl-contract-DoIdoifj-Co9thnGu.mjs → infer-psl-contract-D-3st5lU-DKQhhsut.mjs} +3 -3
- package/dist/{infer-psl-contract-DoIdoifj-Co9thnGu.mjs.map → infer-psl-contract-D-3st5lU-DKQhhsut.mjs.map} +1 -1
- package/dist/{issue-planner-pmBrIrEN.d.mts → issue-planner-BwcfQagl.d.mts} +2 -2
- package/dist/{issue-planner-pmBrIrEN.d.mts.map → issue-planner-BwcfQagl.d.mts.map} +1 -1
- package/dist/{migration-D189kh3f.d.mts → migration-D5f4UTR3.d.mts} +3 -3
- package/dist/{migration-D189kh3f.d.mts.map → migration-D5f4UTR3.d.mts.map} +1 -1
- package/dist/migration-PTHAY9Cv.mjs.map +1 -1
- package/dist/{op-factory-call-CqKUB1XP-CsEGx4Jd.d.mts → op-factory-call-BaT4DlIo-BnVxOrwv.d.mts} +51 -17
- package/dist/op-factory-call-BaT4DlIo-BnVxOrwv.d.mts.map +1 -0
- package/dist/{op-factory-call-BAgAln5R-BTkhp29z.mjs → op-factory-call-CXlapjuM-BHZNE4Ph.mjs} +133 -40
- package/dist/op-factory-call-CXlapjuM-BHZNE4Ph.mjs.map +1 -0
- package/dist/op-factory-call-CwFkWbuo.d.mts +1 -0
- package/dist/{planner-CvUO8Zpn.d.mts → planner-BkGEylgU.d.mts} +17 -8
- package/dist/planner-BkGEylgU.d.mts.map +1 -0
- package/dist/{planner-DSTSuAc8-BAfUo5KV.mjs → planner-DwfHmYme-P1dFkpQ4.mjs} +216 -26
- package/dist/planner-DwfHmYme-P1dFkpQ4.mjs.map +1 -0
- package/dist/{planner-produced-postgres-migration-DT3i_p3G-CyQUv3ac.d.mts → planner-produced-postgres-migration-BwZrjNPg-Ch67sFwK.d.mts} +3 -3
- package/dist/planner-produced-postgres-migration-BwZrjNPg-Ch67sFwK.d.mts.map +1 -0
- package/dist/{planner-produced-postgres-migration-D7-3OBb_-BGHFKj3i.mjs → planner-produced-postgres-migration-DBUj6Imx-DhpHjroB.mjs} +4 -4
- package/dist/{planner-produced-postgres-migration-D7-3OBb_-BGHFKj3i.mjs.map → planner-produced-postgres-migration-DBUj6Imx-DhpHjroB.mjs.map} +1 -1
- package/dist/planner-produced-postgres-migration-eDPWYNBo.d.mts +1 -0
- package/dist/{planner-sql-checks-rqOH8naU-B6xOE5lC.mjs → planner-sql-checks-DCGV2qdu-eaeFLtn8.mjs} +3 -3
- package/dist/{planner-sql-checks-rqOH8naU-B6xOE5lC.mjs.map → planner-sql-checks-DCGV2qdu-eaeFLtn8.mjs.map} +1 -1
- package/dist/{postgres-contract-view-C1bi3x4v-BAfk6euQ.mjs → postgres-contract-view-CL-YTH_3-Diah6i2a.mjs} +4 -4
- package/dist/{postgres-contract-view-C1bi3x4v-BAfk6euQ.mjs.map → postgres-contract-view-CL-YTH_3-Diah6i2a.mjs.map} +1 -1
- package/dist/{postgres-migration-e8UybR1y-C_m4i1jp.d.mts → postgres-migration-D2Xs7BfD-Df3OpTyw.d.mts} +37 -4
- package/dist/postgres-migration-D2Xs7BfD-Df3OpTyw.d.mts.map +1 -0
- package/dist/postgres-migration-DjCmSHjA-D8CPJqkC.mjs +1075 -0
- package/dist/postgres-migration-DjCmSHjA-D8CPJqkC.mjs.map +1 -0
- package/dist/{postgres-schema-AlEVkXXS-ZfXWYddl.mjs → postgres-schema-COkaqci7-C6JpiSha.mjs} +6 -6
- package/dist/postgres-schema-COkaqci7-C6JpiSha.mjs.map +1 -0
- package/dist/{prisma7-binding-B4BfqE0o.mjs → prisma7-binding-CAzQh1rQ.mjs} +5 -5
- package/dist/{prisma7-binding-B4BfqE0o.mjs.map → prisma7-binding-CAzQh1rQ.mjs.map} +1 -1
- package/dist/{render-ops-D2vJApKB-B281fzmn.mjs → render-ops-B5FbJGYf-CnmbaalQ.mjs} +16 -9
- package/dist/render-ops-B5FbJGYf-CnmbaalQ.mjs.map +1 -0
- package/dist/{resolve-ddl-schema-BthOWVjF-DuZ9iUh-.mjs → resolve-ddl-schema-DD69Bwve-e-BpAfFa.mjs} +3 -3
- package/dist/{resolve-ddl-schema-BthOWVjF-DuZ9iUh-.mjs.map → resolve-ddl-schema-DD69Bwve-e-BpAfFa.mjs.map} +1 -1
- package/dist/target.d.mts +9 -9
- package/dist/target.mjs +17 -17
- package/dist/target__contract-free.mjs +3 -3
- package/dist/target__control.mjs +3 -3
- package/dist/target__diff-database-schema.mjs +1 -1
- package/dist/target__issue-planner.d.mts +1 -1
- package/dist/target__issue-planner.mjs +1 -1
- package/dist/target__migration.d.mts +2 -2
- package/dist/target__migration.mjs +2 -2
- package/dist/target__op-factory-call.d.mts +3 -3
- package/dist/target__op-factory-call.mjs +2 -2
- package/dist/target__pack.mjs +1 -1
- package/dist/target__planner-produced-postgres-migration.d.mts +2 -2
- package/dist/target__planner-produced-postgres-migration.mjs +1 -1
- package/dist/target__planner-sql-checks.mjs +1 -1
- package/dist/target__planner.d.mts +1 -1
- package/dist/target__planner.mjs +2 -2
- package/dist/target__prisma7-binding.mjs +1 -1
- package/dist/target__render-ops.mjs +1 -1
- package/dist/target__runtime.mjs +2 -2
- package/dist/target__runtime.mjs.map +1 -1
- package/dist/target__schema-ir-annotations.mjs +1 -1
- package/dist/target__types.mjs +1 -1
- package/package.json +9 -9
- package/dist/control-policy-B7t5CB1S-CotIwNO4.mjs.map +0 -1
- package/dist/op-factory-call-BAgAln5R-BTkhp29z.mjs.map +0 -1
- package/dist/op-factory-call-CqKUB1XP-CsEGx4Jd.d.mts.map +0 -1
- package/dist/op-factory-call-D5UJ7cDi.d.mts +0 -1
- package/dist/planner-CvUO8Zpn.d.mts.map +0 -1
- package/dist/planner-DSTSuAc8-BAfUo5KV.mjs.map +0 -1
- package/dist/planner-produced-postgres-migration-BI_aepPp.d.mts +0 -1
- package/dist/planner-produced-postgres-migration-DT3i_p3G-CyQUv3ac.d.mts.map +0 -1
- package/dist/postgres-migration-CeX6vfEU-DsmCRCnD.mjs +0 -596
- package/dist/postgres-migration-CeX6vfEU-DsmCRCnD.mjs.map +0 -1
- package/dist/postgres-migration-e8UybR1y-C_m4i1jp.d.mts.map +0 -1
- package/dist/postgres-schema-AlEVkXXS-ZfXWYddl.mjs.map +0 -1
- package/dist/render-ops-D2vJApKB-B281fzmn.mjs.map +0 -1
|
@@ -1,596 +0,0 @@
|
|
|
1
|
-
import { t as errorPostgresMigrationStackMissing } from "./errors-DYyzTYzE-39CV_aMo.mjs";
|
|
2
|
-
import { i as PostgresRlsPolicy, n as PostgresRlsEnablement } from "./postgres-schema-AlEVkXXS-ZfXWYddl.mjs";
|
|
3
|
-
import { t as PostgresDatabaseSchemaNode } from "./postgres-role-schema-node-B8Z5i5D--PObwlU2Z.mjs";
|
|
4
|
-
import { n as postgresResolveDefault } from "./default-normalizer-Bf_Fhv4v-CugGfLAe.mjs";
|
|
5
|
-
import { t as resolveDdlSchemaForNamespaceStorage } from "./resolve-ddl-schema-BthOWVjF-DuZ9iUh-.mjs";
|
|
6
|
-
import { a as renderDefaultLiteral } from "./planner-ddl-builders-Y0_96xpe-BzugdEDO.mjs";
|
|
7
|
-
import { A as RenameIndexCall, C as DropNativeEnumTypeCall, D as EnableRowLevelSecurityCall, E as DropTableCall, M as RenameTableCall, N as SetDefaultCall, P as SetNotNullCall, R as installExtension, S as DropIndexCall, T as DropPostgresRlsPolicyCall, _ as DisableRowLevelSecurityCall, b as DropConstraintCall, c as AddUniqueCall, d as CreateIndexCall, f as CreateNativeEnumTypeCall, h as CreateTableCall, i as AddNativeEnumValueCall, j as RenamePostgresRlsPolicyCall, k as RenameConstraintCall, l as AlterColumnTypeCall, m as CreateSchemaCall, n as AddColumnCall, p as CreatePostgresRlsPolicyCall, r as AddForeignKeyCall, s as AddPrimaryKeyCall, t as AddCheckConstraintCall, v as DropCheckConstraintCall, w as DropNotNullCall, x as DropDefaultCall, y as DropColumnCall } from "./op-factory-call-BAgAln5R-BTkhp29z.mjs";
|
|
8
|
-
import { n as defaultPrimaryKeyName, r as defaultUniqueName, t as defaultForeignKeyName } from "./default-constraint-names-CtcRXhV8-nz3ff6b8.mjs";
|
|
9
|
-
import { l as resolveNamespaceIdForDdlSchema, r as issueNode } from "./control-policy-B7t5CB1S-CotIwNO4.mjs";
|
|
10
|
-
import { n as contractToPostgresDatabaseSchemaNode, t as buildPostgresPlanDiff } from "./diff-database-schema-KGNaKzKp-Bt2yYSIt.mjs";
|
|
11
|
-
import { n as PostgresContractView } from "./postgres-contract-view-C1bi3x4v-BAfk6euQ.mjs";
|
|
12
|
-
import { t as dataTransform } from "./data-transform-Bo32KRbq-BLn1_UG-.mjs";
|
|
13
|
-
import { blindCast } from "@prisma/orm-framework/utils/casts";
|
|
14
|
-
import { UNBOUND_NAMESPACE_ID } from "@prisma/orm-framework/components/ir";
|
|
15
|
-
import { issueOutcome } from "@prisma/orm-framework/components/control";
|
|
16
|
-
import { namingOf, parseWireName } from "@prisma/orm-family-sql/schema-ir/naming";
|
|
17
|
-
import { assertDefined } from "@prisma/orm-framework/utils/assertions";
|
|
18
|
-
import { applyTableRename, sqlTypeLookupsOf } from "@prisma/orm-family-sql/family/control";
|
|
19
|
-
import { SqlCheckConstraintIR, SqlIndexIR } from "@prisma/orm-family-sql/schema-ir/types";
|
|
20
|
-
import { errorMigrationOperationOptionRemoved } from "@prisma/orm-framework/errors/migration";
|
|
21
|
-
import { Migration } from "@prisma/orm-family-sql/family/migration";
|
|
22
|
-
import { MigrationContractViews } from "@prisma/orm-toolchain/migration-tools/migration";
|
|
23
|
-
//#region ../../../3-targets/3-targets/postgres/dist/postgres-migration-CeX6vfEU.mjs
|
|
24
|
-
function postgresRenderDefault(def, column, type) {
|
|
25
|
-
if (def.kind === "function") return def.expression;
|
|
26
|
-
return renderDefaultLiteral(def.value, {
|
|
27
|
-
many: column.many,
|
|
28
|
-
...type
|
|
29
|
-
});
|
|
30
|
-
}
|
|
31
|
-
/**
|
|
32
|
-
* The Postgres schema tree a contract describes, as the planner's "from" side:
|
|
33
|
-
* the target descriptor's `migrations.contractToSchema` hook and the trees
|
|
34
|
-
* `renameTable` compares to find its companion renames both go through here,
|
|
35
|
-
* so they are built with the same type lookups, default renderer and default resolver.
|
|
36
|
-
*/
|
|
37
|
-
function postgresContractToSchema(contract, frameworkComponents) {
|
|
38
|
-
const types = sqlTypeLookupsOf(frameworkComponents);
|
|
39
|
-
return contractToPostgresDatabaseSchemaNode(blindCast(contract), {
|
|
40
|
-
annotationNamespace: "pg",
|
|
41
|
-
dataTypeLookup: types.dataTypeLookup,
|
|
42
|
-
codecLookup: types.codecLookup,
|
|
43
|
-
renderDefault: postgresRenderDefault,
|
|
44
|
-
resolveDefault: postgresResolveDefault
|
|
45
|
-
});
|
|
46
|
-
}
|
|
47
|
-
/** The constraint of `nextNodes` the diff pairs with `node` and finds unchanged. */
|
|
48
|
-
function unchangedIn(node, nextNodes) {
|
|
49
|
-
return nextNodes.find((next) => next.id === node.id && next.isEqualTo(node));
|
|
50
|
-
}
|
|
51
|
-
/**
|
|
52
|
-
* The renames of the primary key, unique constraints and foreign keys of one table that the end tree keeps otherwise unchanged but names differently. A constraint's name is its stated name, or the one the planner derives from its table; a start tree read from the database states every name. A constraint whose start and end names differ is renamed to the end name. The diff never compares constraint names, so without these the database keeps the old name. A database may already have the new name, as when Prisma 7 created it and the contract only now states it; the rename's postcheck then holds before it runs, and the runner skips it.
|
|
53
|
-
*/
|
|
54
|
-
function constraintNameRenames(input) {
|
|
55
|
-
const { schemaName, from, to, previous, next } = input;
|
|
56
|
-
const rename = (kind, oldName, unchanged, derivedName) => {
|
|
57
|
-
if (unchanged === void 0) return [];
|
|
58
|
-
const newName = unchanged.name ?? derivedName;
|
|
59
|
-
return oldName === newName ? [] : [new RenameConstraintCall(schemaName, to, kind, oldName, newName)];
|
|
60
|
-
};
|
|
61
|
-
const primaryKey = previous.primaryKey === void 0 ? [] : rename("primaryKey", previous.primaryKey.name ?? defaultPrimaryKeyName(from), unchangedIn(previous.primaryKey, next.primaryKey === void 0 ? [] : [next.primaryKey]), defaultPrimaryKeyName(to));
|
|
62
|
-
const uniques = previous.uniques.flatMap((unique) => rename("unique", unique.name ?? defaultUniqueName(from, unique.columns), unchangedIn(unique, next.uniques), defaultUniqueName(to, unique.columns)));
|
|
63
|
-
const foreignKeys = previous.foreignKeys.flatMap((fk) => rename("foreignKey", fk.name ?? defaultForeignKeyName(from, fk.columns), unchangedIn(fk, next.foreignKeys), defaultForeignKeyName(to, fk.columns)));
|
|
64
|
-
return [
|
|
65
|
-
...primaryKey,
|
|
66
|
-
...uniques,
|
|
67
|
-
...foreignKeys
|
|
68
|
-
];
|
|
69
|
-
}
|
|
70
|
-
/**
|
|
71
|
-
* The constraint renames of a plan: {@link constraintNameRenames} for every table the start tree the planner was given and the end contract both have. The start tree comes from the start contract for `migration plan` and from the database for `db update`, so a database Prisma 8 created under derived names is renamed too once the contract states other names.
|
|
72
|
-
*/
|
|
73
|
-
function plannedConstraintNameRenames(options) {
|
|
74
|
-
if (!options.policy.allowedOperationClasses.includes("widening")) return [];
|
|
75
|
-
PostgresDatabaseSchemaNode.assert(options.schema);
|
|
76
|
-
const startTablesBySchema = new Map(Object.values(options.schema.namespaces).map((namespace) => [namespace.schemaName, namespace.tables]));
|
|
77
|
-
const contract = options.contract;
|
|
78
|
-
const end = postgresContractToSchema(contract, options.frameworkComponents);
|
|
79
|
-
return Object.values(end.namespaces).flatMap((namespace) => {
|
|
80
|
-
const startTables = startTablesBySchema.get(namespace.schemaName) ?? {};
|
|
81
|
-
const schemaName = resolveNamespaceIdForDdlSchema(contract, namespace.schemaName) === UNBOUND_NAMESPACE_ID ? UNBOUND_NAMESPACE_ID : namespace.schemaName;
|
|
82
|
-
return Object.entries(namespace.tables).flatMap(([tableName, next]) => {
|
|
83
|
-
const previous = startTables[tableName];
|
|
84
|
-
return previous === void 0 ? [] : constraintNameRenames({
|
|
85
|
-
schemaName,
|
|
86
|
-
from: tableName,
|
|
87
|
-
to: tableName,
|
|
88
|
-
previous,
|
|
89
|
-
next
|
|
90
|
-
});
|
|
91
|
-
});
|
|
92
|
-
});
|
|
93
|
-
}
|
|
94
|
-
/**
|
|
95
|
-
* Rename post-pass for indexes, per `(schema, table)`, widening-only,
|
|
96
|
-
* deterministic by sorted names — the same structure as the policy pass
|
|
97
|
-
* below (which stays untouched: policies pair by hash only).
|
|
98
|
-
*
|
|
99
|
-
* Hash pairing (prefix-only renames): extras whose live names parse as
|
|
100
|
-
* wire names, grouped by `(schema, table, hash)`; missing nodes iterated
|
|
101
|
-
* in sorted-name order consume the sorted-name-first candidate.
|
|
102
|
-
*
|
|
103
|
-
* Content pairing (exact→wire convergence), after hash pairing has
|
|
104
|
-
* consumed its matches: the remaining wire-named-missing nodes
|
|
105
|
-
* (`prefix` defined) against the remaining extras of any name shape,
|
|
106
|
-
* paired iff content-equal (columns ordered-strict both-defined-or-
|
|
107
|
-
* both-undefined, `unique`/`type` strict, `options` loose, bodies
|
|
108
|
-
* byte-equal).
|
|
109
|
-
*
|
|
110
|
-
* Leftovers proceed as create/drop exactly as before; without the
|
|
111
|
-
* widening allowance the pass is skipped and pairing degrades to the
|
|
112
|
-
* additive half, like the policy pass.
|
|
113
|
-
*/
|
|
114
|
-
function pairIndexRenames(options, issues) {
|
|
115
|
-
const consumed = /* @__PURE__ */ new Set();
|
|
116
|
-
const calls = [];
|
|
117
|
-
if (!options.policy.allowedOperationClasses.includes("widening")) return {
|
|
118
|
-
calls,
|
|
119
|
-
consumed
|
|
120
|
-
};
|
|
121
|
-
const missing = [];
|
|
122
|
-
const extra = [];
|
|
123
|
-
for (const issue of issues) {
|
|
124
|
-
const node = issueNode(issue);
|
|
125
|
-
if (node === void 0 || !SqlIndexIR.is(node)) continue;
|
|
126
|
-
const ddlSchema = issue.path[1];
|
|
127
|
-
const tableName = issue.path[2];
|
|
128
|
-
if (ddlSchema === void 0 || tableName === void 0) continue;
|
|
129
|
-
if (issueOutcome(issue) === "not-found") missing.push({
|
|
130
|
-
issue,
|
|
131
|
-
node,
|
|
132
|
-
ddlSchema,
|
|
133
|
-
tableName
|
|
134
|
-
});
|
|
135
|
-
else if (issueOutcome(issue) === "not-expected") extra.push({
|
|
136
|
-
issue,
|
|
137
|
-
node,
|
|
138
|
-
ddlSchema,
|
|
139
|
-
tableName
|
|
140
|
-
});
|
|
141
|
-
}
|
|
142
|
-
if (missing.length === 0 || extra.length === 0) return {
|
|
143
|
-
calls,
|
|
144
|
-
consumed
|
|
145
|
-
};
|
|
146
|
-
const byName = (a, b) => a.node.name < b.node.name ? -1 : a.node.name > b.node.name ? 1 : 0;
|
|
147
|
-
const emissionSchema = (ddlSchema) => resolveNamespaceIdForDdlSchema(options.contract, ddlSchema) === UNBOUND_NAMESPACE_ID ? UNBOUND_NAMESPACE_ID : ddlSchema;
|
|
148
|
-
const pairingKey = (finding, hash) => JSON.stringify([
|
|
149
|
-
finding.ddlSchema,
|
|
150
|
-
finding.tableName,
|
|
151
|
-
hash
|
|
152
|
-
]);
|
|
153
|
-
const rename = (missingFinding, candidate) => {
|
|
154
|
-
consumed.add(missingFinding.issue);
|
|
155
|
-
consumed.add(candidate.issue);
|
|
156
|
-
calls.push(new RenameIndexCall(emissionSchema(missingFinding.ddlSchema), missingFinding.tableName, candidate.node.name, missingFinding.node.name));
|
|
157
|
-
};
|
|
158
|
-
const sortedMissing = [...missing].sort(byName);
|
|
159
|
-
const extrasByHash = /* @__PURE__ */ new Map();
|
|
160
|
-
for (const finding of extra) {
|
|
161
|
-
const parsed = parseWireName(finding.node.name);
|
|
162
|
-
if (parsed === void 0) continue;
|
|
163
|
-
const key = pairingKey(finding, parsed.hash);
|
|
164
|
-
const group = extrasByHash.get(key) ?? [];
|
|
165
|
-
group.push(finding);
|
|
166
|
-
extrasByHash.set(key, group);
|
|
167
|
-
}
|
|
168
|
-
for (const group of extrasByHash.values()) group.sort(byName);
|
|
169
|
-
for (const missingFinding of sortedMissing) {
|
|
170
|
-
const parsed = parseWireName(missingFinding.node.name);
|
|
171
|
-
if (parsed === void 0) continue;
|
|
172
|
-
const candidate = extrasByHash.get(pairingKey(missingFinding, parsed.hash))?.shift();
|
|
173
|
-
if (candidate === void 0) continue;
|
|
174
|
-
rename(missingFinding, candidate);
|
|
175
|
-
}
|
|
176
|
-
const sortedExtras = [...extra].sort(byName);
|
|
177
|
-
for (const missingFinding of sortedMissing) {
|
|
178
|
-
if (consumed.has(missingFinding.issue)) continue;
|
|
179
|
-
if (missingFinding.node.prefix === void 0) continue;
|
|
180
|
-
const candidate = sortedExtras.find((extraFinding) => !consumed.has(extraFinding.issue) && extraFinding.ddlSchema === missingFinding.ddlSchema && extraFinding.tableName === missingFinding.tableName && missingFinding.node.contentEquals(extraFinding.node, {
|
|
181
|
-
columnPresence: "matching",
|
|
182
|
-
bodies: "verbatim"
|
|
183
|
-
}));
|
|
184
|
-
if (candidate === void 0) continue;
|
|
185
|
-
rename(missingFinding, candidate);
|
|
186
|
-
}
|
|
187
|
-
return {
|
|
188
|
-
calls,
|
|
189
|
-
consumed
|
|
190
|
-
};
|
|
191
|
-
}
|
|
192
|
-
/**
|
|
193
|
-
* Check-constraint rename post-pass: a `not-found` and a `not-expected`
|
|
194
|
-
* check on the same table whose wire-name content hashes match but whose
|
|
195
|
-
* prefixes differ is a prefix-only rename, and collapses into one
|
|
196
|
-
* `ALTER TABLE … RENAME CONSTRAINT`.
|
|
197
|
-
*
|
|
198
|
-
* This is the index pass's hash-pairing phase and nothing else. There is
|
|
199
|
-
* deliberately no content-pairing phase: a live check body is whatever
|
|
200
|
-
* Postgres reprinted, so it never byte-matches the authored text, and
|
|
201
|
-
* pairing an exact-named live check by content would bless whatever
|
|
202
|
-
* predicate is actually live. Adoption of an old exact-named check stays
|
|
203
|
-
* drop + add.
|
|
204
|
-
*
|
|
205
|
-
* Runs only when the policy allows `widening` (rename's class). Without it
|
|
206
|
-
* the pass no-ops and the pair degrades to the slice-1 behavior: an add,
|
|
207
|
-
* plus a drop when `destructive` is allowed too.
|
|
208
|
-
*/
|
|
209
|
-
function pairCheckRenames(options, issues) {
|
|
210
|
-
const consumed = /* @__PURE__ */ new Set();
|
|
211
|
-
const calls = [];
|
|
212
|
-
if (!options.policy.allowedOperationClasses.includes("widening")) return {
|
|
213
|
-
calls,
|
|
214
|
-
consumed
|
|
215
|
-
};
|
|
216
|
-
const missing = [];
|
|
217
|
-
const extra = [];
|
|
218
|
-
for (const issue of issues) {
|
|
219
|
-
const node = issueNode(issue);
|
|
220
|
-
if (node === void 0 || !SqlCheckConstraintIR.is(node)) continue;
|
|
221
|
-
const ddlSchema = issue.path[1];
|
|
222
|
-
const tableName = issue.path[2];
|
|
223
|
-
if (ddlSchema === void 0 || tableName === void 0) continue;
|
|
224
|
-
if (issueOutcome(issue) === "not-found") missing.push({
|
|
225
|
-
issue,
|
|
226
|
-
node,
|
|
227
|
-
ddlSchema,
|
|
228
|
-
tableName
|
|
229
|
-
});
|
|
230
|
-
else if (issueOutcome(issue) === "not-expected") extra.push({
|
|
231
|
-
issue,
|
|
232
|
-
node,
|
|
233
|
-
ddlSchema,
|
|
234
|
-
tableName
|
|
235
|
-
});
|
|
236
|
-
}
|
|
237
|
-
if (missing.length === 0 || extra.length === 0) return {
|
|
238
|
-
calls,
|
|
239
|
-
consumed
|
|
240
|
-
};
|
|
241
|
-
const byName = (a, b) => a.node.name < b.node.name ? -1 : a.node.name > b.node.name ? 1 : 0;
|
|
242
|
-
const emissionSchema = (ddlSchema) => resolveNamespaceIdForDdlSchema(options.contract, ddlSchema) === UNBOUND_NAMESPACE_ID ? UNBOUND_NAMESPACE_ID : ddlSchema;
|
|
243
|
-
const pairingKey = (finding, hash) => JSON.stringify([
|
|
244
|
-
finding.ddlSchema,
|
|
245
|
-
finding.tableName,
|
|
246
|
-
hash
|
|
247
|
-
]);
|
|
248
|
-
const sortedMissing = [...missing].sort(byName);
|
|
249
|
-
const extrasByHash = /* @__PURE__ */ new Map();
|
|
250
|
-
for (const finding of extra) {
|
|
251
|
-
const parsed = parseWireName(finding.node.name);
|
|
252
|
-
if (parsed === void 0) continue;
|
|
253
|
-
const key = pairingKey(finding, parsed.hash);
|
|
254
|
-
const group = extrasByHash.get(key) ?? [];
|
|
255
|
-
group.push(finding);
|
|
256
|
-
extrasByHash.set(key, group);
|
|
257
|
-
}
|
|
258
|
-
for (const group of extrasByHash.values()) group.sort(byName);
|
|
259
|
-
for (const missingFinding of sortedMissing) {
|
|
260
|
-
const parsed = parseWireName(missingFinding.node.name);
|
|
261
|
-
if (parsed === void 0) continue;
|
|
262
|
-
const candidate = extrasByHash.get(pairingKey(missingFinding, parsed.hash))?.shift();
|
|
263
|
-
if (candidate === void 0) continue;
|
|
264
|
-
consumed.add(missingFinding.issue);
|
|
265
|
-
consumed.add(candidate.issue);
|
|
266
|
-
calls.push(new RenameConstraintCall(emissionSchema(missingFinding.ddlSchema), missingFinding.tableName, "checkConstraint", candidate.node.name, missingFinding.node.name));
|
|
267
|
-
}
|
|
268
|
-
return {
|
|
269
|
-
calls,
|
|
270
|
-
consumed
|
|
271
|
-
};
|
|
272
|
-
}
|
|
273
|
-
function renamedMarker(marker, rename) {
|
|
274
|
-
if (!(marker instanceof PostgresRlsEnablement) || marker.tableName !== rename.from) return marker;
|
|
275
|
-
return new PostgresRlsEnablement({
|
|
276
|
-
tableName: rename.to,
|
|
277
|
-
namespaceId: marker.namespaceId
|
|
278
|
-
});
|
|
279
|
-
}
|
|
280
|
-
function renamedPolicy(policy, rename) {
|
|
281
|
-
if (!(policy instanceof PostgresRlsPolicy) || policy.tableName !== rename.from) return policy;
|
|
282
|
-
return new PostgresRlsPolicy({
|
|
283
|
-
naming: namingOf(policy.name, policy.prefix),
|
|
284
|
-
tableName: rename.to,
|
|
285
|
-
namespaceId: policy.namespaceId,
|
|
286
|
-
operation: policy.operation,
|
|
287
|
-
roles: policy.roles,
|
|
288
|
-
using: policy.using,
|
|
289
|
-
withCheck: policy.withCheck,
|
|
290
|
-
permissive: policy.permissive
|
|
291
|
-
});
|
|
292
|
-
}
|
|
293
|
-
/**
|
|
294
|
-
* Moves the RLS marker and the policies of a renamed table onto its new name. The marker is keyed by table name; policies are keyed by their own name and only their `tableName` changes. Policy names do not derive from the table name, so none is renamed.
|
|
295
|
-
*/
|
|
296
|
-
function renameRlsReferences(entries, rename) {
|
|
297
|
-
const markers = entries["rls"];
|
|
298
|
-
const policies = entries["policy"];
|
|
299
|
-
return {
|
|
300
|
-
...entries,
|
|
301
|
-
...markers === void 0 ? {} : { rls: Object.fromEntries(Object.entries(markers).map(([tableName, marker]) => [tableName === rename.from ? rename.to : tableName, renamedMarker(marker, rename)])) },
|
|
302
|
-
...policies === void 0 ? {} : { policy: Object.fromEntries(Object.entries(policies).map(([name, policy]) => [name, renamedPolicy(policy, rename)])) }
|
|
303
|
-
};
|
|
304
|
-
}
|
|
305
|
-
const RENAME_POLICY = { allowedOperationClasses: ["widening"] };
|
|
306
|
-
function emissionSchemaForNamespace(contract, namespaceId) {
|
|
307
|
-
return namespaceId === UNBOUND_NAMESPACE_ID ? UNBOUND_NAMESPACE_ID : resolveDdlSchemaForNamespaceStorage(contract.storage, namespaceId);
|
|
308
|
-
}
|
|
309
|
-
function renamedTableNode(schema, contract, rename) {
|
|
310
|
-
const ddlSchema = resolveDdlSchemaForNamespaceStorage(contract.storage, rename.namespaceId);
|
|
311
|
-
const table = Object.values(schema.namespaces).find((namespace) => namespace.schemaName === ddlSchema)?.tables[rename.to];
|
|
312
|
-
assertDefined(table, `a resolved rename names table "${rename.to}" in schema "${ddlSchema}"`);
|
|
313
|
-
return table;
|
|
314
|
-
}
|
|
315
|
-
/**
|
|
316
|
-
* The calls a migration's `renameTable` emits: the table rename, then a rename of each primary key, unique constraint and foreign key the start contract left unnamed, and of each wire-named index and check whose prefix derives from the table name. Only objects the end contract leaves otherwise unchanged are renamed; a constraint takes the end contract's stated name, or the name derived from the new table name. Throws `MIGRATION.TABLE_RENAME_UNMATCHED` when the start contract lacks the table or the end contract lacks the new name.
|
|
317
|
-
*/
|
|
318
|
-
function postgresTableRenameCalls(input) {
|
|
319
|
-
const applied = applyTableRename({
|
|
320
|
-
startContract: input.startContract,
|
|
321
|
-
endContract: input.endContract,
|
|
322
|
-
rename: input.rename,
|
|
323
|
-
renameTableReferences: renameRlsReferences
|
|
324
|
-
});
|
|
325
|
-
if (!applied.ok) throw applied.failure;
|
|
326
|
-
const { rename } = applied.value;
|
|
327
|
-
const contract = input.endContract;
|
|
328
|
-
const schemaName = emissionSchemaForNamespace(contract, rename.namespaceId);
|
|
329
|
-
const previousSchema = postgresContractToSchema(applied.value.contract, input.frameworkComponents);
|
|
330
|
-
const nextSchema = postgresContractToSchema(contract, input.frameworkComponents);
|
|
331
|
-
const { issues } = buildPostgresPlanDiff({
|
|
332
|
-
contract,
|
|
333
|
-
actualSchema: previousSchema,
|
|
334
|
-
frameworkComponents: input.frameworkComponents
|
|
335
|
-
});
|
|
336
|
-
const onRenamedTable = (call) => call.schemaName === schemaName && call.tableName === rename.to;
|
|
337
|
-
const pairing = {
|
|
338
|
-
contract,
|
|
339
|
-
policy: RENAME_POLICY
|
|
340
|
-
};
|
|
341
|
-
return [
|
|
342
|
-
new RenameTableCall(schemaName, rename.from, rename.to),
|
|
343
|
-
...constraintNameRenames({
|
|
344
|
-
schemaName,
|
|
345
|
-
from: rename.from,
|
|
346
|
-
to: rename.to,
|
|
347
|
-
previous: renamedTableNode(previousSchema, contract, rename),
|
|
348
|
-
next: renamedTableNode(nextSchema, contract, rename)
|
|
349
|
-
}),
|
|
350
|
-
...pairIndexRenames(pairing, issues).calls.filter(onRenamedTable),
|
|
351
|
-
...pairCheckRenames(pairing, issues).calls.filter(onRenamedTable)
|
|
352
|
-
];
|
|
353
|
-
}
|
|
354
|
-
/**
|
|
355
|
-
* Target-owned base class for Postgres migrations.
|
|
356
|
-
*
|
|
357
|
-
* Fixes the `SqlMigration` generic to `PostgresPlanTargetDetails` and the
|
|
358
|
-
* abstract `targetId` to the Postgres target-id string literal, so both
|
|
359
|
-
* user-authored migrations and renderer-generated scaffolds (the output of
|
|
360
|
-
* `renderCallsToTypeScript`) can extend `PostgresMigration` directly without
|
|
361
|
-
* redeclaring target-local identity.
|
|
362
|
-
*
|
|
363
|
-
* Mirrors `MongoMigration` in `@internal/family-mongo`: the renderer
|
|
364
|
-
* emits `extends Migration` against a facade re-export of this class
|
|
365
|
-
* from `@internal/postgres/migration`, keeping the authoring surface
|
|
366
|
-
* target-scoped rather than family-scoped.
|
|
367
|
-
*
|
|
368
|
-
* The constructor materializes a single Postgres `SqlControlAdapter` from
|
|
369
|
-
* `stack.adapter.create(stack)` and stores it; the protected `dataTransform`
|
|
370
|
-
* instance method forwards to the free `dataTransform` factory with that
|
|
371
|
-
* stored adapter, so user migrations can write `this.dataTransform(...)`
|
|
372
|
-
* without threading the adapter through every call.
|
|
373
|
-
*
|
|
374
|
-
* Every method requires an explicit `schema`. Postgres migrations name their
|
|
375
|
-
* schema deliberately — there is no default and no `search_path`-relative
|
|
376
|
-
* option. A migration that left the schema unspecified would resolve against
|
|
377
|
-
* whatever `search_path` the connection happened to carry, and that ambiguity
|
|
378
|
-
* is an antipattern in a migration. (The unbound/unspecified namespace concept
|
|
379
|
-
* remains for SQLite, which has no schemas, and for Mongo's connection `db`.)
|
|
380
|
-
*/
|
|
381
|
-
var PostgresMigration = class extends Migration {
|
|
382
|
-
targetId = "postgres";
|
|
383
|
-
/**
|
|
384
|
-
* Materialized Postgres control adapter, created once per migration
|
|
385
|
-
* instance from the injected stack. `undefined` only when the migration
|
|
386
|
-
* was instantiated without a stack (test fixtures); `controlAdapterFor`
|
|
387
|
-
* throws a MIGRATION.POSTGRES_CONTROL_STACK_MISSING in that case to surface the misuse.
|
|
388
|
-
*/
|
|
389
|
-
controlAdapter;
|
|
390
|
-
#endView = new MigrationContractViews(this, "PostgresMigration", (json) => PostgresContractView.fromJson(json));
|
|
391
|
-
#startView = new MigrationContractViews(this, "PostgresMigration", (json) => PostgresContractView.fromJson(json));
|
|
392
|
-
constructor(stack) {
|
|
393
|
-
super(stack);
|
|
394
|
-
this.controlAdapter = stack?.adapter ? blindCast(stack.adapter.create(stack)) : void 0;
|
|
395
|
-
}
|
|
396
|
-
frameworkComponents() {
|
|
397
|
-
const stack = this.stack;
|
|
398
|
-
if (stack === void 0) return [];
|
|
399
|
-
return [
|
|
400
|
-
stack.target,
|
|
401
|
-
...stack.adapter === void 0 ? [] : [stack.adapter],
|
|
402
|
-
...stack.extensions
|
|
403
|
-
];
|
|
404
|
-
}
|
|
405
|
-
/**
|
|
406
|
-
* Returns the materialized control adapter, or throws a MIGRATION.POSTGRES_CONTROL_STACK_MISSING naming
|
|
407
|
-
* `operation` when the migration was constructed without a `ControlStack`.
|
|
408
|
-
* Single home for the null-check that every DDL/DML method shares.
|
|
409
|
-
*/
|
|
410
|
-
controlAdapterFor(operation) {
|
|
411
|
-
if (!this.controlAdapter) throw errorPostgresMigrationStackMissing(operation);
|
|
412
|
-
return this.controlAdapter;
|
|
413
|
-
}
|
|
414
|
-
/**
|
|
415
|
-
* The typed, schema-qualified Postgres view over this migration's end-state
|
|
416
|
-
* contract — `this.endContract.namespace.<schema>.table.<name>`, etc. Throws
|
|
417
|
-
* if no `endContractJson` was provided.
|
|
418
|
-
*/
|
|
419
|
-
get endContract() {
|
|
420
|
-
return this.#endView.endContract;
|
|
421
|
-
}
|
|
422
|
-
/**
|
|
423
|
-
* The typed Postgres view over this migration's start-state contract, or
|
|
424
|
-
* `null` for a baseline migration (no `startContractJson`).
|
|
425
|
-
*/
|
|
426
|
-
get startContract() {
|
|
427
|
-
return this.#startView.startContract;
|
|
428
|
-
}
|
|
429
|
-
/**
|
|
430
|
-
* Instance-method wrapper around the free `dataTransform` factory that
|
|
431
|
-
* supplies the stored control adapter. Authors call this from inside
|
|
432
|
-
* `get operations()`; the adapter argument is hidden from the call site.
|
|
433
|
-
*/
|
|
434
|
-
dataTransform(contract, name, options) {
|
|
435
|
-
return dataTransform(contract, name, options, this.controlAdapterFor("dataTransform"));
|
|
436
|
-
}
|
|
437
|
-
/**
|
|
438
|
-
* Emit a `CREATE TABLE` migration operation. Builds a typed DDL node from
|
|
439
|
-
* the supplied options and lowers it through the stored control adapter.
|
|
440
|
-
* Throws if no adapter is present (i.e. migration instantiated without a stack).
|
|
441
|
-
*/
|
|
442
|
-
createTable(options) {
|
|
443
|
-
return new CreateTableCall(options.schema, options.table, options.columns, options.constraints).toOp(this.controlAdapterFor("createTable"));
|
|
444
|
-
}
|
|
445
|
-
/**
|
|
446
|
-
* Emit a `CREATE SCHEMA` migration operation. Builds a typed DDL node from
|
|
447
|
-
* the supplied options and lowers it through the stored control adapter.
|
|
448
|
-
* Throws if no adapter is present (i.e. migration instantiated without a stack).
|
|
449
|
-
*/
|
|
450
|
-
createSchema(options) {
|
|
451
|
-
return new CreateSchemaCall(options.schema).toOp(this.controlAdapterFor("createSchema"));
|
|
452
|
-
}
|
|
453
|
-
/**
|
|
454
|
-
* Emit a `CREATE TYPE ... AS ENUM (...)` migration operation for a managed
|
|
455
|
-
* native enum. Builds a typed DDL node and lowers it through the stored
|
|
456
|
-
* control adapter (members render in declaration order). Throws if no adapter
|
|
457
|
-
* is present.
|
|
458
|
-
*/
|
|
459
|
-
createNativeEnumType(options) {
|
|
460
|
-
return new CreateNativeEnumTypeCall(options.schema, options.typeName, options.members).toOp(this.controlAdapterFor("createNativeEnumType"));
|
|
461
|
-
}
|
|
462
|
-
/**
|
|
463
|
-
* Emit a `DROP TYPE` migration operation for a managed native enum, lowered
|
|
464
|
-
* through the stored control adapter. Throws if no adapter is present.
|
|
465
|
-
*/
|
|
466
|
-
dropNativeEnumType(options) {
|
|
467
|
-
return new DropNativeEnumTypeCall(options.schema, options.typeName).toOp(this.controlAdapterFor("dropNativeEnumType"));
|
|
468
|
-
}
|
|
469
|
-
/**
|
|
470
|
-
* Emit an `ALTER TYPE ... ADD VALUE` migration operation appending one
|
|
471
|
-
* member to a managed native enum, lowered through the stored control
|
|
472
|
-
* adapter. Throws if no adapter is present. Every appended value is its
|
|
473
|
-
* own operation — call this once per value to append more than one.
|
|
474
|
-
*/
|
|
475
|
-
addNativeEnumValue(options) {
|
|
476
|
-
return new AddNativeEnumValueCall(options.schema, options.typeName, options.value).toOp(this.controlAdapterFor("addNativeEnumValue"));
|
|
477
|
-
}
|
|
478
|
-
addColumn(options) {
|
|
479
|
-
return new AddColumnCall(options.schema, options.table, options.column).toOp(this.controlAdapterFor("addColumn"));
|
|
480
|
-
}
|
|
481
|
-
addPrimaryKey(options) {
|
|
482
|
-
return new AddPrimaryKeyCall(options.schema, options.table, options.constraint, options.columns).toOp(this.controlAdapterFor("addPrimaryKey"));
|
|
483
|
-
}
|
|
484
|
-
addUnique(options) {
|
|
485
|
-
return new AddUniqueCall(options.schema, options.table, options.constraint, options.columns).toOp(this.controlAdapterFor("addUnique"));
|
|
486
|
-
}
|
|
487
|
-
addForeignKey(options) {
|
|
488
|
-
return new AddForeignKeyCall(options.schema, options.table, options.foreignKey).toOp(this.controlAdapterFor("addForeignKey"));
|
|
489
|
-
}
|
|
490
|
-
addCheckConstraint(options) {
|
|
491
|
-
return new AddCheckConstraintCall(options.schema, options.table, options.constraint, options.expression).toOp(this.controlAdapterFor("addCheckConstraint"));
|
|
492
|
-
}
|
|
493
|
-
renameCheckConstraint(options) {
|
|
494
|
-
return this.renameConstraint({
|
|
495
|
-
...options,
|
|
496
|
-
kind: "checkConstraint"
|
|
497
|
-
});
|
|
498
|
-
}
|
|
499
|
-
renameConstraint(options) {
|
|
500
|
-
return new RenameConstraintCall(options.schema ?? UNBOUND_NAMESPACE_ID, options.table, options.kind, options.from, options.to).toOp(this.controlAdapterFor("renameConstraint"));
|
|
501
|
-
}
|
|
502
|
-
dropCheckConstraint(options) {
|
|
503
|
-
return new DropCheckConstraintCall(options.schema, options.table, options.constraint).toOp(this.controlAdapterFor("dropCheckConstraint"));
|
|
504
|
-
}
|
|
505
|
-
dropConstraint(options) {
|
|
506
|
-
return new DropConstraintCall(options.schema, options.table, options.constraint, options.kind ?? "unique").toOp(this.controlAdapterFor("dropConstraint"));
|
|
507
|
-
}
|
|
508
|
-
/**
|
|
509
|
-
* Emit the operations that rename a table: the table rename, then a rename of each primary key, unique constraint, foreign key, index and check whose name was derived from the old table name, read from this migration's start and end contracts. Spread the result into `operations`: `...this.renameTable({ table: 'userProfile', to: 'UserProfile' })`. `schema` names the table's namespace when more than one declares the table. Throws `MIGRATION.TABLE_RENAME_UNMATCHED` when the start contract lacks the table or the end contract lacks the new name.
|
|
510
|
-
*/
|
|
511
|
-
renameTable(options) {
|
|
512
|
-
const adapter = this.controlAdapterFor("renameTable");
|
|
513
|
-
return postgresTableRenameCalls({
|
|
514
|
-
startContract: this.startContract,
|
|
515
|
-
endContract: this.endContract,
|
|
516
|
-
rename: {
|
|
517
|
-
namespaceId: options.schema,
|
|
518
|
-
from: options.table,
|
|
519
|
-
to: options.to
|
|
520
|
-
},
|
|
521
|
-
frameworkComponents: this.frameworkComponents()
|
|
522
|
-
}).map(async (call) => call.toOp(adapter));
|
|
523
|
-
}
|
|
524
|
-
dropTable(options) {
|
|
525
|
-
return new DropTableCall(options.schema, options.table).toOp(this.controlAdapterFor("dropTable"));
|
|
526
|
-
}
|
|
527
|
-
dropColumn(options) {
|
|
528
|
-
return new DropColumnCall(options.schema, options.table, options.column).toOp(this.controlAdapterFor("dropColumn"));
|
|
529
|
-
}
|
|
530
|
-
alterColumnType(options) {
|
|
531
|
-
return new AlterColumnTypeCall(options.schema, options.table, options.column, options.options).toOp(this.controlAdapterFor("alterColumnType"));
|
|
532
|
-
}
|
|
533
|
-
setNotNull(options) {
|
|
534
|
-
return new SetNotNullCall(options.schema, options.table, options.column).toOp(this.controlAdapterFor("setNotNull"));
|
|
535
|
-
}
|
|
536
|
-
dropNotNull(options) {
|
|
537
|
-
return new DropNotNullCall(options.schema, options.table, options.column).toOp(this.controlAdapterFor("dropNotNull"));
|
|
538
|
-
}
|
|
539
|
-
setDefault(options) {
|
|
540
|
-
refuseEarlierSetDefaultOptions(options);
|
|
541
|
-
return new SetDefaultCall(options.schema, options.table, options.column, options.operationClass).toOp(this.controlAdapterFor("setDefault"));
|
|
542
|
-
}
|
|
543
|
-
dropDefault(options) {
|
|
544
|
-
return new DropDefaultCall(options.schema, options.table, options.column).toOp(this.controlAdapterFor("dropDefault"));
|
|
545
|
-
}
|
|
546
|
-
createIndex(options) {
|
|
547
|
-
return new CreateIndexCall(options.schema, options.table, options.index, options.columns !== void 0 ? { columns: options.columns } : { expression: options.expression }, options.extras).toOp(this.controlAdapterFor("createIndex"));
|
|
548
|
-
}
|
|
549
|
-
renameIndex(options) {
|
|
550
|
-
return new RenameIndexCall(options.schema, options.table, options.from, options.to).toOp(this.controlAdapterFor("renameIndex"));
|
|
551
|
-
}
|
|
552
|
-
dropIndex(options) {
|
|
553
|
-
return new DropIndexCall(options.schema, options.table, options.index).toOp(this.controlAdapterFor("dropIndex"));
|
|
554
|
-
}
|
|
555
|
-
installExtension(options) {
|
|
556
|
-
return installExtension(options, this.controlAdapterFor("installExtension"));
|
|
557
|
-
}
|
|
558
|
-
enableRowLevelSecurity(options) {
|
|
559
|
-
return new EnableRowLevelSecurityCall(options.schema, options.table).toOp(this.controlAdapterFor("enableRowLevelSecurity"));
|
|
560
|
-
}
|
|
561
|
-
disableRowLevelSecurity(options) {
|
|
562
|
-
return new DisableRowLevelSecurityCall(options.schema, options.table).toOp(this.controlAdapterFor("disableRowLevelSecurity"));
|
|
563
|
-
}
|
|
564
|
-
createRlsPolicy(options) {
|
|
565
|
-
return new CreatePostgresRlsPolicyCall(options.schema, options.table, new PostgresRlsPolicy({
|
|
566
|
-
...options.policy,
|
|
567
|
-
using: options.policy.using,
|
|
568
|
-
withCheck: options.policy.withCheck
|
|
569
|
-
})).toOp(this.controlAdapterFor("createRlsPolicy"));
|
|
570
|
-
}
|
|
571
|
-
dropRlsPolicy(options) {
|
|
572
|
-
return new DropPostgresRlsPolicyCall(options.schema, options.table, options.policy).toOp(this.controlAdapterFor("dropRlsPolicy"));
|
|
573
|
-
}
|
|
574
|
-
renameRlsPolicy(options) {
|
|
575
|
-
return new RenamePostgresRlsPolicyCall(options.schema, options.table, options.from, options.to).toOp(this.controlAdapterFor("renameRlsPolicy"));
|
|
576
|
-
}
|
|
577
|
-
};
|
|
578
|
-
/**
|
|
579
|
-
* `setDefault` options an earlier version wrote carry the column's name in `column` and its default as SQL text in `defaultSql`.
|
|
580
|
-
*/
|
|
581
|
-
function refuseEarlierSetDefaultOptions(options) {
|
|
582
|
-
const column = options.column;
|
|
583
|
-
const columnIsName = typeof column === "string";
|
|
584
|
-
if (!columnIsName && !Object.hasOwn(options, "defaultSql")) return;
|
|
585
|
-
throw errorMigrationOperationOptionRemoved({
|
|
586
|
-
operation: "setDefault",
|
|
587
|
-
option: "defaultSql",
|
|
588
|
-
subject: `column ${JSON.stringify(columnIsName ? column : options.column.name)} of table ${JSON.stringify(options.table)}`,
|
|
589
|
-
rewrite: "Pass the column as `col(name, type, { default, codecRef })`, with its default written as `lit(value)` or `fn(expression)`, in place of its name and `defaultSql`.",
|
|
590
|
-
upgradeEntry: "migration-ts-column-defaults"
|
|
591
|
-
});
|
|
592
|
-
}
|
|
593
|
-
//#endregion
|
|
594
|
-
export { plannedConstraintNameRenames as a, pairIndexRenames as i, emissionSchemaForNamespace as n, postgresContractToSchema as o, pairCheckRenames as r, postgresRenderDefault as s, PostgresMigration as t };
|
|
595
|
-
|
|
596
|
-
//# sourceMappingURL=postgres-migration-CeX6vfEU-DsmCRCnD.mjs.map
|