@prisma/orm-target-postgres 8.0.0-rc.11-dev.16 → 8.0.0-rc.11-dev.17
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-DDfZMW0M-Cqq4b6_G.mjs → adapter-bTD1EPrl-DQ66tQwz.mjs} +3 -3
- package/dist/{adapter-DDfZMW0M-Cqq4b6_G.mjs.map → adapter-bTD1EPrl-DQ66tQwz.mjs.map} +1 -1
- package/dist/adapter.d.mts +2 -2
- package/dist/adapter.mjs +3 -3
- package/dist/adapter__adapter.mjs +1 -1
- package/dist/adapter__control.d.mts +2 -2
- package/dist/adapter__control.mjs +5 -4
- package/dist/adapter__control.mjs.map +1 -1
- package/dist/adapter__runtime.mjs +8 -3
- package/dist/adapter__runtime.mjs.map +1 -1
- package/dist/{authoring-DgeWf8RC-C-jQzf_w.mjs → authoring-Beq66XGy-D-GgvlBG.mjs} +63 -20
- package/dist/authoring-Beq66XGy-D-GgvlBG.mjs.map +1 -0
- package/dist/authoring-xyQRYoem-DWCGb5Py.d.mts +36 -0
- package/dist/authoring-xyQRYoem-DWCGb5Py.d.mts.map +1 -0
- package/dist/control-206OMpyA.mjs +470 -0
- package/dist/control-206OMpyA.mjs.map +1 -0
- package/dist/{control--T7XaMS8.d.mts → control-BvK2pHHh.d.mts} +2 -2
- package/dist/{control--T7XaMS8.d.mts.map → control-BvK2pHHh.d.mts.map} +1 -1
- package/dist/{control-xdW1bgaP.d.mts → control-DmVutloY.d.mts} +2 -2
- package/dist/{control-xdW1bgaP.d.mts.map → control-DmVutloY.d.mts.map} +1 -1
- package/dist/{control-adapter-5et6pVM9-B5CKg-5B.mjs → control-adapter-Bdz-Xa1p-rKiOVhsh.mjs} +96 -28
- package/dist/control-adapter-Bdz-Xa1p-rKiOVhsh.mjs.map +1 -0
- package/dist/{control-policy-BKgU_M65-BWedWA-f.mjs → control-policy-B8x7UxGf-BjTez7am.mjs} +24 -17
- package/dist/control-policy-B8x7UxGf-BjTez7am.mjs.map +1 -0
- package/dist/{default-normalizer-Ba5ZebHM-isV86rjy.mjs → default-normalizer-Bjtm2F4f-uV5vvkVt.mjs} +160 -33
- package/dist/default-normalizer-Bjtm2F4f-uV5vvkVt.mjs.map +1 -0
- package/dist/{default-normalizer-B36TOul4.d.mts → default-normalizer-D9WbKo20.d.mts} +2 -2
- package/dist/{default-normalizer-B36TOul4.d.mts.map → default-normalizer-D9WbKo20.d.mts.map} +1 -1
- package/dist/{descriptor-meta-C4i4pLQn-CmdN74uG.mjs → descriptor-meta-BhJOswpM-CqvnQMC0.mjs} +3 -3
- package/dist/{descriptor-meta-C4i4pLQn-CmdN74uG.mjs.map → descriptor-meta-BhJOswpM-CqvnQMC0.mjs.map} +1 -1
- package/dist/{diff-database-schema-BaSP2z4y-Ch42uw-j.mjs → diff-database-schema-BFX0ZWWK-KVfAPOLF.mjs} +4 -4
- package/dist/{diff-database-schema-BaSP2z4y-Ch42uw-j.mjs.map → diff-database-schema-BFX0ZWWK-KVfAPOLF.mjs.map} +1 -1
- package/dist/{control-BC3oXXIK.mjs → infer-psl-contract-BaZaJAD9-DTVu5Zab.mjs} +110 -488
- package/dist/infer-psl-contract-BaZaJAD9-DTVu5Zab.mjs.map +1 -0
- package/dist/migration-PTHAY9Cv.mjs.map +1 -1
- package/dist/{op-factory-call-6Jg-ycA--4AC_11Od.mjs → op-factory-call-B3-CevCo-CSV5SL9W.mjs} +3 -3
- package/dist/{op-factory-call-6Jg-ycA--4AC_11Od.mjs.map → op-factory-call-B3-CevCo-CSV5SL9W.mjs.map} +1 -1
- package/dist/{pack-D8V-43m8.d.mts → pack-CRA_2QjF.d.mts} +8 -38
- package/dist/pack-CRA_2QjF.d.mts.map +1 -0
- package/dist/plain-date-time-now-generator-DJ3icyVr-B-rdIVd3.d.mts +23 -0
- package/dist/plain-date-time-now-generator-DJ3icyVr-B-rdIVd3.d.mts.map +1 -0
- package/dist/{planner-C70Loeo_-qHTNBO3Q.mjs → planner-D_VBDqX0-C2jCXuIt.mjs} +6 -6
- package/dist/{planner-C70Loeo_-qHTNBO3Q.mjs.map → planner-D_VBDqX0-C2jCXuIt.mjs.map} +1 -1
- package/dist/{planner-ddl-builders-Cf6-fTvi-CKp-yZkB.mjs → planner-ddl-builders-CpXQ-J0X-CL5gNUSG.mjs} +14 -5
- package/dist/{planner-ddl-builders-Cf6-fTvi-CKp-yZkB.mjs.map → planner-ddl-builders-CpXQ-J0X-CL5gNUSG.mjs.map} +1 -1
- package/dist/{planner-ddl-builders-ijp60-JO.d.mts → planner-ddl-builders-bBCUsq_0.d.mts} +2 -2
- package/dist/planner-ddl-builders-bBCUsq_0.d.mts.map +1 -0
- package/dist/{planner-produced-postgres-migration-ButAgK7L-CZXweEva.mjs → planner-produced-postgres-migration-DwcW5RrQ-D0DPBmoS.mjs} +3 -3
- package/dist/{planner-produced-postgres-migration-ButAgK7L-CZXweEva.mjs.map → planner-produced-postgres-migration-DwcW5RrQ-D0DPBmoS.mjs.map} +1 -1
- package/dist/{postgres-contract-view-C22aDeL9-BWJIOpCz.mjs → postgres-contract-view-D7tYWHwD-DJNOh9Qo.mjs} +3 -3
- package/dist/{postgres-contract-view-C22aDeL9-BWJIOpCz.mjs.map → postgres-contract-view-D7tYWHwD-DJNOh9Qo.mjs.map} +1 -1
- package/dist/{postgres-migration-Cj-DvDY8-CIrWHp9I.mjs → postgres-migration-DXHNRgZA-HzAql-Bj.mjs} +4 -4
- package/dist/{postgres-migration-Cj-DvDY8-CIrWHp9I.mjs.map → postgres-migration-DXHNRgZA-HzAql-Bj.mjs.map} +1 -1
- package/dist/prisma7-binding-C38o_ABR.d.mts +1012 -0
- package/dist/prisma7-binding-C38o_ABR.d.mts.map +1 -0
- package/dist/prisma7-binding-DjpSw5G6.mjs +331 -0
- package/dist/prisma7-binding-DjpSw5G6.mjs.map +1 -0
- package/dist/{runtime-CpeP58Y6.d.mts → runtime-BRbiY5Vj.d.mts} +2 -2
- package/dist/{runtime-CpeP58Y6.d.mts.map → runtime-BRbiY5Vj.d.mts.map} +1 -1
- package/dist/target.d.mts +8 -7
- package/dist/target.mjs +13 -12
- package/dist/target__control.d.mts +3 -3
- package/dist/target__control.mjs +3 -3
- package/dist/target__default-normalizer.d.mts +1 -1
- package/dist/target__default-normalizer.mjs +1 -1
- package/dist/target__diff-database-schema.mjs +1 -1
- package/dist/target__issue-planner.mjs +1 -1
- package/dist/target__migration.mjs +2 -2
- package/dist/target__op-factory-call.mjs +1 -1
- package/dist/target__pack.d.mts +1 -1
- package/dist/target__pack.mjs +1 -1
- package/dist/target__planner-ddl-builders.d.mts +1 -1
- package/dist/target__planner-ddl-builders.mjs +1 -1
- package/dist/target__planner-produced-postgres-migration.mjs +1 -1
- package/dist/target__planner.mjs +2 -2
- package/dist/target__prisma7-binding.d.mts +2 -0
- package/dist/target__prisma7-binding.mjs +2 -0
- package/dist/target__runtime.d.mts +3 -3
- package/dist/target__runtime.mjs +3 -3
- package/dist/target__runtime.mjs.map +1 -1
- package/package.json +10 -9
- package/dist/authoring-DgeWf8RC-C-jQzf_w.mjs.map +0 -1
- package/dist/control-BC3oXXIK.mjs.map +0 -1
- package/dist/control-adapter-5et6pVM9-B5CKg-5B.mjs.map +0 -1
- package/dist/control-policy-BKgU_M65-BWedWA-f.mjs.map +0 -1
- package/dist/default-normalizer-Ba5ZebHM-isV86rjy.mjs.map +0 -1
- package/dist/list-decoder-8mZBUNe0-C9dPXUP0.d.mts +0 -13
- package/dist/list-decoder-8mZBUNe0-C9dPXUP0.d.mts.map +0 -1
- package/dist/pack-D8V-43m8.d.mts.map +0 -1
- package/dist/planner-ddl-builders-ijp60-JO.d.mts.map +0 -1
|
@@ -1,420 +1,16 @@
|
|
|
1
1
|
import { s as postgresError } from "./errors-DYyzTYzE-39CV_aMo.mjs";
|
|
2
|
-
import {
|
|
2
|
+
import { t as parsePostgresDefault } from "./default-normalizer-Bjtm2F4f-uV5vvkVt.mjs";
|
|
3
3
|
import { t as postgresRenderCheckExpressions } from "./check-expressions-DFTeR0rd-CSxSpyMV.mjs";
|
|
4
|
-
import { t as postgresTargetDescriptorMeta } from "./descriptor-meta-C4i4pLQn-CmdN74uG.mjs";
|
|
5
|
-
import { a as postgresDiffSubjectGranularity, i as postgresDiffSubjectEntityKind } from "./postgres-table-schema-node-BBkitBQh-DT1T5VWU.mjs";
|
|
6
|
-
import { t as PostgresDatabaseSchemaNode } from "./postgres-role-schema-node-B8Z5i5D--PObwlU2Z.mjs";
|
|
7
|
-
import { r as renderDefaultLiteral } from "./planner-ddl-builders-Cf6-fTvi-CKp-yZkB.mjs";
|
|
8
|
-
import { n as contractToPostgresDatabaseSchemaNode, r as diffPostgresSchema } from "./diff-database-schema-BaSP2z4y-Ch42uw-j.mjs";
|
|
9
|
-
import { t as PostgresContractSerializer } from "./postgres-contract-view-C22aDeL9-BWJIOpCz.mjs";
|
|
10
|
-
import { t as createPostgresMigrationPlanner } from "./planner-C70Loeo_-qHTNBO3Q.mjs";
|
|
11
4
|
import { blindCast } from "@prisma/orm-framework/utils/casts";
|
|
12
|
-
import {
|
|
5
|
+
import { coordinateKey, elementCoordinates } from "@prisma/orm-framework/components/ir";
|
|
13
6
|
import { ifDefined } from "@prisma/orm-framework/utils/defined";
|
|
14
7
|
import { composeCheckWirePrefix, computeCheckContentHash, computeIndexContentHash, formatWireName, parseWireName } from "@prisma/orm-family-sql/schema-ir/naming";
|
|
15
8
|
import { assertDefined } from "@prisma/orm-framework/utils/assertions";
|
|
16
|
-
import { APP_SPACE_ID } from "@prisma/orm-framework/components/control";
|
|
17
|
-
import { buildNativeTypeExpander, runnerFailure, runnerSuccess } from "@prisma/orm-family-sql/family/control";
|
|
18
9
|
import { SqlSchemaIR, SqlTableIR } from "@prisma/orm-family-sql/schema-ir/types";
|
|
19
|
-
import {
|
|
20
|
-
import { notOk, ok, okVoid } from "@prisma/orm-framework/utils/result";
|
|
21
|
-
import { SqlSchemaVerifierBase } from "@prisma/orm-family-sql/family/ir";
|
|
22
|
-
import { SqlQueryError } from "@prisma/orm-family-sql/errors";
|
|
23
|
-
import { buildChildRelationField, deriveRelationFieldName, inferRelations, mapDefault, parseRawDefault, toEnumMemberName, toEnumName, toFieldName, toModelName } from "@prisma/orm-family-sql/family/psl-infer";
|
|
10
|
+
import { buildChildRelationField, deriveRelationFieldName, inferRelations, mapDefault, toEnumMemberName, toEnumName, toFieldName, toModelName } from "@prisma/orm-family-sql/family/psl-infer";
|
|
24
11
|
import { UNSPECIFIED_PSL_NAMESPACE_ID, makePslNamespace, makePslNamespaceEntries } from "@prisma/orm-framework/components/psl-ast";
|
|
25
12
|
import { isColumnDefault } from "@prisma/orm-framework/contract/types";
|
|
26
|
-
//#region ../../../3-targets/3-targets/postgres/dist/
|
|
27
|
-
const LOCK_DOMAIN = "prisma_8.contract.marker";
|
|
28
|
-
/**
|
|
29
|
-
* Deep clones and freezes a record object to prevent mutation.
|
|
30
|
-
* Recursively clones nested objects and arrays to ensure complete isolation.
|
|
31
|
-
*/
|
|
32
|
-
function cloneAndFreezeRecord(value) {
|
|
33
|
-
const cloned = {};
|
|
34
|
-
for (const [key, val] of Object.entries(value)) if (val === null || val === void 0) cloned[key] = val;
|
|
35
|
-
else if (Array.isArray(val)) cloned[key] = Object.freeze([...val]);
|
|
36
|
-
else if (typeof val === "object") cloned[key] = cloneAndFreezeRecord(val);
|
|
37
|
-
else cloned[key] = val;
|
|
38
|
-
return Object.freeze(cloned);
|
|
39
|
-
}
|
|
40
|
-
function createPostgresMigrationRunner(family) {
|
|
41
|
-
return new PostgresMigrationRunner(family);
|
|
42
|
-
}
|
|
43
|
-
var PostgresMigrationRunner = class {
|
|
44
|
-
family;
|
|
45
|
-
constructor(family) {
|
|
46
|
-
this.family = family;
|
|
47
|
-
}
|
|
48
|
-
/**
|
|
49
|
-
* Body of the migration runner without transaction management. The
|
|
50
|
-
* caller ({@link PostgresMigrationRunner.execute}) owns the
|
|
51
|
-
* `BEGIN`/`COMMIT`/`ROLLBACK` lifecycle.
|
|
52
|
-
*/
|
|
53
|
-
async executeOnConnection(options) {
|
|
54
|
-
const schema = options.schemaName ?? Object.keys(options.destinationContract.storage.namespaces).find((id) => id !== UNBOUND_NAMESPACE_ID) ?? UNBOUND_NAMESPACE_ID;
|
|
55
|
-
const driver = options.driver;
|
|
56
|
-
if (options.space !== void 0 && options.space !== options.plan.spaceId) throw postgresError("MIGRATION.CONTRACT_SPACE_VIOLATION", `SqlMigrationRunner: options.space (${options.space}) does not match plan.spaceId (${options.plan.spaceId})`, { meta: {
|
|
57
|
-
space: options.space,
|
|
58
|
-
planSpaceId: options.plan.spaceId
|
|
59
|
-
} });
|
|
60
|
-
const space = options.plan.spaceId;
|
|
61
|
-
const lockKey = `${LOCK_DOMAIN}:${schema}:${space}`;
|
|
62
|
-
const planOps = blindCast(await Promise.all(options.plan.operations));
|
|
63
|
-
const destinationCheck = this.ensurePlanMatchesDestinationContract(options.plan.destination, options.destinationContract);
|
|
64
|
-
if (!destinationCheck.ok) return destinationCheck;
|
|
65
|
-
const policyCheck = this.enforcePolicyCompatibility(options.policy, planOps);
|
|
66
|
-
if (!policyCheck.ok) return policyCheck;
|
|
67
|
-
await this.acquireLock(driver, lockKey);
|
|
68
|
-
const ensureResult = await this.ensureControlTables(driver, options.destinationContract);
|
|
69
|
-
if (!ensureResult.ok) return ensureResult;
|
|
70
|
-
const existingMarker = await this.family.readMarker({
|
|
71
|
-
driver,
|
|
72
|
-
space
|
|
73
|
-
});
|
|
74
|
-
const markerCheck = this.ensureMarkerCompatibility(existingMarker, options.plan);
|
|
75
|
-
if (!markerCheck.ok) return markerCheck;
|
|
76
|
-
const markerAtDestination = this.markerMatchesDestination(existingMarker, options.plan);
|
|
77
|
-
const isSelfEdge = options.plan.origin?.storageHash === options.plan.destination.storageHash;
|
|
78
|
-
const skipOperations = markerAtDestination && options.plan.origin != null && !isSelfEdge;
|
|
79
|
-
let applyValue;
|
|
80
|
-
if (skipOperations) applyValue = {
|
|
81
|
-
operationsExecuted: 0,
|
|
82
|
-
executedOperations: []
|
|
83
|
-
};
|
|
84
|
-
else {
|
|
85
|
-
const applyResult = await this.applyPlan(driver, options, planOps);
|
|
86
|
-
if (!applyResult.ok) return applyResult;
|
|
87
|
-
applyValue = applyResult.value;
|
|
88
|
-
}
|
|
89
|
-
if (space === APP_SPACE_ID) {
|
|
90
|
-
const schemaNode = await this.family.introspect({
|
|
91
|
-
driver,
|
|
92
|
-
contract: options.destinationContract
|
|
93
|
-
});
|
|
94
|
-
const schemaVerifyResult = this.family.verifySchema({
|
|
95
|
-
contract: options.destinationContract,
|
|
96
|
-
schema: schemaNode,
|
|
97
|
-
strict: options.strictVerification ?? true,
|
|
98
|
-
frameworkComponents: options.frameworkComponents
|
|
99
|
-
});
|
|
100
|
-
if (!schemaVerifyResult.ok) return runnerFailure("MIGRATION.SCHEMA_VERIFY_FAILED", schemaVerifyResult.summary, {
|
|
101
|
-
why: "The resulting database schema does not satisfy the destination contract.",
|
|
102
|
-
meta: { issues: schemaVerifyResult.schema.issues }
|
|
103
|
-
});
|
|
104
|
-
}
|
|
105
|
-
const incomingInvariants = options.plan.providedInvariants ?? [];
|
|
106
|
-
const existingInvariants = new Set(existingMarker?.invariants ?? []);
|
|
107
|
-
const incomingIsSubsetOfExisting = incomingInvariants.every((id) => existingInvariants.has(id));
|
|
108
|
-
if (!(isSelfEdge && applyValue.operationsExecuted === 0 && incomingIsSubsetOfExisting)) {
|
|
109
|
-
const markerResult = await this.upsertMarker(driver, options, existingMarker, space);
|
|
110
|
-
if (!markerResult.ok) return markerResult;
|
|
111
|
-
await this.recordLedgerEntries(driver, options, applyValue.executedOperations, planOps.length);
|
|
112
|
-
}
|
|
113
|
-
return runnerSuccess({
|
|
114
|
-
operationsPlanned: planOps.length,
|
|
115
|
-
operationsExecuted: applyValue.operationsExecuted
|
|
116
|
-
});
|
|
117
|
-
}
|
|
118
|
-
async execute(options) {
|
|
119
|
-
const driver = options.driver;
|
|
120
|
-
const perSpaceOptions = options.perSpaceOptions;
|
|
121
|
-
if (perSpaceOptions.length === 0) return ok({ perSpaceResults: [] });
|
|
122
|
-
await this.beginTransaction(driver);
|
|
123
|
-
let committed = false;
|
|
124
|
-
try {
|
|
125
|
-
const perSpaceResults = [];
|
|
126
|
-
for (const spaceOptions of perSpaceOptions) {
|
|
127
|
-
const space = spaceOptions.space ?? spaceOptions.plan.spaceId;
|
|
128
|
-
const result = await this.executeOnConnection({
|
|
129
|
-
...spaceOptions,
|
|
130
|
-
driver,
|
|
131
|
-
space
|
|
132
|
-
});
|
|
133
|
-
if (!result.ok) return notOk({
|
|
134
|
-
...result.failure,
|
|
135
|
-
failingSpace: space
|
|
136
|
-
});
|
|
137
|
-
perSpaceResults.push({
|
|
138
|
-
space,
|
|
139
|
-
value: result.value
|
|
140
|
-
});
|
|
141
|
-
}
|
|
142
|
-
await this.commitTransaction(driver);
|
|
143
|
-
committed = true;
|
|
144
|
-
return ok({ perSpaceResults });
|
|
145
|
-
} finally {
|
|
146
|
-
if (!committed) await this.rollbackTransaction(driver);
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
async applyPlan(driver, options, ops) {
|
|
150
|
-
const checks = options.executionChecks;
|
|
151
|
-
const runPrechecks = checks?.prechecks !== false;
|
|
152
|
-
const runPostchecks = checks?.postchecks !== false;
|
|
153
|
-
const runIdempotency = checks?.idempotencyChecks !== false;
|
|
154
|
-
let operationsExecuted = 0;
|
|
155
|
-
const executedOperations = [];
|
|
156
|
-
for (const operation of ops) {
|
|
157
|
-
options.callbacks?.onOperationStart?.(operation);
|
|
158
|
-
try {
|
|
159
|
-
if (runPostchecks && runIdempotency) {
|
|
160
|
-
if (await this.expectationsAreSatisfied(driver, operation.postcheck)) {
|
|
161
|
-
executedOperations.push(this.createPostcheckPreSatisfiedSkipRecord(operation));
|
|
162
|
-
continue;
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
if (runPrechecks) {
|
|
166
|
-
const precheckResult = await this.runExpectationSteps(driver, operation.precheck, operation, "precheck");
|
|
167
|
-
if (!precheckResult.ok) return precheckResult;
|
|
168
|
-
}
|
|
169
|
-
const executeResult = await this.runExecuteSteps(driver, operation.execute, operation);
|
|
170
|
-
if (!executeResult.ok) return executeResult;
|
|
171
|
-
if (runPostchecks) {
|
|
172
|
-
const postcheckResult = await this.runExpectationSteps(driver, operation.postcheck, operation, "postcheck");
|
|
173
|
-
if (!postcheckResult.ok) return postcheckResult;
|
|
174
|
-
}
|
|
175
|
-
executedOperations.push(operation);
|
|
176
|
-
operationsExecuted += 1;
|
|
177
|
-
} finally {
|
|
178
|
-
options.callbacks?.onOperationComplete?.(operation);
|
|
179
|
-
}
|
|
180
|
-
}
|
|
181
|
-
return ok({
|
|
182
|
-
operationsExecuted,
|
|
183
|
-
executedOperations
|
|
184
|
-
});
|
|
185
|
-
}
|
|
186
|
-
async ensureControlTables(driver, contract) {
|
|
187
|
-
const lowererContext = { contract };
|
|
188
|
-
const [schemaQuery, ...tableQueries] = this.family.bootstrapControlTableQueries();
|
|
189
|
-
if (schemaQuery === void 0) throw new InternalError("Postgres control-table bootstrap must include CREATE SCHEMA");
|
|
190
|
-
await this.executeStatement(driver, await this.family.lowerAst(schemaQuery, lowererContext));
|
|
191
|
-
const legacyDetection = await this.detectLegacyMarkerShape(driver);
|
|
192
|
-
if (!legacyDetection.ok) return legacyDetection;
|
|
193
|
-
for (const query of tableQueries) await this.executeStatement(driver, await this.family.lowerAst(query, lowererContext));
|
|
194
|
-
return okVoid();
|
|
195
|
-
}
|
|
196
|
-
async detectLegacyMarkerShape(driver) {
|
|
197
|
-
const result = await driver.query(`select column_name
|
|
198
|
-
from information_schema.columns
|
|
199
|
-
where table_schema = 'prisma_contract'
|
|
200
|
-
and table_name = 'marker'`);
|
|
201
|
-
if (result.rows.length === 0) return okVoid();
|
|
202
|
-
const columns = new Set(result.rows.map((row) => row.column_name));
|
|
203
|
-
if (columns.has("space")) return okVoid();
|
|
204
|
-
return runnerFailure("MIGRATION.LEGACY_MARKER_SHAPE", "Legacy marker-table shape detected on prisma_contract.marker (no `space` column). Prisma 8 is in pre-1.0; the previous transitional auto-migration to the per-space-row schema has been removed. Drop `prisma_contract.marker` and re-run `dbInit` to reinitialise from a clean baseline.", { meta: {
|
|
205
|
-
table: "prisma_contract.marker",
|
|
206
|
-
columns: [...columns].sort()
|
|
207
|
-
} });
|
|
208
|
-
}
|
|
209
|
-
async runExpectationSteps(driver, steps, operation, phase) {
|
|
210
|
-
for (const step of steps) {
|
|
211
|
-
const result = await driver.query(step.sql, step.params ?? []);
|
|
212
|
-
if (!this.stepResultIsTrue(result.rows)) return runnerFailure(phase === "precheck" ? "MIGRATION.PRECHECK_FAILED" : "MIGRATION.POSTCHECK_FAILED", `Operation ${operation.id} failed during ${phase}: ${step.description}`, { meta: {
|
|
213
|
-
operationId: operation.id,
|
|
214
|
-
phase,
|
|
215
|
-
stepDescription: step.description
|
|
216
|
-
} });
|
|
217
|
-
}
|
|
218
|
-
return okVoid();
|
|
219
|
-
}
|
|
220
|
-
async runExecuteSteps(driver, steps, operation) {
|
|
221
|
-
for (const step of steps) try {
|
|
222
|
-
await driver.query(step.sql, step.params ?? []);
|
|
223
|
-
} catch (error) {
|
|
224
|
-
if (SqlQueryError.is(error)) return runnerFailure("MIGRATION.EXECUTION_FAILED", `Operation ${operation.id} failed during execution: ${step.description}`, {
|
|
225
|
-
why: error.message,
|
|
226
|
-
meta: {
|
|
227
|
-
operationId: operation.id,
|
|
228
|
-
stepDescription: step.description,
|
|
229
|
-
sql: step.sql,
|
|
230
|
-
sqlState: error.sqlState,
|
|
231
|
-
constraint: error.constraint,
|
|
232
|
-
table: error.table,
|
|
233
|
-
column: error.column,
|
|
234
|
-
detail: error.detail
|
|
235
|
-
}
|
|
236
|
-
});
|
|
237
|
-
throw error;
|
|
238
|
-
}
|
|
239
|
-
return okVoid();
|
|
240
|
-
}
|
|
241
|
-
stepResultIsTrue(rows) {
|
|
242
|
-
if (!rows || rows.length === 0) return false;
|
|
243
|
-
const firstRow = rows[0];
|
|
244
|
-
const firstValue = firstRow ? Object.values(firstRow)[0] : void 0;
|
|
245
|
-
if (typeof firstValue === "boolean") return firstValue;
|
|
246
|
-
if (typeof firstValue === "number") return firstValue !== 0;
|
|
247
|
-
if (typeof firstValue === "string") {
|
|
248
|
-
const lower = firstValue.toLowerCase();
|
|
249
|
-
if (lower === "t" || lower === "true" || lower === "1") return true;
|
|
250
|
-
if (lower === "f" || lower === "false" || lower === "0") return false;
|
|
251
|
-
return firstValue.length > 0;
|
|
252
|
-
}
|
|
253
|
-
return Boolean(firstValue);
|
|
254
|
-
}
|
|
255
|
-
async expectationsAreSatisfied(driver, steps) {
|
|
256
|
-
if (steps.length === 0) return false;
|
|
257
|
-
for (const step of steps) {
|
|
258
|
-
const result = await driver.query(step.sql, step.params ?? []);
|
|
259
|
-
if (!this.stepResultIsTrue(result.rows)) return false;
|
|
260
|
-
}
|
|
261
|
-
return true;
|
|
262
|
-
}
|
|
263
|
-
createPostcheckPreSatisfiedSkipRecord(operation) {
|
|
264
|
-
const clonedMeta = operation.meta ? cloneAndFreezeRecord(operation.meta) : void 0;
|
|
265
|
-
const runnerMeta = Object.freeze({
|
|
266
|
-
skipped: true,
|
|
267
|
-
reason: "postcheck_pre_satisfied"
|
|
268
|
-
});
|
|
269
|
-
const mergedMeta = Object.freeze({
|
|
270
|
-
...clonedMeta ?? {},
|
|
271
|
-
runner: runnerMeta
|
|
272
|
-
});
|
|
273
|
-
const frozenPostcheck = Object.freeze([...operation.postcheck]);
|
|
274
|
-
return Object.freeze({
|
|
275
|
-
id: operation.id,
|
|
276
|
-
label: operation.label,
|
|
277
|
-
...ifDefined("summary", operation.summary),
|
|
278
|
-
operationClass: operation.operationClass,
|
|
279
|
-
target: operation.target,
|
|
280
|
-
precheck: Object.freeze([]),
|
|
281
|
-
execute: Object.freeze([]),
|
|
282
|
-
postcheck: frozenPostcheck,
|
|
283
|
-
...ifDefined("meta", operation.meta || mergedMeta ? mergedMeta : void 0)
|
|
284
|
-
});
|
|
285
|
-
}
|
|
286
|
-
markerMatchesDestination(marker, plan) {
|
|
287
|
-
if (!marker) return false;
|
|
288
|
-
if (marker.storageHash !== plan.destination.storageHash) return false;
|
|
289
|
-
if (plan.destination.profileHash && marker.profileHash !== plan.destination.profileHash) return false;
|
|
290
|
-
return true;
|
|
291
|
-
}
|
|
292
|
-
enforcePolicyCompatibility(policy, operations) {
|
|
293
|
-
const allowedClasses = new Set(policy.allowedOperationClasses);
|
|
294
|
-
for (const operation of operations) if (!allowedClasses.has(operation.operationClass)) return runnerFailure("MIGRATION.POLICY_VIOLATION", `Operation ${operation.id} has class "${operation.operationClass}" which is not allowed by policy.`, {
|
|
295
|
-
why: `Policy only allows: ${policy.allowedOperationClasses.join(", ")}.`,
|
|
296
|
-
meta: {
|
|
297
|
-
operationId: operation.id,
|
|
298
|
-
operationClass: operation.operationClass,
|
|
299
|
-
allowedClasses: policy.allowedOperationClasses
|
|
300
|
-
}
|
|
301
|
-
});
|
|
302
|
-
return okVoid();
|
|
303
|
-
}
|
|
304
|
-
ensureMarkerCompatibility(marker, plan) {
|
|
305
|
-
const origin = plan.origin ?? null;
|
|
306
|
-
if (!origin) return okVoid();
|
|
307
|
-
if (!marker) return runnerFailure("MIGRATION.MARKER_ORIGIN_MISMATCH", `Missing contract marker: expected origin storage hash ${origin.storageHash}.`, { meta: { expectedOriginStorageHash: origin.storageHash } });
|
|
308
|
-
if (marker.storageHash !== origin.storageHash) return runnerFailure("MIGRATION.MARKER_ORIGIN_MISMATCH", `Existing contract marker (${marker.storageHash}) does not match plan origin (${origin.storageHash}).`, { meta: {
|
|
309
|
-
markerStorageHash: marker.storageHash,
|
|
310
|
-
expectedOriginStorageHash: origin.storageHash
|
|
311
|
-
} });
|
|
312
|
-
if (origin.profileHash && marker.profileHash !== origin.profileHash) return runnerFailure("MIGRATION.MARKER_ORIGIN_MISMATCH", `Existing contract marker profile hash (${marker.profileHash}) does not match plan origin profile hash (${origin.profileHash}).`, { meta: {
|
|
313
|
-
markerProfileHash: marker.profileHash,
|
|
314
|
-
expectedOriginProfileHash: origin.profileHash
|
|
315
|
-
} });
|
|
316
|
-
return okVoid();
|
|
317
|
-
}
|
|
318
|
-
ensurePlanMatchesDestinationContract(destination, contract) {
|
|
319
|
-
if (destination.storageHash !== contract.storage.storageHash) return runnerFailure("MIGRATION.DESTINATION_CONTRACT_MISMATCH", `Plan destination storage hash (${destination.storageHash}) does not match provided contract storage hash (${contract.storage.storageHash}).`, { meta: {
|
|
320
|
-
planStorageHash: destination.storageHash,
|
|
321
|
-
contractStorageHash: contract.storage.storageHash
|
|
322
|
-
} });
|
|
323
|
-
if (destination.profileHash && contract.profileHash && destination.profileHash !== contract.profileHash) return runnerFailure("MIGRATION.DESTINATION_CONTRACT_MISMATCH", `Plan destination profile hash (${destination.profileHash}) does not match provided contract profile hash (${contract.profileHash}).`, { meta: {
|
|
324
|
-
planProfileHash: destination.profileHash,
|
|
325
|
-
contractProfileHash: contract.profileHash
|
|
326
|
-
} });
|
|
327
|
-
return okVoid();
|
|
328
|
-
}
|
|
329
|
-
async upsertMarker(driver, options, existingMarker, space) {
|
|
330
|
-
const destination = {
|
|
331
|
-
storageHash: options.plan.destination.storageHash,
|
|
332
|
-
profileHash: options.plan.destination.profileHash ?? options.destinationContract.profileHash ?? options.plan.destination.storageHash,
|
|
333
|
-
invariants: options.plan.providedInvariants ?? []
|
|
334
|
-
};
|
|
335
|
-
if (!existingMarker) {
|
|
336
|
-
await this.family.initMarker({
|
|
337
|
-
driver,
|
|
338
|
-
space,
|
|
339
|
-
destination
|
|
340
|
-
});
|
|
341
|
-
return okVoid();
|
|
342
|
-
}
|
|
343
|
-
if (!await this.family.updateMarker({
|
|
344
|
-
driver,
|
|
345
|
-
space,
|
|
346
|
-
expectedFrom: existingMarker.storageHash,
|
|
347
|
-
destination
|
|
348
|
-
})) return runnerFailure("MIGRATION.MARKER_CAS_FAILURE", "Marker was modified by another process during migration execution.", { meta: {
|
|
349
|
-
space,
|
|
350
|
-
expectedStorageHash: existingMarker.storageHash,
|
|
351
|
-
destinationStorageHash: options.plan.destination.storageHash
|
|
352
|
-
} });
|
|
353
|
-
return okVoid();
|
|
354
|
-
}
|
|
355
|
-
async recordLedgerEntries(driver, options, executedOperations, planOpsLength) {
|
|
356
|
-
const space = options.plan.spaceId;
|
|
357
|
-
const edges = options.migrationEdges;
|
|
358
|
-
const totalEdgeOps = edges.reduce((sum, edge) => sum + edge.operationCount, 0);
|
|
359
|
-
if (totalEdgeOps !== planOpsLength) throw new InternalError(`Ledger write: plan.operations length (${planOpsLength}) does not match sum of migrationEdges operationCount (${totalEdgeOps})`);
|
|
360
|
-
let offset = 0;
|
|
361
|
-
for (const edge of edges) {
|
|
362
|
-
const edgeOps = executedOperations.slice(offset, offset + edge.operationCount);
|
|
363
|
-
offset += edge.operationCount;
|
|
364
|
-
await this.family.writeLedgerEntry({
|
|
365
|
-
driver,
|
|
366
|
-
space,
|
|
367
|
-
entry: {
|
|
368
|
-
edgeId: `${edge.from}->${edge.to}`,
|
|
369
|
-
from: edge.from,
|
|
370
|
-
to: edge.to,
|
|
371
|
-
migrationName: edge.dirName,
|
|
372
|
-
migrationHash: edge.migrationHash,
|
|
373
|
-
operations: edgeOps,
|
|
374
|
-
...ifDefined("destinationContractJson", edge.destinationContractJson)
|
|
375
|
-
}
|
|
376
|
-
});
|
|
377
|
-
}
|
|
378
|
-
}
|
|
379
|
-
async acquireLock(driver, key) {
|
|
380
|
-
await driver.query("select pg_advisory_xact_lock(hashtext($1))", [key]);
|
|
381
|
-
}
|
|
382
|
-
async beginTransaction(driver) {
|
|
383
|
-
await driver.query("BEGIN");
|
|
384
|
-
}
|
|
385
|
-
async commitTransaction(driver) {
|
|
386
|
-
await driver.query("COMMIT");
|
|
387
|
-
}
|
|
388
|
-
async rollbackTransaction(driver) {
|
|
389
|
-
await driver.query("ROLLBACK");
|
|
390
|
-
}
|
|
391
|
-
async executeStatement(driver, statement) {
|
|
392
|
-
await driver.query(statement.sql, statement.params);
|
|
393
|
-
}
|
|
394
|
-
};
|
|
395
|
-
/**
|
|
396
|
-
* Postgres target `SchemaVerifier` concretion. Plugs into the
|
|
397
|
-
* SQL-shared verification surface; production verification today still
|
|
398
|
-
* routes through the family verify verdict (`verifySqlSchemaByDiff` over
|
|
399
|
-
* `diffPostgresSchema`), which carries options (codec hooks,
|
|
400
|
-
* normalizers, framework components) that the framework-level
|
|
401
|
-
* `SchemaVerifyOptions` shape does not yet surface.
|
|
402
|
-
*
|
|
403
|
-
* The hooks return the empty list pending the call-site migration that
|
|
404
|
-
* routes the existing verifier behaviour through the SPI — at that
|
|
405
|
-
* point `verifyCommonSqlSchema` will likely lift onto the family base
|
|
406
|
-
* (mirroring `verifyCommonMongoSchema`) and `verifyTargetExtensions`
|
|
407
|
-
* will house Postgres-only kinds (functions, RLS policies in a future
|
|
408
|
-
* project).
|
|
409
|
-
*/
|
|
410
|
-
var PostgresSchemaVerifier = class extends SqlSchemaVerifierBase {
|
|
411
|
-
verifyCommonSqlSchema(_options) {
|
|
412
|
-
return [];
|
|
413
|
-
}
|
|
414
|
-
verifyTargetExtensions(_options) {
|
|
415
|
-
return [];
|
|
416
|
-
}
|
|
417
|
-
};
|
|
13
|
+
//#region ../../../3-targets/3-targets/postgres/dist/infer-psl-contract-BaZaJAD9.mjs
|
|
418
14
|
function buildFieldNamesByTable(tables) {
|
|
419
15
|
const fieldNamesByTable = /* @__PURE__ */ new Map();
|
|
420
16
|
for (const table of Object.values(tables)) {
|
|
@@ -560,18 +156,79 @@ function namedArg(name, value) {
|
|
|
560
156
|
function escapePslString(value) {
|
|
561
157
|
return value.replace(/\\/g, "\\\\").replace(/"/g, "\\\"").replace(/\n/g, "\\n").replace(/\r/g, "\\r");
|
|
562
158
|
}
|
|
159
|
+
const INTEGER_TEXT = /^-?\d+$/;
|
|
160
|
+
const SPECIAL_VALUE_TEXT = /^(?:NaN|-?Infinity)$/;
|
|
161
|
+
const DECIMAL_TEXT = /^(?:-?\d+(?:\.\d+)?|NaN|-?Infinity)$/;
|
|
162
|
+
/** PSL has no exponent syntax, so the decimal point moves to where the exponent puts it. */
|
|
163
|
+
function plainNumeral(value) {
|
|
164
|
+
const [coefficient = "", exponent] = String(value).split("e");
|
|
165
|
+
if (exponent === void 0) return coefficient;
|
|
166
|
+
const sign = coefficient.startsWith("-") ? "-" : "";
|
|
167
|
+
const [whole = "", fraction = ""] = coefficient.slice(sign.length).split(".");
|
|
168
|
+
const digits = `${whole}${fraction}`;
|
|
169
|
+
const point = whole.length + Number(exponent);
|
|
170
|
+
if (point <= 0) return `${sign}0.${"0".repeat(-point)}${digits}`;
|
|
171
|
+
if (point >= digits.length) return `${sign}${digits}${"0".repeat(point - digits.length)}`;
|
|
172
|
+
return `${sign}${digits.slice(0, point)}.${digits.slice(point)}`;
|
|
173
|
+
}
|
|
174
|
+
const formatPslValue = (value) => {
|
|
175
|
+
if (typeof value === "string") return `"${escapePslString(value)}"`;
|
|
176
|
+
if (typeof value === "number" || typeof value === "boolean") return String(value);
|
|
177
|
+
};
|
|
178
|
+
const formatNumber = (value) => typeof value === "number" && Number.isFinite(value) ? plainNumeral(value) : void 0;
|
|
179
|
+
/** PSL has no number for `NaN` or `Infinity`; the float codecs pass their quoted text through. */
|
|
180
|
+
const formatFloat = (value) => typeof value === "string" && SPECIAL_VALUE_TEXT.test(value) ? `"${value}"` : formatNumber(value);
|
|
181
|
+
/**
|
|
182
|
+
* `pg/int8@1` reads a PSL number from the text written, so every digit of an `int8` survives. A
|
|
183
|
+
* PSL string is not a `bigint`. A JavaScript number past the safe integer range is already rounded.
|
|
184
|
+
*/
|
|
185
|
+
const formatInteger = (value) => {
|
|
186
|
+
if (typeof value === "string") return INTEGER_TEXT.test(value) ? value : void 0;
|
|
187
|
+
return typeof value === "number" && Number.isSafeInteger(value) ? String(value) : void 0;
|
|
188
|
+
};
|
|
563
189
|
/**
|
|
564
|
-
*
|
|
565
|
-
*
|
|
566
|
-
* string/number/boolean elements, so any other element (e.g. `null`, a
|
|
567
|
-
* nested array/object) makes the value unrepresentable and this returns
|
|
568
|
-
* `undefined`.
|
|
190
|
+
* `pg/numeric@1` stores decimal text, `NaN` or `Infinity`, and reads a PSL string as that text. A
|
|
191
|
+
* PSL number would also keep every digit, but has no spelling for `NaN` or `Infinity`.
|
|
569
192
|
*/
|
|
570
|
-
|
|
193
|
+
const formatDecimalText = (value) => {
|
|
194
|
+
const text = typeof value === "number" && Number.isFinite(value) ? plainNumeral(value) : value;
|
|
195
|
+
return typeof text === "string" && DECIMAL_TEXT.test(text) ? `"${text}"` : void 0;
|
|
196
|
+
};
|
|
197
|
+
/**
|
|
198
|
+
* The codecs of `Date`, `Time`, `Timestamp` and `Timestamptz` encode Temporal values, which no PSL
|
|
199
|
+
* literal is. A JSON codec reads a PSL string as a JSON string, not as JSON text, so a JSON default
|
|
200
|
+
* keeps its raw expression.
|
|
201
|
+
*/
|
|
202
|
+
const noLiteral = () => void 0;
|
|
203
|
+
const DEFAULT_VALUE_FORMATS = /* @__PURE__ */ new Map([
|
|
204
|
+
["Int", formatNumber],
|
|
205
|
+
["SmallInt", formatNumber],
|
|
206
|
+
["Float", formatFloat],
|
|
207
|
+
["Real", formatFloat],
|
|
208
|
+
["BigInt", formatInteger],
|
|
209
|
+
["Numeric", formatDecimalText],
|
|
210
|
+
["Date", noLiteral],
|
|
211
|
+
["Time", noLiteral],
|
|
212
|
+
["Timestamp", noLiteral],
|
|
213
|
+
["Timestamptz", noLiteral],
|
|
214
|
+
["Json", noLiteral],
|
|
215
|
+
["Jsonb", noLiteral]
|
|
216
|
+
]);
|
|
217
|
+
/** The default value format for a field of a PSL type the Postgres type map resolves. */
|
|
218
|
+
function pslDefaultValueFormat(typeName) {
|
|
219
|
+
return DEFAULT_VALUE_FORMATS.get(typeName) ?? formatPslValue;
|
|
220
|
+
}
|
|
221
|
+
/**
|
|
222
|
+
* Formats a resolved list default as PSL literal-list syntax (`[1, 2]`, `["a"]`, `[]`), or returns
|
|
223
|
+
* `undefined` when any element has no literal, such as `null` or a value `format` refuses.
|
|
224
|
+
*/
|
|
225
|
+
function formatPslListLiteralValue(elements, format) {
|
|
571
226
|
const parts = [];
|
|
572
|
-
for (const element of elements)
|
|
573
|
-
|
|
574
|
-
|
|
227
|
+
for (const element of elements) {
|
|
228
|
+
const part = format(element);
|
|
229
|
+
if (part === void 0) return void 0;
|
|
230
|
+
parts.push(part);
|
|
231
|
+
}
|
|
575
232
|
return `[${parts.join(", ")}]`;
|
|
576
233
|
}
|
|
577
234
|
/**
|
|
@@ -954,17 +611,8 @@ function buildScalarField(column, table, typeMap, enumNameMap, fieldNameMap, def
|
|
|
954
611
|
const attributes = [];
|
|
955
612
|
const isId = isSinglePk && pkColumns.has(column.name);
|
|
956
613
|
if (isId) attributes.push(buildSimpleConstraintFieldAttribute("id", singlePkConstraintName));
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
const formatted = Array.isArray(column.resolvedDefault.value) ? formatPslListLiteralValue(column.resolvedDefault.value) : void 0;
|
|
960
|
-
if (formatted !== void 0) attributes.push(parseDefaultAttributeString(`@default(${formatted})`));
|
|
961
|
-
} else if (column.default !== void 0) {
|
|
962
|
-
const parsed = parseColumnDefault(column.default, column.nativeType, rawDefaultParser);
|
|
963
|
-
if (parsed) {
|
|
964
|
-
const result = mapDefault(parsed, defaultMapping);
|
|
965
|
-
if ("attribute" in result) attributes.push(parseDefaultAttributeString(result.attribute));
|
|
966
|
-
}
|
|
967
|
-
}
|
|
614
|
+
const defaultAttribute = inferDefaultAttribute(column, enumPslName === void 0 ? pslDefaultValueFormat(resolution.pslType.name) : formatPslValue, defaultMapping, rawDefaultParser);
|
|
615
|
+
if (defaultAttribute !== void 0) attributes.push(parseDefaultAttributeString(defaultAttribute));
|
|
968
616
|
if (uniqueColumns.has(column.name) && !isId) {
|
|
969
617
|
const uniqueConstraintName = uniqueColumns.get(column.name);
|
|
970
618
|
attributes.push(buildSimpleConstraintFieldAttribute("unique", uniqueConstraintName));
|
|
@@ -990,6 +638,34 @@ function buildScalarField(column, table, typeMap, enumNameMap, fieldNameMap, def
|
|
|
990
638
|
span: SYNTHETIC_SPAN
|
|
991
639
|
};
|
|
992
640
|
}
|
|
641
|
+
/**
|
|
642
|
+
* A literal default prints as the PSL literal its codec accepts. A literal that has no such PSL
|
|
643
|
+
* literal prints as `dbgenerated(...)` with the expression Postgres reported: `contract emit`
|
|
644
|
+
* accepts that on a scalar column and rejects it at the field on a list column.
|
|
645
|
+
*/
|
|
646
|
+
function inferDefaultAttribute(column, valueFormat, defaultMapping, rawDefaultParser) {
|
|
647
|
+
if (column.default === void 0 && column.resolvedDefault?.kind === "function" && column.resolvedDefault.expression === "autoincrement()") return "@default(autoincrement())";
|
|
648
|
+
if (column.many === true && column.resolvedDefault?.kind === "literal") {
|
|
649
|
+
const { value } = column.resolvedDefault;
|
|
650
|
+
return Array.isArray(value) ? literalOrRawAttribute(formatPslListLiteralValue(value, valueFormat), column, defaultMapping) : void 0;
|
|
651
|
+
}
|
|
652
|
+
const parsed = parseColumnDefault(column.default, column.nativeType, rawDefaultParser);
|
|
653
|
+
if (parsed === void 0) return;
|
|
654
|
+
if (parsed.kind === "literal") return literalOrRawAttribute(valueFormat(parsed.value), column, defaultMapping);
|
|
655
|
+
return mappedAttribute(parsed, defaultMapping);
|
|
656
|
+
}
|
|
657
|
+
function literalOrRawAttribute(literal, column, defaultMapping) {
|
|
658
|
+
if (literal !== void 0) return `@default(${literal})`;
|
|
659
|
+
return typeof column.default === "string" ? mappedAttribute({
|
|
660
|
+
kind: "function",
|
|
661
|
+
expression: column.default
|
|
662
|
+
}, defaultMapping) : void 0;
|
|
663
|
+
}
|
|
664
|
+
/** A default the mapping can only describe in a comment is dropped: a field AST node has no comment. */
|
|
665
|
+
function mappedAttribute(columnDefault, defaultMapping) {
|
|
666
|
+
const result = mapDefault(columnDefault, defaultMapping);
|
|
667
|
+
return "attribute" in result ? result.attribute : void 0;
|
|
668
|
+
}
|
|
993
669
|
function buildRelationField(rel, hostTableName, fieldNamesByTable, usedFieldNames) {
|
|
994
670
|
const fieldName = createUniqueFieldName(rel.fieldName, usedFieldNames);
|
|
995
671
|
usedFieldNames.add(fieldName);
|
|
@@ -1235,8 +911,9 @@ function createPostgresTypeMap(enumTypeNames) {
|
|
|
1235
911
|
*
|
|
1236
912
|
* Target-owned inference: it walks the `PostgresDatabaseSchemaNode` tree and
|
|
1237
913
|
* owns the Postgres dialect knowledge — the native type map and default map.
|
|
1238
|
-
*
|
|
1239
|
-
*
|
|
914
|
+
* It reads raw defaults with `parsePostgresDefault`, the parser introspection
|
|
915
|
+
* and verify use. Relation inference, name transforms, and generic default
|
|
916
|
+
* mapping are shape-neutral utilities imported from the SQL family.
|
|
1240
917
|
*
|
|
1241
918
|
* The tree's tables (across its namespaces — `contract infer` introspects a
|
|
1242
919
|
* single live namespace) are gathered into the model set and emitted in one
|
|
@@ -1323,7 +1000,7 @@ function inferPostgresPslContract(tree, describedContracts) {
|
|
|
1323
1000
|
return buildPslDocumentAst(schemaIR, {
|
|
1324
1001
|
typeMap: createPostgresTypeMap(enumInfo.typeNames),
|
|
1325
1002
|
defaultMapping: createPostgresDefaultMapping(),
|
|
1326
|
-
parseRawDefault,
|
|
1003
|
+
parseRawDefault: parsePostgresDefault,
|
|
1327
1004
|
...enumDefinitions.size > 0 ? { enumInfo } : {}
|
|
1328
1005
|
}, {
|
|
1329
1006
|
extraRelationsByTable,
|
|
@@ -1406,62 +1083,7 @@ function buildPslDocumentAst(schemaIR, options, foreignKeyExtras, namespaceName,
|
|
|
1406
1083
|
span: SYNTHETIC_SPAN
|
|
1407
1084
|
};
|
|
1408
1085
|
}
|
|
1409
|
-
function postgresRenderDefault(def, column) {
|
|
1410
|
-
if (def.kind === "function") return def.expression;
|
|
1411
|
-
return renderDefaultLiteral(def.value, column);
|
|
1412
|
-
}
|
|
1413
|
-
const postgresTargetDescriptor = {
|
|
1414
|
-
...postgresTargetDescriptorMeta,
|
|
1415
|
-
contractSerializer: new PostgresContractSerializer(),
|
|
1416
|
-
schemaVerifier: new PostgresSchemaVerifier(),
|
|
1417
|
-
inferPslContract(schema, describedContracts) {
|
|
1418
|
-
PostgresDatabaseSchemaNode.assert(schema);
|
|
1419
|
-
return inferPostgresPslContract(schema, describedContracts);
|
|
1420
|
-
},
|
|
1421
|
-
diffSchema(input) {
|
|
1422
|
-
return diffPostgresSchema(input);
|
|
1423
|
-
},
|
|
1424
|
-
classifySubjectGranularity: postgresDiffSubjectGranularity,
|
|
1425
|
-
classifyEntityKind: postgresDiffSubjectEntityKind,
|
|
1426
|
-
migrations: {
|
|
1427
|
-
createPlanner(adapter) {
|
|
1428
|
-
return createPostgresMigrationPlanner(adapter);
|
|
1429
|
-
},
|
|
1430
|
-
createRunner(family) {
|
|
1431
|
-
return createPostgresMigrationRunner(family);
|
|
1432
|
-
},
|
|
1433
|
-
contractToSchema(contract, frameworkComponents) {
|
|
1434
|
-
const expander = buildNativeTypeExpander(frameworkComponents);
|
|
1435
|
-
return contractToPostgresDatabaseSchemaNode(blindCast(contract), {
|
|
1436
|
-
annotationNamespace: "pg",
|
|
1437
|
-
...ifDefined("expandNativeType", expander),
|
|
1438
|
-
renderDefault: postgresRenderDefault,
|
|
1439
|
-
resolveDefault: postgresResolveDefault
|
|
1440
|
-
});
|
|
1441
|
-
}
|
|
1442
|
-
},
|
|
1443
|
-
create() {
|
|
1444
|
-
return {
|
|
1445
|
-
familyId: "sql",
|
|
1446
|
-
targetId: "postgres"
|
|
1447
|
-
};
|
|
1448
|
-
},
|
|
1449
|
-
/**
|
|
1450
|
-
* Direct method for SQL-specific usage.
|
|
1451
|
-
* @deprecated Use migrations.createPlanner() for CLI compatibility.
|
|
1452
|
-
*/
|
|
1453
|
-
createPlanner(adapter) {
|
|
1454
|
-
return createPostgresMigrationPlanner(adapter);
|
|
1455
|
-
},
|
|
1456
|
-
/**
|
|
1457
|
-
* Direct method for SQL-specific usage.
|
|
1458
|
-
* @deprecated Use migrations.createRunner() for CLI compatibility.
|
|
1459
|
-
*/
|
|
1460
|
-
createRunner(family) {
|
|
1461
|
-
return createPostgresMigrationRunner(family);
|
|
1462
|
-
}
|
|
1463
|
-
};
|
|
1464
1086
|
//#endregion
|
|
1465
|
-
export {
|
|
1087
|
+
export { inferPostgresPslContract as i, createPostgresDefaultMapping as n, createPostgresTypeMap as r, buildPslDocumentAst as t };
|
|
1466
1088
|
|
|
1467
|
-
//# sourceMappingURL=
|
|
1089
|
+
//# sourceMappingURL=infer-psl-contract-BaZaJAD9-DTVu5Zab.mjs.map
|