@prisma-next/target-postgres 0.12.0-dev.27 → 0.12.0-dev.29
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/control.mjs +1 -1
- package/dist/{data-transform-4QL41_vQ.mjs → data-transform-DIYwbe4S.mjs} +1 -1
- package/dist/{data-transform-4QL41_vQ.mjs.map → data-transform-DIYwbe4S.mjs.map} +1 -1
- package/dist/data-transform.mjs +1 -1
- package/dist/{errors-BhiZYTWZ.mjs → errors-De185dnO.mjs} +1 -1
- package/dist/{errors-BhiZYTWZ.mjs.map → errors-De185dnO.mjs.map} +1 -1
- package/dist/errors.mjs +1 -1
- package/dist/{issue-planner-BrqTKeZa.mjs → issue-planner-ttX4mOiF.mjs} +16 -103
- package/dist/issue-planner-ttX4mOiF.mjs.map +1 -0
- package/dist/issue-planner.d.mts.map +1 -1
- package/dist/issue-planner.mjs +1 -1
- package/dist/migration.mjs +2 -2
- package/dist/{planner-produced-postgres-migration-x3hafaGC.mjs → planner-produced-postgres-migration-D6KXC2DH.mjs} +4 -4
- package/dist/{planner-produced-postgres-migration-x3hafaGC.mjs.map → planner-produced-postgres-migration-D6KXC2DH.mjs.map} +1 -1
- package/dist/planner-produced-postgres-migration.mjs +1 -1
- package/dist/{planner-schema-lookup-DLJbkU7-.mjs → planner-schema-lookup-Bm4S3LvB.mjs} +1 -1
- package/dist/{planner-schema-lookup-DLJbkU7-.mjs.map → planner-schema-lookup-Bm4S3LvB.mjs.map} +1 -1
- package/dist/planner-schema-lookup.mjs +1 -1
- package/dist/planner-y-bVvDFR.mjs +342 -0
- package/dist/planner-y-bVvDFR.mjs.map +1 -0
- package/dist/planner.d.mts +2 -1
- package/dist/planner.d.mts.map +1 -1
- package/dist/planner.mjs +1 -1
- package/dist/{postgres-migration-BDaWGYDu.mjs → postgres-migration-BnDg_Nj0.mjs} +3 -3
- package/dist/{postgres-migration-BDaWGYDu.mjs.map → postgres-migration-BnDg_Nj0.mjs.map} +1 -1
- package/dist/{render-ops-Da7bQcyv.mjs → render-ops-BpU-Qv06.mjs} +1 -1
- package/dist/{render-ops-Da7bQcyv.mjs.map → render-ops-BpU-Qv06.mjs.map} +1 -1
- package/dist/render-ops.mjs +1 -1
- package/dist/{render-typescript-DTpTcoNZ.mjs → render-typescript-D9O7aOS_.mjs} +1 -1
- package/dist/{render-typescript-DTpTcoNZ.mjs.map → render-typescript-D9O7aOS_.mjs.map} +1 -1
- package/dist/render-typescript.mjs +1 -1
- package/package.json +17 -17
- package/src/core/migrations/control-policy.ts +91 -0
- package/src/core/migrations/issue-planner.ts +1 -12
- package/src/core/migrations/planner.ts +38 -5
- package/dist/issue-planner-BrqTKeZa.mjs.map +0 -1
- package/dist/planner-C_fLowcn.mjs +0 -184
- package/dist/planner-C_fLowcn.mjs.map +0 -1
|
@@ -0,0 +1,342 @@
|
|
|
1
|
+
import { t as postgresColumnsCompatible } from "./column-type-compatibility-Dzxz_CkP.mjs";
|
|
2
|
+
import { r as isPostgresSchema } from "./postgres-schema-Dky_Jff8.mjs";
|
|
3
|
+
import { t as createResolveExistingEnumValues } from "./enum-planning-DHQE3zSH.mjs";
|
|
4
|
+
import { t as parsePostgresDefault } from "./default-normalizer-DFHtpCPH.mjs";
|
|
5
|
+
import { t as normalizeSchemaNativeType } from "./native-type-normalizer-BUUe8USD.mjs";
|
|
6
|
+
import { n as postgresPlannerStrategies, t as planIssues } from "./issue-planner-ttX4mOiF.mjs";
|
|
7
|
+
import { t as TypeScriptRenderablePostgresMigration } from "./planner-produced-postgres-migration-D6KXC2DH.mjs";
|
|
8
|
+
import { extractCodecControlHooks, partitionCallsByControlPolicy, partitionIssuesByControlPolicy, planFieldEventOperations, plannerFailure } from "@prisma-next/family-sql/control";
|
|
9
|
+
import { ifDefined } from "@prisma-next/utils/defined";
|
|
10
|
+
import { UNBOUND_NAMESPACE_ID } from "@prisma-next/framework-components/ir";
|
|
11
|
+
import { isPostgresEnumStorageEntry, storageTableAt } from "@prisma-next/sql-contract/types";
|
|
12
|
+
import { verifySqlSchema } from "@prisma-next/family-sql/schema-verify";
|
|
13
|
+
import { blindCast } from "@prisma-next/utils/casts";
|
|
14
|
+
//#region src/core/migrations/control-policy.ts
|
|
15
|
+
/**
|
|
16
|
+
* Factory calls that create a whole, previously-absent top-level storage
|
|
17
|
+
* object. Used to decide whether `tolerated` permits a call (it only allows
|
|
18
|
+
* creating absent objects, never modifying existing ones).
|
|
19
|
+
*
|
|
20
|
+
* Deliberately an explicit, closed set rather than a `factoryName`
|
|
21
|
+
* create/alter/drop classification: it answers exactly one yes/no question
|
|
22
|
+
* and is fail-closed. Any call not listed here — including future or
|
|
23
|
+
* extension-contributed factories — is treated as NOT object-creation, so it
|
|
24
|
+
* is suppressed under `tolerated` rather than permissively emitted.
|
|
25
|
+
*/
|
|
26
|
+
const OBJECT_CREATION_FACTORIES = new Set([
|
|
27
|
+
"createTable",
|
|
28
|
+
"createEnumType",
|
|
29
|
+
"createSchema"
|
|
30
|
+
]);
|
|
31
|
+
function createsNewTopLevelObject(call) {
|
|
32
|
+
return OBJECT_CREATION_FACTORIES.has(call.factoryName);
|
|
33
|
+
}
|
|
34
|
+
function ddlSchemaNameForNamespace(contract, namespaceId) {
|
|
35
|
+
const namespace = contract.storage.namespaces[namespaceId];
|
|
36
|
+
return isPostgresSchema(namespace) ? namespace.ddlSchemaName(contract.storage) : namespaceId;
|
|
37
|
+
}
|
|
38
|
+
function resolveNamespaceIdForTable(contract, tableName, ddlSchemaName) {
|
|
39
|
+
for (const namespaceId of Object.keys(contract.storage.namespaces)) {
|
|
40
|
+
if (!storageTableAt(contract.storage, namespaceId, tableName)) continue;
|
|
41
|
+
if (ddlSchemaName === void 0 || ddlSchemaNameForNamespace(contract, namespaceId) === ddlSchemaName) return namespaceId;
|
|
42
|
+
}
|
|
43
|
+
return UNBOUND_NAMESPACE_ID;
|
|
44
|
+
}
|
|
45
|
+
function resolveNamespaceIdForDdlSchema(contract, ddlSchemaName) {
|
|
46
|
+
for (const namespaceId of Object.keys(contract.storage.namespaces)) {
|
|
47
|
+
const ns = contract.storage.namespaces[namespaceId];
|
|
48
|
+
if (isPostgresSchema(ns) && ns.ddlSchemaName(contract.storage) === ddlSchemaName) return namespaceId;
|
|
49
|
+
if (namespaceId === ddlSchemaName) return namespaceId;
|
|
50
|
+
}
|
|
51
|
+
return UNBOUND_NAMESPACE_ID;
|
|
52
|
+
}
|
|
53
|
+
function postgresCallFields(call) {
|
|
54
|
+
return {
|
|
55
|
+
...ifDefined("schemaName", "schemaName" in call ? call.schemaName : void 0),
|
|
56
|
+
...ifDefined("tableName", "tableName" in call ? call.tableName : void 0),
|
|
57
|
+
...ifDefined("columnName", "columnName" in call ? call.columnName : void 0),
|
|
58
|
+
...ifDefined("typeName", "typeName" in call ? call.typeName : void 0)
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
function formatPostgresControlPolicySubjectLabel(factoryName, subject, contract) {
|
|
62
|
+
if (subject?.table) return `${factoryName}(${ddlSchemaNameForNamespace(contract, subject.namespaceId)}.${subject.table})`;
|
|
63
|
+
if (subject?.typeName) return `${factoryName}(${ddlSchemaNameForNamespace(contract, subject.namespaceId)}.${subject.typeName})`;
|
|
64
|
+
return factoryName;
|
|
65
|
+
}
|
|
66
|
+
function resolvePostgresCallControlPolicySubject(call, contract) {
|
|
67
|
+
const callFields = postgresCallFields(call);
|
|
68
|
+
const createsNewObject = createsNewTopLevelObject(call);
|
|
69
|
+
if (call.factoryName === "createSchema" && callFields.schemaName) return {
|
|
70
|
+
namespaceId: resolveNamespaceIdForDdlSchema(contract, callFields.schemaName),
|
|
71
|
+
createsNewObject
|
|
72
|
+
};
|
|
73
|
+
if (callFields.typeName && call.factoryName !== "addColumn") {
|
|
74
|
+
const namespaceId = callFields.schemaName ? resolveNamespaceIdForDdlSchema(contract, callFields.schemaName) : UNBOUND_NAMESPACE_ID;
|
|
75
|
+
const ns = contract.storage.namespaces[namespaceId];
|
|
76
|
+
const rawEnum = ns && "enum" in ns && ns.enum != null ? ns.enum[callFields.typeName] : void 0;
|
|
77
|
+
return {
|
|
78
|
+
namespaceId,
|
|
79
|
+
...ifDefined("explicitNodeControlPolicy", isPostgresEnumStorageEntry(rawEnum) ? rawEnum.control : void 0),
|
|
80
|
+
typeName: callFields.typeName,
|
|
81
|
+
createsNewObject
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
if (callFields.tableName) {
|
|
85
|
+
const namespaceId = resolveNamespaceIdForTable(contract, callFields.tableName, callFields.schemaName);
|
|
86
|
+
const tableControlPolicy = storageTableAt(contract.storage, namespaceId, callFields.tableName)?.control;
|
|
87
|
+
return {
|
|
88
|
+
namespaceId,
|
|
89
|
+
...ifDefined("explicitNodeControlPolicy", tableControlPolicy),
|
|
90
|
+
table: callFields.tableName,
|
|
91
|
+
...ifDefined("column", callFields.columnName),
|
|
92
|
+
createsNewObject
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
if (callFields.schemaName) return {
|
|
96
|
+
namespaceId: resolveNamespaceIdForDdlSchema(contract, callFields.schemaName),
|
|
97
|
+
createsNewObject
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Issue kinds that describe the absence of a whole, top-level Postgres
|
|
102
|
+
* object — the same kinds `createsNewTopLevelObject` recognises for calls.
|
|
103
|
+
* Used by {@link resolvePostgresIssueCreationFactoryName} to decide whether
|
|
104
|
+
* a `tolerated` subject permits the issue to flow into the planner
|
|
105
|
+
* (create-if-absent) and to seed the suppressed-subject warning's
|
|
106
|
+
* `factoryName` when the planner is skipped.
|
|
107
|
+
*/
|
|
108
|
+
const POSTGRES_ISSUE_CREATION_FACTORY = Object.freeze({
|
|
109
|
+
missing_schema: "createSchema",
|
|
110
|
+
missing_table: "createTable",
|
|
111
|
+
type_missing: "createEnumType"
|
|
112
|
+
});
|
|
113
|
+
function resolvePostgresIssueCreationFactoryName(issue) {
|
|
114
|
+
return POSTGRES_ISSUE_CREATION_FACTORY[issue.kind];
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* Resolve the control-policy subject coordinate for a single
|
|
118
|
+
* {@link SchemaIssue}. Mirrors the resolution `resolvePostgresCallControlPolicySubject`
|
|
119
|
+
* performs for a generated DDL call, but works *off the issue* — so the
|
|
120
|
+
* planner can partition issues by effective policy before the diff engine
|
|
121
|
+
* runs. `createsNewObject` is derived from the issue's kind: schema/table/
|
|
122
|
+
* type-missing issues describe a brand-new top-level object; everything else
|
|
123
|
+
* touches an existing object.
|
|
124
|
+
*
|
|
125
|
+
* An `extra_table` issue carries no contract namespace coordinate (the table
|
|
126
|
+
* isn't in any contract namespace), so the subject's `namespaceId` falls
|
|
127
|
+
* back to {@link UNBOUND_NAMESPACE_ID}; the call-side resolver does the same
|
|
128
|
+
* for the `DropTableCall` it produces.
|
|
129
|
+
*/
|
|
130
|
+
function resolvePostgresIssueControlPolicySubject(issue, contract) {
|
|
131
|
+
const createsNewObject = POSTGRES_ISSUE_CREATION_FACTORY[issue.kind] !== void 0;
|
|
132
|
+
if (issue.kind === "missing_schema" && issue.namespaceId) return {
|
|
133
|
+
namespaceId: issue.namespaceId,
|
|
134
|
+
createsNewObject
|
|
135
|
+
};
|
|
136
|
+
if ("typeName" in issue && issue.typeName) {
|
|
137
|
+
const namespaceId = "namespaceId" in issue && issue.namespaceId ? issue.namespaceId : UNBOUND_NAMESPACE_ID;
|
|
138
|
+
const ns = contract.storage.namespaces[namespaceId];
|
|
139
|
+
const rawEnum = ns && "enum" in ns && ns.enum != null ? ns.enum[issue.typeName] : void 0;
|
|
140
|
+
return {
|
|
141
|
+
namespaceId,
|
|
142
|
+
...ifDefined("explicitNodeControlPolicy", isPostgresEnumStorageEntry(rawEnum) ? rawEnum.control : void 0),
|
|
143
|
+
typeName: issue.typeName,
|
|
144
|
+
createsNewObject
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
if ("table" in issue && issue.table) {
|
|
148
|
+
const namespaceId = "namespaceId" in issue && issue.namespaceId ? issue.namespaceId : resolveNamespaceIdForTable(contract, issue.table, void 0);
|
|
149
|
+
return {
|
|
150
|
+
namespaceId,
|
|
151
|
+
...ifDefined("explicitNodeControlPolicy", storageTableAt(contract.storage, namespaceId, issue.table)?.control),
|
|
152
|
+
table: issue.table,
|
|
153
|
+
...ifDefined("column", "column" in issue ? issue.column : void 0),
|
|
154
|
+
createsNewObject
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
//#endregion
|
|
159
|
+
//#region src/core/migrations/verify-postgres-namespaces.ts
|
|
160
|
+
/**
|
|
161
|
+
* Resolves the live-database schema name for a given namespace
|
|
162
|
+
* coordinate. Mirrors `resolveDdlSchemaForNamespace` in
|
|
163
|
+
* `planner-strategies.ts` so the verifier's projection and the
|
|
164
|
+
* planner's projection always agree — Postgres-aware namespaces (the
|
|
165
|
+
* production path) dispatch to `ddlSchemaName(storage)`, and bare
|
|
166
|
+
* object payloads (used by some tests) fall back to the coordinate
|
|
167
|
+
* itself.
|
|
168
|
+
*/
|
|
169
|
+
function resolveDdlSchemaName(storage, namespaceId) {
|
|
170
|
+
const namespace = storage.namespaces[namespaceId];
|
|
171
|
+
if (isPostgresSchema(namespace)) return namespace.ddlSchemaName(storage);
|
|
172
|
+
return namespaceId;
|
|
173
|
+
}
|
|
174
|
+
/**
|
|
175
|
+
* Reads the introspected list of schema names from the Postgres-flavoured
|
|
176
|
+
* annotations slot on the schema IR. Defaults to the always-present
|
|
177
|
+
* `public` schema when introspection did not populate the slot — a fresh
|
|
178
|
+
* Postgres database always carries `public` (unless an operator dropped
|
|
179
|
+
* it manually), so any verifier path that runs without an enriched
|
|
180
|
+
* introspection still suppresses the redundant `CREATE SCHEMA "public"`.
|
|
181
|
+
*
|
|
182
|
+
* Production introspection (`PostgresControlAdapter.introspect`) is the
|
|
183
|
+
* authoritative source: it queries `pg_namespace` and writes every
|
|
184
|
+
* non-system schema into `annotations.pg.existingSchemas`. Tests that
|
|
185
|
+
* want to assert against a richer initial state pass the slot
|
|
186
|
+
* explicitly via the schema IR.
|
|
187
|
+
*/
|
|
188
|
+
function existingSchemasFromSchema(schema) {
|
|
189
|
+
const slot = schema.annotations?.pg?.existingSchemas;
|
|
190
|
+
if (Array.isArray(slot)) return slot.filter((s) => typeof s === "string");
|
|
191
|
+
return ["public"];
|
|
192
|
+
}
|
|
193
|
+
/**
|
|
194
|
+
* Emits a `missing_schema` issue for every contract-declared Postgres
|
|
195
|
+
* namespace whose live container does not yet exist.
|
|
196
|
+
*
|
|
197
|
+
* A namespace's live container is the schema returned by its
|
|
198
|
+
* polymorphic `ddlSchemaName(storage)` method — named schemas resolve
|
|
199
|
+
* to their own id; the unbound singleton returns `UNBOUND_NAMESPACE_ID`
|
|
200
|
+
* and is skipped explicitly (late-bound namespaces have no fixed DDL
|
|
201
|
+
* schema). Issues are emitted only when the resolved name is a real,
|
|
202
|
+
* creatable schema (not the unbound sentinel) and is missing from the
|
|
203
|
+
* introspected list. `public` is suppressed implicitly because the
|
|
204
|
+
* introspection (or its sensible default) always carries it.
|
|
205
|
+
*
|
|
206
|
+
* Each emitted issue stamps `namespaceId` with the contract namespace
|
|
207
|
+
* coordinate so the downstream `mapIssueToCall` re-resolves the DDL
|
|
208
|
+
* schema name through the same polymorphic path — keeping the
|
|
209
|
+
* coordinate, not the resolved name, as the issue's stable identity.
|
|
210
|
+
*/
|
|
211
|
+
function verifyPostgresNamespacePresence(input) {
|
|
212
|
+
const { contract, schema } = input;
|
|
213
|
+
const existing = new Set(existingSchemasFromSchema(schema));
|
|
214
|
+
const issues = [];
|
|
215
|
+
const namespaceIds = Object.keys(contract.storage.namespaces).sort();
|
|
216
|
+
for (const namespaceId of namespaceIds) {
|
|
217
|
+
if (namespaceId === UNBOUND_NAMESPACE_ID) continue;
|
|
218
|
+
const ddlName = resolveDdlSchemaName(contract.storage, namespaceId);
|
|
219
|
+
if (ddlName === UNBOUND_NAMESPACE_ID) continue;
|
|
220
|
+
if (existing.has(ddlName)) continue;
|
|
221
|
+
issues.push({
|
|
222
|
+
kind: "missing_schema",
|
|
223
|
+
namespaceId,
|
|
224
|
+
message: `Schema "${ddlName}" is missing from database`
|
|
225
|
+
});
|
|
226
|
+
}
|
|
227
|
+
return issues;
|
|
228
|
+
}
|
|
229
|
+
//#endregion
|
|
230
|
+
//#region src/core/migrations/planner.ts
|
|
231
|
+
function createPostgresMigrationPlanner() {
|
|
232
|
+
return new PostgresMigrationPlanner();
|
|
233
|
+
}
|
|
234
|
+
/**
|
|
235
|
+
* Postgres migration planner — a thin wrapper over `planIssues`.
|
|
236
|
+
*
|
|
237
|
+
* `plan()` verifies the live schema against the target contract (producing
|
|
238
|
+
* `SchemaIssue[]`) and delegates to `planIssues` with the unified
|
|
239
|
+
* `postgresPlannerStrategies` list: enum-change, NOT-NULL backfill,
|
|
240
|
+
* type-change, nullable-tightening, codec-hook storage types,
|
|
241
|
+
* component-declared dependency installs, and shared-temp-default /
|
|
242
|
+
* empty-table-guarded NOT-NULL add-column. The same strategy list runs for
|
|
243
|
+
* `migration plan`, `db update`, and `db init`; behavior diverges purely on
|
|
244
|
+
* `policy.allowedOperationClasses` (the data-safe strategies short-circuit
|
|
245
|
+
* when `'data'` is excluded). The issue planner applies operation-class
|
|
246
|
+
* policy gates and emits a single `PostgresOpFactoryCall[]` that drives both
|
|
247
|
+
* the runtime-ops view (via `renderOps`) and the `renderTypeScript()`
|
|
248
|
+
* authoring surface.
|
|
249
|
+
*/
|
|
250
|
+
var PostgresMigrationPlanner = class {
|
|
251
|
+
plan(options) {
|
|
252
|
+
return this.planSql(options);
|
|
253
|
+
}
|
|
254
|
+
emptyMigration(context, spaceId) {
|
|
255
|
+
return new TypeScriptRenderablePostgresMigration([], {
|
|
256
|
+
from: context.fromHash,
|
|
257
|
+
to: context.toHash
|
|
258
|
+
}, spaceId);
|
|
259
|
+
}
|
|
260
|
+
planSql(options) {
|
|
261
|
+
const schemaName = options.schemaName ?? Object.keys(options.contract.storage.namespaces).find((id) => id !== UNBOUND_NAMESPACE_ID) ?? UNBOUND_NAMESPACE_ID;
|
|
262
|
+
const policyResult = this.ensureAdditivePolicy(options.policy);
|
|
263
|
+
if (policyResult) return policyResult;
|
|
264
|
+
const schemaIssues = this.collectSchemaIssues(options);
|
|
265
|
+
const codecHooks = extractCodecControlHooks(options.frameworkComponents);
|
|
266
|
+
const storageTypes = options.contract.storage.types ?? {};
|
|
267
|
+
const issuePartition = partitionIssuesByControlPolicy({
|
|
268
|
+
issues: schemaIssues,
|
|
269
|
+
contract: options.contract,
|
|
270
|
+
resolveControlPolicySubject: (issue) => resolvePostgresIssueControlPolicySubject(issue, options.contract),
|
|
271
|
+
resolveCreationFactoryName: resolvePostgresIssueCreationFactoryName,
|
|
272
|
+
formatSubjectLabel: (factoryName, subject) => formatPostgresControlPolicySubjectLabel(factoryName, subject, options.contract)
|
|
273
|
+
});
|
|
274
|
+
const result = planIssues({
|
|
275
|
+
issues: issuePartition.plannable,
|
|
276
|
+
toContract: options.contract,
|
|
277
|
+
fromContract: options.fromContract,
|
|
278
|
+
schemaName,
|
|
279
|
+
codecHooks,
|
|
280
|
+
storageTypes,
|
|
281
|
+
schema: options.schema,
|
|
282
|
+
policy: options.policy,
|
|
283
|
+
frameworkComponents: options.frameworkComponents,
|
|
284
|
+
strategies: postgresPlannerStrategies
|
|
285
|
+
});
|
|
286
|
+
if (!result.ok) return plannerFailure(result.failure);
|
|
287
|
+
const fieldEventPartition = partitionCallsByControlPolicy({
|
|
288
|
+
calls: blindCast(planFieldEventOperations({
|
|
289
|
+
priorContract: options.fromContract,
|
|
290
|
+
newContract: options.contract,
|
|
291
|
+
codecHooks
|
|
292
|
+
})),
|
|
293
|
+
contract: options.contract,
|
|
294
|
+
resolveControlPolicySubject: (call) => resolvePostgresCallControlPolicySubject(call, options.contract),
|
|
295
|
+
resolveFactoryName: (call) => call.factoryName,
|
|
296
|
+
formatSubjectLabel: (factoryName, subject) => formatPostgresControlPolicySubjectLabel(factoryName, subject, options.contract)
|
|
297
|
+
});
|
|
298
|
+
const calls = [...result.value.calls, ...fieldEventPartition.kept];
|
|
299
|
+
const warnings = [...issuePartition.warnings, ...fieldEventPartition.warnings];
|
|
300
|
+
return Object.freeze({
|
|
301
|
+
kind: "success",
|
|
302
|
+
plan: new TypeScriptRenderablePostgresMigration(calls, {
|
|
303
|
+
from: options.fromContract?.storage.storageHash ?? null,
|
|
304
|
+
to: options.contract.storage.storageHash
|
|
305
|
+
}, options.spaceId),
|
|
306
|
+
...warnings.length > 0 ? { warnings: Object.freeze(warnings) } : {}
|
|
307
|
+
});
|
|
308
|
+
}
|
|
309
|
+
ensureAdditivePolicy(policy) {
|
|
310
|
+
if (!policy.allowedOperationClasses.includes("additive")) return plannerFailure([{
|
|
311
|
+
kind: "unsupportedOperation",
|
|
312
|
+
summary: "Migration planner requires additive operations be allowed",
|
|
313
|
+
why: "The planner requires the \"additive\" operation class to be allowed in the policy."
|
|
314
|
+
}]);
|
|
315
|
+
return null;
|
|
316
|
+
}
|
|
317
|
+
collectSchemaIssues(options) {
|
|
318
|
+
const allowed = options.policy.allowedOperationClasses;
|
|
319
|
+
const strict = allowed.includes("widening") || allowed.includes("destructive");
|
|
320
|
+
const verifyResult = verifySqlSchema({
|
|
321
|
+
contract: options.contract,
|
|
322
|
+
schema: options.schema,
|
|
323
|
+
strict,
|
|
324
|
+
typeMetadataRegistry: /* @__PURE__ */ new Map(),
|
|
325
|
+
frameworkComponents: options.frameworkComponents,
|
|
326
|
+
normalizeDefault: parsePostgresDefault,
|
|
327
|
+
normalizeNativeType: normalizeSchemaNativeType,
|
|
328
|
+
columnsCompatible: postgresColumnsCompatible,
|
|
329
|
+
resolveExistingEnumValues: createResolveExistingEnumValues(options.contract.storage)
|
|
330
|
+
});
|
|
331
|
+
const namespaceIssues = verifyPostgresNamespacePresence({
|
|
332
|
+
contract: options.contract,
|
|
333
|
+
schema: options.schema
|
|
334
|
+
});
|
|
335
|
+
if (namespaceIssues.length === 0) return verifyResult.schema.issues;
|
|
336
|
+
return [...namespaceIssues, ...verifyResult.schema.issues];
|
|
337
|
+
}
|
|
338
|
+
};
|
|
339
|
+
//#endregion
|
|
340
|
+
export { createPostgresMigrationPlanner as t };
|
|
341
|
+
|
|
342
|
+
//# sourceMappingURL=planner-y-bVvDFR.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"planner-y-bVvDFR.mjs","names":[],"sources":["../src/core/migrations/control-policy.ts","../src/core/migrations/verify-postgres-namespaces.ts","../src/core/migrations/planner.ts"],"sourcesContent":["import type { Contract } from '@prisma-next/contract/types';\nimport type { ControlPolicySubject } from '@prisma-next/family-sql/control';\nimport type { SchemaIssue } from '@prisma-next/framework-components/control';\nimport { UNBOUND_NAMESPACE_ID } from '@prisma-next/framework-components/ir';\nimport {\n isPostgresEnumStorageEntry,\n type SqlStorage,\n storageTableAt,\n} from '@prisma-next/sql-contract/types';\nimport { ifDefined } from '@prisma-next/utils/defined';\nimport { isPostgresSchema } from '../postgres-schema';\nimport type { PostgresOpFactoryCall } from './op-factory-call';\n\n/**\n * Factory calls that create a whole, previously-absent top-level storage\n * object. Used to decide whether `tolerated` permits a call (it only allows\n * creating absent objects, never modifying existing ones).\n *\n * Deliberately an explicit, closed set rather than a `factoryName`\n * create/alter/drop classification: it answers exactly one yes/no question\n * and is fail-closed. Any call not listed here — including future or\n * extension-contributed factories — is treated as NOT object-creation, so it\n * is suppressed under `tolerated` rather than permissively emitted.\n */\nconst OBJECT_CREATION_FACTORIES: ReadonlySet<string> = new Set<string>([\n 'createTable',\n 'createEnumType',\n 'createSchema',\n]);\n\nfunction createsNewTopLevelObject(call: PostgresOpFactoryCall): boolean {\n return OBJECT_CREATION_FACTORIES.has(call.factoryName);\n}\n\nfunction ddlSchemaNameForNamespace(contract: Contract<SqlStorage>, namespaceId: string): string {\n const namespace = contract.storage.namespaces[namespaceId];\n return isPostgresSchema(namespace) ? namespace.ddlSchemaName(contract.storage) : namespaceId;\n}\n\nfunction resolveNamespaceIdForTable(\n contract: Contract<SqlStorage>,\n tableName: string,\n ddlSchemaName: string | undefined,\n): string {\n for (const namespaceId of Object.keys(contract.storage.namespaces)) {\n const table = storageTableAt(contract.storage, namespaceId, tableName);\n if (!table) continue;\n if (\n ddlSchemaName === undefined ||\n ddlSchemaNameForNamespace(contract, namespaceId) === ddlSchemaName\n ) {\n return namespaceId;\n }\n }\n return UNBOUND_NAMESPACE_ID;\n}\n\nfunction resolveNamespaceIdForDdlSchema(\n contract: Contract<SqlStorage>,\n ddlSchemaName: string,\n): string {\n for (const namespaceId of Object.keys(contract.storage.namespaces)) {\n const ns = contract.storage.namespaces[namespaceId];\n if (isPostgresSchema(ns) && ns.ddlSchemaName(contract.storage) === ddlSchemaName) {\n return namespaceId;\n }\n if (namespaceId === ddlSchemaName) {\n return namespaceId;\n }\n }\n return UNBOUND_NAMESPACE_ID;\n}\n\ninterface PostgresCallFields {\n readonly schemaName?: string;\n readonly tableName?: string;\n readonly columnName?: string;\n readonly typeName?: string;\n}\n\nfunction postgresCallFields(call: PostgresOpFactoryCall): PostgresCallFields {\n return {\n ...ifDefined('schemaName', 'schemaName' in call ? call.schemaName : undefined),\n ...ifDefined('tableName', 'tableName' in call ? call.tableName : undefined),\n ...ifDefined('columnName', 'columnName' in call ? call.columnName : undefined),\n ...ifDefined('typeName', 'typeName' in call ? call.typeName : undefined),\n };\n}\n\nexport function formatPostgresControlPolicySubjectLabel(\n factoryName: string,\n subject: ControlPolicySubject | undefined,\n contract: Contract<SqlStorage>,\n): string {\n if (subject?.table) {\n const ddlSchema = ddlSchemaNameForNamespace(contract, subject.namespaceId);\n return `${factoryName}(${ddlSchema}.${subject.table})`;\n }\n if (subject?.typeName) {\n const ddlSchema = ddlSchemaNameForNamespace(contract, subject.namespaceId);\n return `${factoryName}(${ddlSchema}.${subject.typeName})`;\n }\n return factoryName;\n}\n\nexport function resolvePostgresCallControlPolicySubject(\n call: PostgresOpFactoryCall,\n contract: Contract<SqlStorage>,\n): ControlPolicySubject | undefined {\n const callFields = postgresCallFields(call);\n const createsNewObject = createsNewTopLevelObject(call);\n\n if (call.factoryName === 'createSchema' && callFields.schemaName) {\n return {\n namespaceId: resolveNamespaceIdForDdlSchema(contract, callFields.schemaName),\n createsNewObject,\n };\n }\n\n if (callFields.typeName && call.factoryName !== 'addColumn') {\n const namespaceId = callFields.schemaName\n ? resolveNamespaceIdForDdlSchema(contract, callFields.schemaName)\n : UNBOUND_NAMESPACE_ID;\n const ns = contract.storage.namespaces[namespaceId];\n const rawEnum =\n ns && 'enum' in ns && ns.enum != null ? ns.enum[callFields.typeName] : undefined;\n const controlPolicy = isPostgresEnumStorageEntry(rawEnum) ? rawEnum.control : undefined;\n return {\n namespaceId,\n ...ifDefined('explicitNodeControlPolicy', controlPolicy),\n typeName: callFields.typeName,\n createsNewObject,\n };\n }\n\n if (callFields.tableName) {\n const namespaceId = resolveNamespaceIdForTable(\n contract,\n callFields.tableName,\n callFields.schemaName,\n );\n const table = storageTableAt(contract.storage, namespaceId, callFields.tableName);\n const tableControlPolicy = table?.control;\n return {\n namespaceId,\n ...ifDefined('explicitNodeControlPolicy', tableControlPolicy),\n table: callFields.tableName,\n ...ifDefined('column', callFields.columnName),\n createsNewObject,\n };\n }\n\n if (callFields.schemaName) {\n return {\n namespaceId: resolveNamespaceIdForDdlSchema(contract, callFields.schemaName),\n createsNewObject,\n };\n }\n\n return undefined;\n}\n\n/**\n * Issue kinds that describe the absence of a whole, top-level Postgres\n * object — the same kinds `createsNewTopLevelObject` recognises for calls.\n * Used by {@link resolvePostgresIssueCreationFactoryName} to decide whether\n * a `tolerated` subject permits the issue to flow into the planner\n * (create-if-absent) and to seed the suppressed-subject warning's\n * `factoryName` when the planner is skipped.\n */\nconst POSTGRES_ISSUE_CREATION_FACTORY: Readonly<Record<string, string>> = Object.freeze({\n missing_schema: 'createSchema',\n missing_table: 'createTable',\n type_missing: 'createEnumType',\n});\n\nexport function resolvePostgresIssueCreationFactoryName(issue: SchemaIssue): string | undefined {\n return POSTGRES_ISSUE_CREATION_FACTORY[issue.kind];\n}\n\n/**\n * Resolve the control-policy subject coordinate for a single\n * {@link SchemaIssue}. Mirrors the resolution `resolvePostgresCallControlPolicySubject`\n * performs for a generated DDL call, but works *off the issue* — so the\n * planner can partition issues by effective policy before the diff engine\n * runs. `createsNewObject` is derived from the issue's kind: schema/table/\n * type-missing issues describe a brand-new top-level object; everything else\n * touches an existing object.\n *\n * An `extra_table` issue carries no contract namespace coordinate (the table\n * isn't in any contract namespace), so the subject's `namespaceId` falls\n * back to {@link UNBOUND_NAMESPACE_ID}; the call-side resolver does the same\n * for the `DropTableCall` it produces.\n */\nexport function resolvePostgresIssueControlPolicySubject(\n issue: SchemaIssue,\n contract: Contract<SqlStorage>,\n): ControlPolicySubject | undefined {\n const createsNewObject = POSTGRES_ISSUE_CREATION_FACTORY[issue.kind] !== undefined;\n\n if (issue.kind === 'missing_schema' && issue.namespaceId) {\n return { namespaceId: issue.namespaceId, createsNewObject };\n }\n\n if ('typeName' in issue && issue.typeName) {\n const namespaceId =\n 'namespaceId' in issue && issue.namespaceId ? issue.namespaceId : UNBOUND_NAMESPACE_ID;\n const ns = contract.storage.namespaces[namespaceId];\n const rawEnum = ns && 'enum' in ns && ns.enum != null ? ns.enum[issue.typeName] : undefined;\n const controlPolicy = isPostgresEnumStorageEntry(rawEnum) ? rawEnum.control : undefined;\n return {\n namespaceId,\n ...ifDefined('explicitNodeControlPolicy', controlPolicy),\n typeName: issue.typeName,\n createsNewObject,\n };\n }\n\n if ('table' in issue && issue.table) {\n const namespaceId =\n 'namespaceId' in issue && issue.namespaceId\n ? issue.namespaceId\n : resolveNamespaceIdForTable(contract, issue.table, undefined);\n const table = storageTableAt(contract.storage, namespaceId, issue.table);\n return {\n namespaceId,\n ...ifDefined('explicitNodeControlPolicy', table?.control),\n table: issue.table,\n ...ifDefined('column', 'column' in issue ? issue.column : undefined),\n createsNewObject,\n };\n }\n\n return undefined;\n}\n","import type { Contract } from '@prisma-next/contract/types';\nimport type { SchemaIssue } from '@prisma-next/framework-components/control';\nimport { UNBOUND_NAMESPACE_ID } from '@prisma-next/framework-components/ir';\nimport type { SqlStorage } from '@prisma-next/sql-contract/types';\nimport type { SqlSchemaIR } from '@prisma-next/sql-schema-ir/types';\nimport { isPostgresSchema } from '../postgres-schema';\n\n/**\n * Resolves the live-database schema name for a given namespace\n * coordinate. Mirrors `resolveDdlSchemaForNamespace` in\n * `planner-strategies.ts` so the verifier's projection and the\n * planner's projection always agree — Postgres-aware namespaces (the\n * production path) dispatch to `ddlSchemaName(storage)`, and bare\n * object payloads (used by some tests) fall back to the coordinate\n * itself.\n */\nfunction resolveDdlSchemaName(storage: SqlStorage, namespaceId: string): string {\n const namespace = storage.namespaces[namespaceId];\n if (isPostgresSchema(namespace)) {\n return namespace.ddlSchemaName(storage);\n }\n return namespaceId;\n}\n\n/**\n * Reads the introspected list of schema names from the Postgres-flavoured\n * annotations slot on the schema IR. Defaults to the always-present\n * `public` schema when introspection did not populate the slot — a fresh\n * Postgres database always carries `public` (unless an operator dropped\n * it manually), so any verifier path that runs without an enriched\n * introspection still suppresses the redundant `CREATE SCHEMA \"public\"`.\n *\n * Production introspection (`PostgresControlAdapter.introspect`) is the\n * authoritative source: it queries `pg_namespace` and writes every\n * non-system schema into `annotations.pg.existingSchemas`. Tests that\n * want to assert against a richer initial state pass the slot\n * explicitly via the schema IR.\n */\nfunction existingSchemasFromSchema(schema: SqlSchemaIR): readonly string[] {\n const annotations = (schema as { annotations?: { pg?: { existingSchemas?: unknown } } })\n .annotations;\n const slot = annotations?.pg?.existingSchemas;\n if (Array.isArray(slot)) {\n return slot.filter((s): s is string => typeof s === 'string');\n }\n return ['public'];\n}\n\n/**\n * Emits a `missing_schema` issue for every contract-declared Postgres\n * namespace whose live container does not yet exist.\n *\n * A namespace's live container is the schema returned by its\n * polymorphic `ddlSchemaName(storage)` method — named schemas resolve\n * to their own id; the unbound singleton returns `UNBOUND_NAMESPACE_ID`\n * and is skipped explicitly (late-bound namespaces have no fixed DDL\n * schema). Issues are emitted only when the resolved name is a real,\n * creatable schema (not the unbound sentinel) and is missing from the\n * introspected list. `public` is suppressed implicitly because the\n * introspection (or its sensible default) always carries it.\n *\n * Each emitted issue stamps `namespaceId` with the contract namespace\n * coordinate so the downstream `mapIssueToCall` re-resolves the DDL\n * schema name through the same polymorphic path — keeping the\n * coordinate, not the resolved name, as the issue's stable identity.\n */\nexport function verifyPostgresNamespacePresence(input: {\n readonly contract: Contract<SqlStorage>;\n readonly schema: SqlSchemaIR;\n}): readonly SchemaIssue[] {\n const { contract, schema } = input;\n const existing = new Set(existingSchemasFromSchema(schema));\n const issues: SchemaIssue[] = [];\n const namespaceIds = Object.keys(contract.storage.namespaces).sort();\n for (const namespaceId of namespaceIds) {\n if (namespaceId === UNBOUND_NAMESPACE_ID) continue;\n const ddlName = resolveDdlSchemaName(contract.storage, namespaceId);\n if (ddlName === UNBOUND_NAMESPACE_ID) continue;\n if (existing.has(ddlName)) continue;\n issues.push({\n kind: 'missing_schema',\n namespaceId,\n message: `Schema \"${ddlName}\" is missing from database`,\n });\n }\n return issues;\n}\n","import type { Contract } from '@prisma-next/contract/types';\nimport type {\n MigrationOperationPolicy,\n SqlMigrationPlannerPlanOptions,\n SqlPlannerConflict,\n SqlPlannerFailureResult,\n} from '@prisma-next/family-sql/control';\nimport {\n extractCodecControlHooks,\n partitionCallsByControlPolicy,\n partitionIssuesByControlPolicy,\n planFieldEventOperations,\n plannerFailure,\n} from '@prisma-next/family-sql/control';\nimport { verifySqlSchema } from '@prisma-next/family-sql/schema-verify';\nimport type { TargetBoundComponentDescriptor } from '@prisma-next/framework-components/components';\nimport type {\n MigrationPlanner,\n MigrationPlanWithAuthoringSurface,\n MigrationScaffoldContext,\n SchemaIssue,\n} from '@prisma-next/framework-components/control';\nimport { UNBOUND_NAMESPACE_ID } from '@prisma-next/framework-components/ir';\nimport { blindCast } from '@prisma-next/utils/casts';\nimport { postgresColumnsCompatible } from '../column-type-compatibility';\nimport { parsePostgresDefault } from '../default-normalizer';\nimport { normalizeSchemaNativeType } from '../native-type-normalizer';\nimport {\n formatPostgresControlPolicySubjectLabel,\n resolvePostgresCallControlPolicySubject,\n resolvePostgresIssueControlPolicySubject,\n resolvePostgresIssueCreationFactoryName,\n} from './control-policy';\nimport { createResolveExistingEnumValues } from './enum-planning';\nimport { planIssues } from './issue-planner';\nimport type { PostgresOpFactoryCall } from './op-factory-call';\nimport { TypeScriptRenderablePostgresMigration } from './planner-produced-postgres-migration';\nimport { postgresPlannerStrategies } from './planner-strategies';\nimport { verifyPostgresNamespacePresence } from './verify-postgres-namespaces';\n\ntype PlannerFrameworkComponents = SqlMigrationPlannerPlanOptions extends {\n readonly frameworkComponents: infer T;\n}\n ? T\n : ReadonlyArray<unknown>;\n\ntype PlannerOptionsWithComponents = SqlMigrationPlannerPlanOptions & {\n readonly frameworkComponents: PlannerFrameworkComponents;\n};\n\ntype VerifySqlSchemaOptionsWithComponents = Parameters<typeof verifySqlSchema>[0] & {\n readonly frameworkComponents: PlannerFrameworkComponents;\n};\n\nexport function createPostgresMigrationPlanner(): PostgresMigrationPlanner {\n return new PostgresMigrationPlanner();\n}\n\n/**\n * Result of `PostgresMigrationPlanner.plan()`. A discriminated union whose\n * success variant carries a `TypeScriptRenderablePostgresMigration` — a\n * migration object that both the CLI (via `renderTypeScript()`) and the\n * SQL-typed callers (via `operations`, `describe()`, etc.) consume\n * uniformly.\n */\nexport type PostgresPlanResult =\n | {\n readonly kind: 'success';\n readonly plan: TypeScriptRenderablePostgresMigration;\n readonly warnings?: readonly SqlPlannerConflict[];\n }\n | SqlPlannerFailureResult;\n\n/**\n * Postgres migration planner — a thin wrapper over `planIssues`.\n *\n * `plan()` verifies the live schema against the target contract (producing\n * `SchemaIssue[]`) and delegates to `planIssues` with the unified\n * `postgresPlannerStrategies` list: enum-change, NOT-NULL backfill,\n * type-change, nullable-tightening, codec-hook storage types,\n * component-declared dependency installs, and shared-temp-default /\n * empty-table-guarded NOT-NULL add-column. The same strategy list runs for\n * `migration plan`, `db update`, and `db init`; behavior diverges purely on\n * `policy.allowedOperationClasses` (the data-safe strategies short-circuit\n * when `'data'` is excluded). The issue planner applies operation-class\n * policy gates and emits a single `PostgresOpFactoryCall[]` that drives both\n * the runtime-ops view (via `renderOps`) and the `renderTypeScript()`\n * authoring surface.\n */\nexport class PostgresMigrationPlanner implements MigrationPlanner<'sql', 'postgres'> {\n plan(options: {\n readonly contract: unknown;\n readonly schema: unknown;\n readonly policy: MigrationOperationPolicy;\n /**\n * The \"from\" contract (state the planner assumes the database starts\n * at), or `null` for reconciliation flows. Only `migration plan` ever\n * supplies a non-null value; `db update` / `db init` reconcile against\n * the live schema and pass `null`. When present alongside the\n * `'data'` operation class, strategies that need from/to column-shape\n * comparisons (unsafe type change, nullability tightening) activate.\n *\n * Typed as the framework `Contract | null` to satisfy the\n * `MigrationPlanner` interface contract; `planSql` narrows to the SQL\n * shape via `SqlMigrationPlannerPlanOptions`. Used to populate\n * `describe().from` on the produced plan as\n * `fromContract?.storage.storageHash ?? null`.\n */\n readonly fromContract: Contract | null;\n readonly schemaName?: string;\n readonly frameworkComponents: ReadonlyArray<TargetBoundComponentDescriptor<'sql', string>>;\n /**\n * Contract space this plan applies to. Stamped onto the produced\n * {@link TypeScriptRenderablePostgresMigration.spaceId} so the runner keys\n * the marker row by the right space.\n */\n readonly spaceId: string;\n }): PostgresPlanResult {\n return this.planSql(options as SqlMigrationPlannerPlanOptions);\n }\n\n emptyMigration(\n context: MigrationScaffoldContext,\n spaceId: string,\n ): MigrationPlanWithAuthoringSurface {\n return new TypeScriptRenderablePostgresMigration(\n [],\n {\n from: context.fromHash,\n to: context.toHash,\n },\n spaceId,\n );\n }\n\n private planSql(options: SqlMigrationPlannerPlanOptions): PostgresPlanResult {\n const schemaName =\n options.schemaName ??\n Object.keys(options.contract.storage.namespaces).find((id) => id !== UNBOUND_NAMESPACE_ID) ??\n UNBOUND_NAMESPACE_ID;\n const policyResult = this.ensureAdditivePolicy(options.policy);\n if (policyResult) {\n return policyResult;\n }\n\n const schemaIssues = this.collectSchemaIssues(options);\n const codecHooks = extractCodecControlHooks(options.frameworkComponents);\n const storageTypes = options.contract.storage.types ?? {};\n\n // Input-side control-policy partition. `external` / `observed` subjects\n // — and non-creation issues for `tolerated` subjects — are dropped from\n // the planner's input entirely; the planner never observes them, never\n // diffs them, never generates DDL for them. Suppression warnings are\n // built directly from the suppressed partition (one per subject), so the\n // user-visible message survives even when the planner would have failed\n // to model the subject's live shape.\n const issuePartition = partitionIssuesByControlPolicy({\n issues: schemaIssues,\n contract: options.contract,\n resolveControlPolicySubject: (issue) =>\n resolvePostgresIssueControlPolicySubject(issue, options.contract),\n resolveCreationFactoryName: resolvePostgresIssueCreationFactoryName,\n formatSubjectLabel: (factoryName, subject) =>\n formatPostgresControlPolicySubjectLabel(factoryName, subject, options.contract),\n });\n\n const result = planIssues({\n issues: issuePartition.plannable,\n toContract: options.contract,\n // `fromContract` is only supplied by `migration plan`. It is `null` for\n // `db update` / `db init`, which means data-safety strategies needing\n // from/to comparisons (unsafe type change, nullable tightening) are\n // inapplicable there — reconciliation falls through to\n // `mapIssueToCall`'s direct destructive handlers.\n fromContract: options.fromContract,\n schemaName,\n codecHooks,\n storageTypes,\n schema: options.schema,\n policy: options.policy,\n frameworkComponents: options.frameworkComponents,\n strategies: postgresPlannerStrategies,\n });\n\n if (!result.ok) {\n return plannerFailure(result.failure);\n }\n\n // Inline `onFieldEvent`-emitted ops after structural DDL. The fixed\n // ordering is `structural → added → dropped → altered`, with\n // within-group sorting by `(tableName, fieldName)` so re-emits are\n // byte-stable. The hook fires only at the application emitter —\n // extension-space planning never reaches this helper.\n const fieldEventOps = planFieldEventOperations({\n priorContract: options.fromContract,\n newContract: options.contract,\n codecHooks,\n });\n // Codec hook ops are target-agnostic `OpFactoryCall`; Postgres planning\n // lifts them at this integration boundary (see field-event-planner JSDoc).\n const fieldEventPostgresCalls = blindCast<\n readonly PostgresOpFactoryCall[],\n 'Codec hook ops conform to PostgresOpFactoryCall at the app emitter boundary'\n >(fieldEventOps);\n const fieldEventPartition = partitionCallsByControlPolicy({\n calls: fieldEventPostgresCalls,\n contract: options.contract,\n resolveControlPolicySubject: (call) =>\n resolvePostgresCallControlPolicySubject(call, options.contract),\n resolveFactoryName: (call) => call.factoryName,\n formatSubjectLabel: (factoryName, subject) =>\n formatPostgresControlPolicySubjectLabel(factoryName, subject, options.contract),\n });\n const calls = [...result.value.calls, ...fieldEventPartition.kept];\n const warnings: SqlPlannerConflict[] = [\n ...issuePartition.warnings,\n ...fieldEventPartition.warnings,\n ];\n\n return Object.freeze({\n kind: 'success' as const,\n plan: new TypeScriptRenderablePostgresMigration(\n calls,\n {\n from: options.fromContract?.storage.storageHash ?? null,\n to: options.contract.storage.storageHash,\n },\n options.spaceId,\n ),\n ...(warnings.length > 0 ? { warnings: Object.freeze(warnings) } : {}),\n });\n }\n\n private ensureAdditivePolicy(policy: MigrationOperationPolicy) {\n if (!policy.allowedOperationClasses.includes('additive')) {\n return plannerFailure([\n {\n kind: 'unsupportedOperation',\n summary: 'Migration planner requires additive operations be allowed',\n why: 'The planner requires the \"additive\" operation class to be allowed in the policy.',\n },\n ]);\n }\n return null;\n }\n\n private collectSchemaIssues(options: PlannerOptionsWithComponents): readonly SchemaIssue[] {\n // `db init` uses additive-only policy and intentionally ignores extra\n // schema objects. Any reconciliation-capable policy (widening or\n // destructive) must inspect extras to reconcile strict equality.\n const allowed = options.policy.allowedOperationClasses;\n const strict = allowed.includes('widening') || allowed.includes('destructive');\n const verifyOptions: VerifySqlSchemaOptionsWithComponents = {\n contract: options.contract,\n schema: options.schema,\n strict,\n typeMetadataRegistry: new Map(),\n frameworkComponents: options.frameworkComponents,\n normalizeDefault: parsePostgresDefault,\n normalizeNativeType: normalizeSchemaNativeType,\n columnsCompatible: postgresColumnsCompatible,\n resolveExistingEnumValues: createResolveExistingEnumValues(options.contract.storage),\n };\n const verifyResult = verifySqlSchema(verifyOptions);\n // Schema presence is a Postgres-specific concern (no equivalent in\n // SQLite / Mongo), so the issue emission lives in the target layer\n // rather than in the family verifier. Stitch it in here so a single\n // `SchemaIssue[]` flows through `planIssues` and the planner emits\n // CREATE SCHEMA in the dep bucket before any CreateTableCall.\n const namespaceIssues = verifyPostgresNamespacePresence({\n contract: options.contract,\n schema: options.schema,\n });\n if (namespaceIssues.length === 0) {\n return verifyResult.schema.issues;\n }\n return [...namespaceIssues, ...verifyResult.schema.issues];\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAwBA,MAAM,4BAAiD,IAAI,IAAY;CACrE;CACA;CACA;AACF,CAAC;AAED,SAAS,yBAAyB,MAAsC;CACtE,OAAO,0BAA0B,IAAI,KAAK,WAAW;AACvD;AAEA,SAAS,0BAA0B,UAAgC,aAA6B;CAC9F,MAAM,YAAY,SAAS,QAAQ,WAAW;CAC9C,OAAO,iBAAiB,SAAS,IAAI,UAAU,cAAc,SAAS,OAAO,IAAI;AACnF;AAEA,SAAS,2BACP,UACA,WACA,eACQ;CACR,KAAK,MAAM,eAAe,OAAO,KAAK,SAAS,QAAQ,UAAU,GAAG;EAElE,IAAI,CADU,eAAe,SAAS,SAAS,aAAa,SACnD,GAAG;EACZ,IACE,kBAAkB,KAAA,KAClB,0BAA0B,UAAU,WAAW,MAAM,eAErD,OAAO;CAEX;CACA,OAAO;AACT;AAEA,SAAS,+BACP,UACA,eACQ;CACR,KAAK,MAAM,eAAe,OAAO,KAAK,SAAS,QAAQ,UAAU,GAAG;EAClE,MAAM,KAAK,SAAS,QAAQ,WAAW;EACvC,IAAI,iBAAiB,EAAE,KAAK,GAAG,cAAc,SAAS,OAAO,MAAM,eACjE,OAAO;EAET,IAAI,gBAAgB,eAClB,OAAO;CAEX;CACA,OAAO;AACT;AASA,SAAS,mBAAmB,MAAiD;CAC3E,OAAO;EACL,GAAG,UAAU,cAAc,gBAAgB,OAAO,KAAK,aAAa,KAAA,CAAS;E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EAC7D,IAAI,CAAC,OAAO,wBAAwB,SAAS,UAAU,GACrD,OAAO,eAAe,CACpB;GACE,MAAM;GACN,SAAS;GACT,KAAK;EACP,CACF,CAAC;EAEH,OAAO;CACT;CAEA,oBAA4B,SAA+D;EAIzF,MAAM,UAAU,QAAQ,OAAO;EAC/B,MAAM,SAAS,QAAQ,SAAS,UAAU,KAAK,QAAQ,SAAS,aAAa;EAY7E,MAAM,eAAe,gBAAgB;GAVnC,UAAU,QAAQ;GAClB,QAAQ,QAAQ;GAChB;GACA,sCAAsB,IAAI,IAAI;GAC9B,qBAAqB,QAAQ;GAC7B,kBAAkB;GAClB,qBAAqB;GACrB,mBAAmB;GACnB,2BAA2B,gCAAgC,QAAQ,SAAS,OAAO;EAEpC,CAAC;EAMlD,MAAM,kBAAkB,gCAAgC;GACtD,UAAU,QAAQ;GAClB,QAAQ,QAAQ;EAClB,CAAC;EACD,IAAI,gBAAgB,WAAW,GAC7B,OAAO,aAAa,OAAO;EAE7B,OAAO,CAAC,GAAG,iBAAiB,GAAG,aAAa,OAAO,MAAM;CAC3D;AACF"}
|
package/dist/planner.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { t as TypeScriptRenderablePostgresMigration } from "./planner-produced-postgres-migration-RdjC7aUC.mjs";
|
|
2
|
-
import { MigrationOperationPolicy, SqlPlannerFailureResult } from "@prisma-next/family-sql/control";
|
|
2
|
+
import { MigrationOperationPolicy, SqlPlannerConflict, SqlPlannerFailureResult } from "@prisma-next/family-sql/control";
|
|
3
3
|
import { MigrationPlanWithAuthoringSurface, MigrationPlanner, MigrationScaffoldContext } from "@prisma-next/framework-components/control";
|
|
4
4
|
import { Contract } from "@prisma-next/contract/types";
|
|
5
5
|
import { TargetBoundComponentDescriptor } from "@prisma-next/framework-components/components";
|
|
@@ -16,6 +16,7 @@ declare function createPostgresMigrationPlanner(): PostgresMigrationPlanner;
|
|
|
16
16
|
type PostgresPlanResult = {
|
|
17
17
|
readonly kind: 'success';
|
|
18
18
|
readonly plan: TypeScriptRenderablePostgresMigration;
|
|
19
|
+
readonly warnings?: readonly SqlPlannerConflict[];
|
|
19
20
|
} | SqlPlannerFailureResult;
|
|
20
21
|
/**
|
|
21
22
|
* Postgres migration planner — a thin wrapper over `planIssues`.
|
package/dist/planner.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"planner.d.mts","names":[],"sources":["../src/core/migrations/planner.ts"],"mappings":";;;;;;;
|
|
1
|
+
{"version":3,"file":"planner.d.mts","names":[],"sources":["../src/core/migrations/planner.ts"],"mappings":";;;;;;;iBAsDgB,8BAAA,CAAA,GAAkC,wBAAwB;;AAA1E;;;;AAA0E;AAW1E;KAAY,kBAAA;EAAA,SAEG,IAAA;EAAA,SACA,IAAA,EAAM,qCAAA;EAAA,SACN,QAAA,YAAoB,kBAAA;AAAA,IAE/B,uBAAA;;;;;;;;;;AAAuB;AAkB3B;;;;;;cAAa,wBAAA,YAAoC,gBAAA;EAC/C,IAAA,CAAK,OAAA;IAAA,SACM,QAAA;IAAA,SACA,MAAA;IAAA,SACA,MAAA,EAAQ,wBAAA;IAJ4C;;;;;;;;;;;;;;IAAA,SAmBpD,YAAA,EAAc,QAAA;IAAA,SACd,UAAA;IAAA,SACA,mBAAA,EAAqB,aAAA,CAAc,8BAAA;IAW9C;;;;;IAAA,SALW,OAAA;EAAA,IACP,kBAAA;EAIJ,cAAA,CACE,OAAA,EAAS,wBAAA,EACT,OAAA,WACC,iCAAA;EAAA,QAWK,OAAA;EAAA,QAkGA,oBAAA;EAAA,QAaA,mBAAA;AAAA"}
|
package/dist/planner.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { t as createPostgresMigrationPlanner } from "./planner-
|
|
1
|
+
import { t as createPostgresMigrationPlanner } from "./planner-y-bVvDFR.mjs";
|
|
2
2
|
export { createPostgresMigrationPlanner };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { t as errorPostgresMigrationStackMissing } from "./errors-
|
|
2
|
-
import { t as dataTransform } from "./data-transform-
|
|
1
|
+
import { t as errorPostgresMigrationStackMissing } from "./errors-De185dnO.mjs";
|
|
2
|
+
import { t as dataTransform } from "./data-transform-DIYwbe4S.mjs";
|
|
3
3
|
import { Migration } from "@prisma-next/family-sql/migration";
|
|
4
4
|
//#region src/core/migrations/postgres-migration.ts
|
|
5
5
|
/**
|
|
@@ -48,4 +48,4 @@ var PostgresMigration = class extends Migration {
|
|
|
48
48
|
//#endregion
|
|
49
49
|
export { PostgresMigration as t };
|
|
50
50
|
|
|
51
|
-
//# sourceMappingURL=postgres-migration-
|
|
51
|
+
//# sourceMappingURL=postgres-migration-BnDg_Nj0.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"postgres-migration-
|
|
1
|
+
{"version":3,"file":"postgres-migration-BnDg_Nj0.mjs","names":["SqlMigration"],"sources":["../src/core/migrations/postgres-migration.ts"],"sourcesContent":["import type { Contract } from '@prisma-next/contract/types';\nimport type { SqlMigrationPlanOperation } from '@prisma-next/family-sql/control';\nimport type { SqlControlAdapter } from '@prisma-next/family-sql/control-adapter';\nimport { Migration as SqlMigration } from '@prisma-next/family-sql/migration';\nimport type { ControlStack } from '@prisma-next/framework-components/control';\nimport type { SqlStorage } from '@prisma-next/sql-contract/types';\nimport { errorPostgresMigrationStackMissing } from '../errors';\nimport { type DataTransformOptions, dataTransform } from './operations/data-transform';\nimport type { PostgresPlanTargetDetails } from './planner-target-details';\n\n/**\n * Target-owned base class for Postgres migrations.\n *\n * Fixes the `SqlMigration` generic to `PostgresPlanTargetDetails` and the\n * abstract `targetId` to the Postgres target-id string literal, so both\n * user-authored migrations and renderer-generated scaffolds (the output of\n * `renderCallsToTypeScript`) can extend `PostgresMigration` directly without\n * redeclaring target-local identity.\n *\n * Mirrors `MongoMigration` in `@prisma-next/family-mongo`: the renderer\n * emits `extends Migration` against a facade re-export of this class\n * from `@prisma-next/postgres/migration`, keeping the authoring surface\n * target-scoped rather than family-scoped.\n *\n * The constructor materializes a single Postgres `SqlControlAdapter` from\n * `stack.adapter.create(stack)` and stores it; the protected `dataTransform`\n * instance method forwards to the free `dataTransform` factory with that\n * stored adapter, so user migrations can write `this.dataTransform(...)`\n * without threading the adapter through every call.\n */\nexport abstract class PostgresMigration extends SqlMigration<\n PostgresPlanTargetDetails,\n 'postgres'\n> {\n readonly targetId = 'postgres' as const;\n\n /**\n * Materialized Postgres control adapter, created once per migration\n * instance from the injected stack. `undefined` only when the migration\n * was instantiated without a stack (test fixtures); `dataTransform`\n * throws in that case to surface the misuse.\n */\n protected readonly controlAdapter: SqlControlAdapter<'postgres'> | undefined;\n\n constructor(stack?: ControlStack<'sql', 'postgres'>) {\n super(stack);\n // The descriptor `create()` is typed as the wider `ControlAdapterInstance`;\n // the Postgres descriptor concretely returns a `SqlControlAdapter<'postgres'>`,\n // so the cast holds for any Postgres-target stack assembled at runtime.\n this.controlAdapter = stack?.adapter\n ? (stack.adapter.create(stack) as SqlControlAdapter<'postgres'>)\n : undefined;\n }\n\n /**\n * Instance-method wrapper around the free `dataTransform` factory that\n * supplies the stored control adapter. Authors call this from inside\n * `get operations()`; the adapter argument is hidden from the call site.\n */\n protected dataTransform<TContract extends Contract<SqlStorage>>(\n contract: TContract,\n name: string,\n options: DataTransformOptions,\n ): SqlMigrationPlanOperation<PostgresPlanTargetDetails> {\n if (!this.controlAdapter) {\n throw errorPostgresMigrationStackMissing();\n }\n return dataTransform(contract, name, options, this.controlAdapter);\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AA8BA,IAAsB,oBAAtB,cAAgDA,UAG9C;CACA,WAAoB;;;;;;;CAQpB;CAEA,YAAY,OAAyC;EACnD,MAAM,KAAK;EAIX,KAAK,iBAAiB,OAAO,UACxB,MAAM,QAAQ,OAAO,KAAK,IAC3B,KAAA;CACN;;;;;;CAOA,cACE,UACA,MACA,SACsD;EACtD,IAAI,CAAC,KAAK,gBACR,MAAM,mCAAmC;EAE3C,OAAO,cAAc,UAAU,MAAM,SAAS,KAAK,cAAc;CACnE;AACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"render-ops-
|
|
1
|
+
{"version":3,"file":"render-ops-BpU-Qv06.mjs","names":[],"sources":["../src/core/migrations/render-ops.ts"],"sourcesContent":["import type { SqlMigrationPlanOperation } from '@prisma-next/family-sql/control';\nimport type { OpFactoryCall } from '@prisma-next/framework-components/control';\nimport type { PostgresPlanTargetDetails } from './planner-target-details';\n\ntype Op = SqlMigrationPlanOperation<PostgresPlanTargetDetails>;\n\n/**\n * Asserts an op materialised by an `OpFactoryCall` targets postgres. The\n * extension surface lets any contributor emit calls, so this is the\n * integration boundary where a stray non-postgres op would otherwise\n * silently flow through to postgres-shaped renderers — exactly the\n * place to fail loudly with op metadata (`id` + `target.id`).\n */\nfunction assertPostgresOp(\n op: ReturnType<OpFactoryCall['toOp']>,\n callFactoryName: string,\n): asserts op is Op {\n const targetId = (op as Partial<Op>).target?.id;\n if (targetId !== 'postgres') {\n throw new Error(\n `renderOps: expected postgres op but got target.id=\"${String(targetId)}\" for op.id=\"${op.id}\" (factoryName=\"${callFactoryName}\"). An OpFactoryCall produced an op for a different target on the postgres planner path; check the call's target binding.`,\n );\n }\n}\n\nexport function renderOps(calls: readonly OpFactoryCall[]): Op[] {\n return calls.map((c) => {\n const op = c.toOp();\n assertPostgresOp(op, c.factoryName);\n return op;\n });\n}\n"],"mappings":";;;;;;;;AAaA,SAAS,iBACP,IACA,iBACkB;CAClB,MAAM,WAAY,GAAmB,QAAQ;CAC7C,IAAI,aAAa,YACf,MAAM,IAAI,MACR,sDAAsD,OAAO,QAAQ,EAAE,eAAe,GAAG,GAAG,kBAAkB,gBAAgB,0HAChI;AAEJ;AAEA,SAAgB,UAAU,OAAuC;CAC/D,OAAO,MAAM,KAAK,MAAM;EACtB,MAAM,KAAK,EAAE,KAAK;EAClB,iBAAiB,IAAI,EAAE,WAAW;EAClC,OAAO;CACT,CAAC;AACH"}
|
package/dist/render-ops.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { t as renderOps } from "./render-ops-
|
|
1
|
+
import { t as renderOps } from "./render-ops-BpU-Qv06.mjs";
|
|
2
2
|
export { renderOps };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"render-typescript-
|
|
1
|
+
{"version":3,"file":"render-typescript-D9O7aOS_.mjs","names":[],"sources":["../src/core/migrations/render-typescript.ts"],"sourcesContent":["/**\n * Polymorphic TypeScript emitter for the Postgres migration IR.\n *\n * Each `OpFactoryCall` renders itself via `renderTypeScript()` and\n * declares its own `importRequirements()`; this file just composes the module\n * source around those contributions. The design mirrors the Mongo target's\n * `render-typescript.ts` deliberately — byte-for-byte alignment isn't required\n * (different factory module specifiers, different base-class name) but the\n * shape is, so future consolidation to a framework-level helper is mechanical.\n */\n\nimport type { OpFactoryCall } from '@prisma-next/framework-components/control';\nimport { detectScaffoldRuntime, shebangLineFor } from '@prisma-next/migration-tools/migration-ts';\nimport { type ImportRequirement, renderImports } from '@prisma-next/ts-render';\n\nexport interface RenderMigrationMeta {\n readonly from: string | null;\n readonly to: string;\n}\n\n/**\n * Always-present base imports for the rendered scaffold. Both come from\n * `@prisma-next/postgres/migration` so an authored Postgres\n * `migration.ts` only needs a single dependency for its base class and\n * its CLI entrypoint:\n *\n * - `Migration` — the facade re-export fixes the `SqlMigration`\n * generic to `PostgresPlanTargetDetails` and the abstract `targetId`\n * to `'postgres'`, so user-authored migrations don't need to thread\n * target-details or redeclare `targetId`.\n * - `MigrationCLI` — the migration-file CLI entrypoint, re-exported from\n * `@prisma-next/cli/migration-cli`. Loads `prisma-next.config.ts`,\n * assembles a `ControlStack`, and instantiates the migration class.\n * The migration file owns this dependency directly: pulling CLI\n * machinery in at script run time is acceptable because the script's\n * whole purpose is to be invoked from the project that owns the\n * config.\n */\nconst BASE_IMPORTS: readonly ImportRequirement[] = [\n { moduleSpecifier: '@prisma-next/postgres/migration', symbol: 'Migration' },\n { moduleSpecifier: '@prisma-next/postgres/migration', symbol: 'MigrationCLI' },\n];\n\nexport function renderCallsToTypeScript(\n calls: ReadonlyArray<OpFactoryCall>,\n meta: RenderMigrationMeta,\n): string {\n const imports = buildImports(calls);\n const operationsBody = calls.map((c) => c.renderTypeScript()).join(',\\n');\n\n return [\n shebangLineFor(detectScaffoldRuntime()),\n imports,\n '',\n 'export default class M extends Migration {',\n buildDescribeMethod(meta),\n ' override get operations() {',\n ' return [',\n indent(operationsBody, 6),\n ' ];',\n ' }',\n '}',\n '',\n 'MigrationCLI.run(import.meta.url, M);',\n '',\n ].join('\\n');\n}\n\nfunction buildImports(calls: ReadonlyArray<OpFactoryCall>): string {\n const requirements: ImportRequirement[] = [...BASE_IMPORTS];\n for (const call of calls) {\n for (const req of call.importRequirements()) {\n requirements.push(req);\n }\n }\n return renderImports(requirements);\n}\n\nfunction buildDescribeMethod(meta: RenderMigrationMeta): string {\n const lines: string[] = [];\n lines.push(' override describe() {');\n lines.push(' return {');\n lines.push(` from: ${JSON.stringify(meta.from)},`);\n lines.push(` to: ${JSON.stringify(meta.to)},`);\n lines.push(' };');\n lines.push(' }');\n lines.push('');\n return lines.join('\\n');\n}\n\nfunction indent(text: string, spaces: number): string {\n const pad = ' '.repeat(spaces);\n return text\n .split('\\n')\n .map((line) => (line.trim() ? `${pad}${line}` : line))\n .join('\\n');\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAsCA,MAAM,eAA6C,CACjD;CAAE,iBAAiB;CAAmC,QAAQ;AAAY,GAC1E;CAAE,iBAAiB;CAAmC,QAAQ;AAAe,CAC/E;AAEA,SAAgB,wBACd,OACA,MACQ;CACR,MAAM,UAAU,aAAa,KAAK;CAClC,MAAM,iBAAiB,MAAM,KAAK,MAAM,EAAE,iBAAiB,CAAC,EAAE,KAAK,KAAK;CAExE,OAAO;EACL,eAAe,sBAAsB,CAAC;EACtC;EACA;EACA;EACA,oBAAoB,IAAI;EACxB;EACA;EACA,OAAO,gBAAgB,CAAC;EACxB;EACA;EACA;EACA;EACA;EACA;CACF,EAAE,KAAK,IAAI;AACb;AAEA,SAAS,aAAa,OAA6C;CACjE,MAAM,eAAoC,CAAC,GAAG,YAAY;CAC1D,KAAK,MAAM,QAAQ,OACjB,KAAK,MAAM,OAAO,KAAK,mBAAmB,GACxC,aAAa,KAAK,GAAG;CAGzB,OAAO,cAAc,YAAY;AACnC;AAEA,SAAS,oBAAoB,MAAmC;CAC9D,MAAM,QAAkB,CAAC;CACzB,MAAM,KAAK,yBAAyB;CACpC,MAAM,KAAK,cAAc;CACzB,MAAM,KAAK,eAAe,KAAK,UAAU,KAAK,IAAI,EAAE,EAAE;CACtD,MAAM,KAAK,aAAa,KAAK,UAAU,KAAK,EAAE,EAAE,EAAE;CAClD,MAAM,KAAK,QAAQ;CACnB,MAAM,KAAK,KAAK;CAChB,MAAM,KAAK,EAAE;CACb,OAAO,MAAM,KAAK,IAAI;AACxB;AAEA,SAAS,OAAO,MAAc,QAAwB;CACpD,MAAM,MAAM,IAAI,OAAO,MAAM;CAC7B,OAAO,KACJ,MAAM,IAAI,EACV,KAAK,SAAU,KAAK,KAAK,IAAI,GAAG,MAAM,SAAS,IAAK,EACpD,KAAK,IAAI;AACd"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { t as renderCallsToTypeScript } from "./render-typescript-
|
|
1
|
+
import { t as renderCallsToTypeScript } from "./render-typescript-D9O7aOS_.mjs";
|
|
2
2
|
export { renderCallsToTypeScript };
|
package/package.json
CHANGED
|
@@ -1,32 +1,32 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@prisma-next/target-postgres",
|
|
3
|
-
"version": "0.12.0-dev.
|
|
3
|
+
"version": "0.12.0-dev.29",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"sideEffects": false,
|
|
7
7
|
"description": "Postgres target pack for Prisma Next",
|
|
8
8
|
"dependencies": {
|
|
9
|
-
"@prisma-next/cli": "0.12.0-dev.
|
|
10
|
-
"@prisma-next/contract": "0.12.0-dev.
|
|
11
|
-
"@prisma-next/errors": "0.12.0-dev.
|
|
12
|
-
"@prisma-next/family-sql": "0.12.0-dev.
|
|
13
|
-
"@prisma-next/framework-components": "0.12.0-dev.
|
|
14
|
-
"@prisma-next/migration-tools": "0.12.0-dev.
|
|
15
|
-
"@prisma-next/ts-render": "0.12.0-dev.
|
|
16
|
-
"@prisma-next/sql-contract": "0.12.0-dev.
|
|
17
|
-
"@prisma-next/sql-errors": "0.12.0-dev.
|
|
18
|
-
"@prisma-next/sql-operations": "0.12.0-dev.
|
|
19
|
-
"@prisma-next/sql-relational-core": "0.12.0-dev.
|
|
20
|
-
"@prisma-next/sql-schema-ir": "0.12.0-dev.
|
|
21
|
-
"@prisma-next/utils": "0.12.0-dev.
|
|
9
|
+
"@prisma-next/cli": "0.12.0-dev.29",
|
|
10
|
+
"@prisma-next/contract": "0.12.0-dev.29",
|
|
11
|
+
"@prisma-next/errors": "0.12.0-dev.29",
|
|
12
|
+
"@prisma-next/family-sql": "0.12.0-dev.29",
|
|
13
|
+
"@prisma-next/framework-components": "0.12.0-dev.29",
|
|
14
|
+
"@prisma-next/migration-tools": "0.12.0-dev.29",
|
|
15
|
+
"@prisma-next/ts-render": "0.12.0-dev.29",
|
|
16
|
+
"@prisma-next/sql-contract": "0.12.0-dev.29",
|
|
17
|
+
"@prisma-next/sql-errors": "0.12.0-dev.29",
|
|
18
|
+
"@prisma-next/sql-operations": "0.12.0-dev.29",
|
|
19
|
+
"@prisma-next/sql-relational-core": "0.12.0-dev.29",
|
|
20
|
+
"@prisma-next/sql-schema-ir": "0.12.0-dev.29",
|
|
21
|
+
"@prisma-next/utils": "0.12.0-dev.29",
|
|
22
22
|
"@standard-schema/spec": "^1.1.0",
|
|
23
23
|
"arktype": "^2.2.0",
|
|
24
24
|
"pathe": "^2.0.3"
|
|
25
25
|
},
|
|
26
26
|
"devDependencies": {
|
|
27
|
-
"@prisma-next/test-utils": "0.12.0-dev.
|
|
28
|
-
"@prisma-next/tsconfig": "0.12.0-dev.
|
|
29
|
-
"@prisma-next/tsdown": "0.12.0-dev.
|
|
27
|
+
"@prisma-next/test-utils": "0.12.0-dev.29",
|
|
28
|
+
"@prisma-next/tsconfig": "0.12.0-dev.29",
|
|
29
|
+
"@prisma-next/tsdown": "0.12.0-dev.29",
|
|
30
30
|
"tsdown": "0.22.0",
|
|
31
31
|
"typescript": "5.9.3",
|
|
32
32
|
"vitest": "4.1.6"
|