@prisma-next/target-sqlite 0.5.0-dev.6 → 0.5.0-dev.61

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.
Files changed (134) hide show
  1. package/dist/codec-ids-B1-OiN8Q.mjs +14 -0
  2. package/dist/codec-ids-B1-OiN8Q.mjs.map +1 -0
  3. package/dist/codec-ids-DyLO2Rfx.d.mts +13 -0
  4. package/dist/codec-ids-DyLO2Rfx.d.mts.map +1 -0
  5. package/dist/codec-ids.d.mts +2 -0
  6. package/dist/codec-ids.mjs +3 -0
  7. package/dist/codec-types-Bbzv7qCW.d.mts +24 -0
  8. package/dist/codec-types-Bbzv7qCW.d.mts.map +1 -0
  9. package/dist/codec-types.d.mts +4 -0
  10. package/dist/codec-types.mjs +3 -0
  11. package/dist/codecs-BqDitp2X.d.mts +127 -0
  12. package/dist/codecs-BqDitp2X.d.mts.map +1 -0
  13. package/dist/codecs-CDcidsHL.mjs +221 -0
  14. package/dist/codecs-CDcidsHL.mjs.map +1 -0
  15. package/dist/codecs.d.mts +3 -0
  16. package/dist/codecs.mjs +14 -0
  17. package/dist/codecs.mjs.map +1 -0
  18. package/dist/control.d.mts +4 -3
  19. package/dist/control.d.mts.map +1 -1
  20. package/dist/control.mjs +343 -1
  21. package/dist/control.mjs.map +1 -1
  22. package/dist/default-normalizer-R-sQXAYt.mjs +69 -0
  23. package/dist/default-normalizer-R-sQXAYt.mjs.map +1 -0
  24. package/dist/default-normalizer.d.mts +8 -0
  25. package/dist/default-normalizer.d.mts.map +1 -0
  26. package/dist/default-normalizer.mjs +3 -0
  27. package/dist/descriptor-meta-BA2YAFQq.mjs +24 -0
  28. package/dist/descriptor-meta-BA2YAFQq.mjs.map +1 -0
  29. package/dist/migration.d.mts +76 -0
  30. package/dist/migration.d.mts.map +1 -0
  31. package/dist/migration.mjs +38 -0
  32. package/dist/migration.mjs.map +1 -0
  33. package/dist/native-type-normalizer-BMovohPm.mjs +14 -0
  34. package/dist/native-type-normalizer-BMovohPm.mjs.map +1 -0
  35. package/dist/native-type-normalizer.d.mts +11 -0
  36. package/dist/native-type-normalizer.d.mts.map +1 -0
  37. package/dist/native-type-normalizer.mjs +3 -0
  38. package/dist/op-factory-call-BUVV-W9F.mjs +252 -0
  39. package/dist/op-factory-call-BUVV-W9F.mjs.map +1 -0
  40. package/dist/op-factory-call-dUIOao68.d.mts +134 -0
  41. package/dist/op-factory-call-dUIOao68.d.mts.map +1 -0
  42. package/dist/op-factory-call.d.mts +3 -0
  43. package/dist/op-factory-call.mjs +3 -0
  44. package/dist/pack.d.mts +37 -1
  45. package/dist/pack.d.mts.map +1 -1
  46. package/dist/pack.mjs +1 -1
  47. package/dist/planner-CuchCrpN.mjs +522 -0
  48. package/dist/planner-CuchCrpN.mjs.map +1 -0
  49. package/dist/planner-produced-sqlite-migration-BfIIUtxe.d.mts +24 -0
  50. package/dist/planner-produced-sqlite-migration-BfIIUtxe.d.mts.map +1 -0
  51. package/dist/planner-produced-sqlite-migration-C3AAaQoW.mjs +107 -0
  52. package/dist/planner-produced-sqlite-migration-C3AAaQoW.mjs.map +1 -0
  53. package/dist/planner-produced-sqlite-migration.d.mts +5 -0
  54. package/dist/planner-produced-sqlite-migration.mjs +3 -0
  55. package/dist/planner-target-details-BQIWQlBu.mjs +16 -0
  56. package/dist/planner-target-details-BQIWQlBu.mjs.map +1 -0
  57. package/dist/planner-target-details-CtWRvse0.d.mts +12 -0
  58. package/dist/planner-target-details-CtWRvse0.d.mts.map +1 -0
  59. package/dist/planner-target-details.d.mts +2 -0
  60. package/dist/planner-target-details.mjs +3 -0
  61. package/dist/planner.d.mts +56 -0
  62. package/dist/planner.d.mts.map +1 -0
  63. package/dist/planner.mjs +3 -0
  64. package/dist/render-ops-CXOv7SRC.mjs +8 -0
  65. package/dist/render-ops-CXOv7SRC.mjs.map +1 -0
  66. package/dist/render-ops.d.mts +11 -0
  67. package/dist/render-ops.d.mts.map +1 -0
  68. package/dist/render-ops.mjs +3 -0
  69. package/dist/runtime.d.mts.map +1 -1
  70. package/dist/runtime.mjs +2 -4
  71. package/dist/runtime.mjs.map +1 -1
  72. package/dist/shared-D_1fFqLf.d.mts +69 -0
  73. package/dist/shared-D_1fFqLf.d.mts.map +1 -0
  74. package/dist/sql-utils-D3SMPFDD.mjs +33 -0
  75. package/dist/sql-utils-D3SMPFDD.mjs.map +1 -0
  76. package/dist/sql-utils.d.mts +22 -0
  77. package/dist/sql-utils.d.mts.map +1 -0
  78. package/dist/sql-utils.mjs +3 -0
  79. package/dist/sqlite-migration-BeR1cikr.d.mts +18 -0
  80. package/dist/sqlite-migration-BeR1cikr.d.mts.map +1 -0
  81. package/dist/sqlite-migration-CnLhIrJF.mjs +17 -0
  82. package/dist/sqlite-migration-CnLhIrJF.mjs.map +1 -0
  83. package/dist/statement-builders-B3OGOp7n.mjs +148 -0
  84. package/dist/statement-builders-B3OGOp7n.mjs.map +1 -0
  85. package/dist/statement-builders.d.mts +48 -0
  86. package/dist/statement-builders.d.mts.map +1 -0
  87. package/dist/statement-builders.mjs +3 -0
  88. package/dist/tables-sKIg_lWE.mjs +408 -0
  89. package/dist/tables-sKIg_lWE.mjs.map +1 -0
  90. package/package.json +29 -7
  91. package/src/core/authoring.ts +9 -0
  92. package/src/core/codec-helpers.ts +11 -0
  93. package/src/core/codec-ids.ts +13 -0
  94. package/src/core/codecs.ts +337 -0
  95. package/src/core/control-target.ts +54 -11
  96. package/src/core/default-normalizer.ts +92 -0
  97. package/src/core/descriptor-meta.ts +5 -1
  98. package/src/core/migrations/issue-planner.ts +586 -0
  99. package/src/core/migrations/op-factory-call.ts +332 -0
  100. package/src/core/migrations/operations/columns.ts +62 -0
  101. package/src/core/migrations/operations/data-transform.ts +51 -0
  102. package/src/core/migrations/operations/indexes.ts +52 -0
  103. package/src/core/migrations/operations/shared.ts +120 -0
  104. package/src/core/migrations/operations/tables.ts +388 -0
  105. package/src/core/migrations/planner-ddl-builders.ts +142 -0
  106. package/src/core/migrations/planner-produced-sqlite-migration.ts +56 -0
  107. package/src/core/migrations/planner-strategies.ts +231 -0
  108. package/src/core/migrations/planner-target-details.ts +33 -0
  109. package/src/core/migrations/planner.ts +149 -0
  110. package/src/core/migrations/render-ops.ts +9 -0
  111. package/src/core/migrations/render-typescript.ts +91 -0
  112. package/src/core/migrations/runner.ts +593 -0
  113. package/src/core/migrations/sqlite-migration.ts +13 -0
  114. package/src/core/migrations/statement-builders.ts +190 -0
  115. package/src/core/native-type-normalizer.ts +9 -0
  116. package/src/core/registry.ts +11 -0
  117. package/src/core/runtime-target.ts +1 -3
  118. package/src/core/sql-utils.ts +47 -0
  119. package/src/exports/codec-ids.ts +13 -0
  120. package/src/exports/codec-types.ts +43 -0
  121. package/src/exports/codecs.ts +20 -0
  122. package/src/exports/control.ts +1 -0
  123. package/src/exports/default-normalizer.ts +1 -0
  124. package/src/exports/migration.ts +23 -0
  125. package/src/exports/native-type-normalizer.ts +1 -0
  126. package/src/exports/op-factory-call.ts +11 -0
  127. package/src/exports/planner-produced-sqlite-migration.ts +4 -0
  128. package/src/exports/planner-target-details.ts +2 -0
  129. package/src/exports/planner.ts +2 -0
  130. package/src/exports/render-ops.ts +1 -0
  131. package/src/exports/sql-utils.ts +1 -0
  132. package/src/exports/statement-builders.ts +11 -0
  133. package/dist/descriptor-meta-DbuuziYA.mjs +0 -14
  134. package/dist/descriptor-meta-DbuuziYA.mjs.map +0 -1
package/dist/control.mjs CHANGED
@@ -1,13 +1,355 @@
1
- import { t as sqliteTargetDescriptorMeta } from "./descriptor-meta-DbuuziYA.mjs";
1
+ import { t as sqliteTargetDescriptorMeta } from "./descriptor-meta-BA2YAFQq.mjs";
2
+ import { t as parseSqliteDefault } from "./default-normalizer-R-sQXAYt.mjs";
3
+ import { t as normalizeSqliteNativeType } from "./native-type-normalizer-BMovohPm.mjs";
4
+ import { d as renderDefaultLiteral } from "./tables-sKIg_lWE.mjs";
5
+ import { n as createSqliteMigrationPlanner } from "./planner-CuchCrpN.mjs";
6
+ import { a as buildWriteMarkerStatements, c as readMarkerStatement, i as buildLedgerInsertStatement, o as ensureLedgerTableStatement, s as ensureMarkerTableStatement } from "./statement-builders-B3OGOp7n.mjs";
7
+ import { contractToSchemaIR, runnerFailure, runnerSuccess } from "@prisma-next/family-sql/control";
8
+ import { verifySqlSchema } from "@prisma-next/family-sql/schema-verify";
9
+ import { ok, okVoid } from "@prisma-next/utils/result";
10
+ import { ifDefined } from "@prisma-next/utils/defined";
11
+ import { parseContractMarkerRow } from "@prisma-next/family-sql/verify";
2
12
 
13
+ //#region src/core/migrations/runner.ts
14
+ function createSqliteMigrationRunner(family) {
15
+ return new SqliteMigrationRunner(family);
16
+ }
17
+ var SqliteMigrationRunner = class {
18
+ constructor(family) {
19
+ this.family = family;
20
+ }
21
+ async execute(options) {
22
+ const driver = options.driver;
23
+ const destinationCheck = this.ensurePlanMatchesDestinationContract(options.plan.destination, options.destinationContract);
24
+ if (!destinationCheck.ok) return destinationCheck;
25
+ const policyCheck = this.enforcePolicyCompatibility(options.policy, options.plan.operations);
26
+ if (!policyCheck.ok) return policyCheck;
27
+ const fkWasEnabled = await this.readForeignKeysEnabled(driver);
28
+ if (fkWasEnabled) await driver.query("PRAGMA foreign_keys = OFF");
29
+ try {
30
+ await this.beginExclusiveTransaction(driver);
31
+ let committed = false;
32
+ try {
33
+ await this.ensureControlTables(driver);
34
+ const existingMarker = await this.readMarker(driver);
35
+ const markerCheck = this.ensureMarkerCompatibility(existingMarker, options.plan);
36
+ if (!markerCheck.ok) return markerCheck;
37
+ const markerAtDestination = this.markerMatchesDestination(existingMarker, options.plan);
38
+ const isSelfEdge = options.plan.origin?.storageHash === options.plan.destination.storageHash;
39
+ const skipOperations = markerAtDestination && options.plan.origin != null && !isSelfEdge;
40
+ let operationsExecuted;
41
+ let executedOperations;
42
+ if (skipOperations) {
43
+ operationsExecuted = 0;
44
+ executedOperations = [];
45
+ } else {
46
+ const applyResult = await this.applyPlan(driver, options);
47
+ if (!applyResult.ok) return applyResult;
48
+ operationsExecuted = applyResult.value.operationsExecuted;
49
+ executedOperations = applyResult.value.executedOperations;
50
+ }
51
+ const schemaIR = await this.family.introspect({
52
+ driver,
53
+ contract: options.destinationContract
54
+ });
55
+ const schemaVerifyResult = verifySqlSchema({
56
+ contract: options.destinationContract,
57
+ schema: schemaIR,
58
+ strict: options.strictVerification ?? true,
59
+ context: options.context ?? {},
60
+ typeMetadataRegistry: this.family.typeMetadataRegistry,
61
+ frameworkComponents: options.frameworkComponents,
62
+ normalizeDefault: parseSqliteDefault,
63
+ normalizeNativeType: normalizeSqliteNativeType
64
+ });
65
+ if (!schemaVerifyResult.ok) return runnerFailure("SCHEMA_VERIFY_FAILED", schemaVerifyResult.summary, {
66
+ why: "The resulting database schema does not satisfy the destination contract.",
67
+ meta: { issues: schemaVerifyResult.schema.issues }
68
+ });
69
+ const incomingInvariants = options.plan.providedInvariants;
70
+ const existingInvariants = new Set(existingMarker?.invariants ?? []);
71
+ const incomingIsSubsetOfExisting = incomingInvariants.every((id) => existingInvariants.has(id));
72
+ if (!(isSelfEdge && operationsExecuted === 0 && incomingIsSubsetOfExisting)) {
73
+ await this.upsertMarker(driver, options, existingMarker);
74
+ await this.recordLedgerEntry(driver, options, existingMarker, executedOperations);
75
+ }
76
+ if (fkWasEnabled) {
77
+ const fkIntegrityCheck = await this.verifyForeignKeyIntegrity(driver);
78
+ if (!fkIntegrityCheck.ok) return fkIntegrityCheck;
79
+ }
80
+ await this.commitTransaction(driver);
81
+ committed = true;
82
+ return runnerSuccess({
83
+ operationsPlanned: options.plan.operations.length,
84
+ operationsExecuted
85
+ });
86
+ } finally {
87
+ if (!committed) await this.rollbackTransaction(driver);
88
+ }
89
+ } finally {
90
+ if (fkWasEnabled) await driver.query("PRAGMA foreign_keys = ON");
91
+ }
92
+ }
93
+ async readForeignKeysEnabled(driver) {
94
+ return (await driver.query("PRAGMA foreign_keys")).rows[0]?.foreign_keys === 1;
95
+ }
96
+ async verifyForeignKeyIntegrity(driver) {
97
+ const result = await driver.query("PRAGMA foreign_key_check");
98
+ if (result.rows.length === 0) return okVoid();
99
+ return runnerFailure("FOREIGN_KEY_VIOLATION", `Foreign key integrity check failed after migration: ${result.rows.length} violation(s).`, {
100
+ why: "PRAGMA foreign_key_check reported violations after applying recreate-table operations.",
101
+ meta: { violations: result.rows }
102
+ });
103
+ }
104
+ async applyPlan(driver, options) {
105
+ const checks = options.executionChecks;
106
+ const runPrechecks = checks?.prechecks !== false;
107
+ const runPostchecks = checks?.postchecks !== false;
108
+ const runIdempotency = checks?.idempotencyChecks !== false;
109
+ let operationsExecuted = 0;
110
+ const executedOperations = [];
111
+ for (const operation of options.plan.operations) {
112
+ options.callbacks?.onOperationStart?.(operation);
113
+ try {
114
+ if (runPostchecks && runIdempotency) {
115
+ if (await this.expectationsAreSatisfied(driver, operation.postcheck)) {
116
+ executedOperations.push(this.createSkipRecord(operation));
117
+ continue;
118
+ }
119
+ }
120
+ if (runPrechecks) {
121
+ const precheckResult = await this.runExpectationSteps(driver, operation.precheck, operation, "precheck");
122
+ if (!precheckResult.ok) return precheckResult;
123
+ }
124
+ const executeResult = await this.runExecuteSteps(driver, operation.execute, operation);
125
+ if (!executeResult.ok) return executeResult;
126
+ if (runPostchecks) {
127
+ const postcheckResult = await this.runExpectationSteps(driver, operation.postcheck, operation, "postcheck");
128
+ if (!postcheckResult.ok) return postcheckResult;
129
+ }
130
+ executedOperations.push(operation);
131
+ operationsExecuted += 1;
132
+ } finally {
133
+ options.callbacks?.onOperationComplete?.(operation);
134
+ }
135
+ }
136
+ return ok({
137
+ operationsExecuted,
138
+ executedOperations
139
+ });
140
+ }
141
+ async ensureControlTables(driver) {
142
+ await this.executeStatement(driver, ensureMarkerTableStatement);
143
+ await this.executeStatement(driver, ensureLedgerTableStatement);
144
+ }
145
+ async readMarker(driver) {
146
+ const stmt = readMarkerStatement();
147
+ try {
148
+ const row = (await driver.query(stmt.sql, stmt.params)).rows[0];
149
+ if (!row) return null;
150
+ const invariants = typeof row.invariants === "string" ? JSON.parse(row.invariants) : row.invariants;
151
+ return parseContractMarkerRow({
152
+ ...row,
153
+ invariants
154
+ });
155
+ } catch (error) {
156
+ if (error instanceof Error && error.message.includes("no such table")) return null;
157
+ throw error;
158
+ }
159
+ }
160
+ async runExpectationSteps(driver, steps, operation, phase) {
161
+ for (const step of steps) {
162
+ const result = await driver.query(step.sql, step.params ?? []);
163
+ if (!this.stepResultIsTrue(result.rows)) return runnerFailure(phase === "precheck" ? "PRECHECK_FAILED" : "POSTCHECK_FAILED", `Operation ${operation.id} failed during ${phase}: ${step.description}`, { meta: {
164
+ operationId: operation.id,
165
+ phase,
166
+ stepDescription: step.description
167
+ } });
168
+ }
169
+ return okVoid();
170
+ }
171
+ async runExecuteSteps(driver, steps, operation) {
172
+ for (const step of steps) try {
173
+ await driver.query(step.sql, step.params ?? []);
174
+ } catch (error) {
175
+ const message = error instanceof Error ? error.message : String(error);
176
+ return runnerFailure("EXECUTION_FAILED", `Operation ${operation.id} failed during execution: ${step.description}`, {
177
+ why: message,
178
+ meta: {
179
+ operationId: operation.id,
180
+ stepDescription: step.description,
181
+ sql: step.sql
182
+ }
183
+ });
184
+ }
185
+ return okVoid();
186
+ }
187
+ stepResultIsTrue(rows) {
188
+ if (!rows || rows.length === 0) return false;
189
+ const firstRow = rows[0];
190
+ const firstValue = firstRow ? Object.values(firstRow)[0] : void 0;
191
+ if (typeof firstValue === "number") return firstValue !== 0;
192
+ if (typeof firstValue === "boolean") return firstValue;
193
+ if (typeof firstValue === "string") {
194
+ const lower = firstValue.toLowerCase();
195
+ if (lower === "true" || lower === "1") return true;
196
+ if (lower === "false" || lower === "0") return false;
197
+ return firstValue.length > 0;
198
+ }
199
+ return Boolean(firstValue);
200
+ }
201
+ async expectationsAreSatisfied(driver, steps) {
202
+ if (steps.length === 0) return false;
203
+ for (const step of steps) {
204
+ const result = await driver.query(step.sql, step.params ?? []);
205
+ if (!this.stepResultIsTrue(result.rows)) return false;
206
+ }
207
+ return true;
208
+ }
209
+ createSkipRecord(operation) {
210
+ return Object.freeze({
211
+ id: operation.id,
212
+ label: operation.label,
213
+ ...ifDefined("summary", operation.summary),
214
+ operationClass: operation.operationClass,
215
+ target: operation.target,
216
+ precheck: Object.freeze([]),
217
+ execute: Object.freeze([]),
218
+ postcheck: Object.freeze([...operation.postcheck]),
219
+ meta: Object.freeze({
220
+ ...operation.meta ?? {},
221
+ runner: Object.freeze({
222
+ skipped: true,
223
+ reason: "postcheck_pre_satisfied"
224
+ })
225
+ })
226
+ });
227
+ }
228
+ markerMatchesDestination(marker, plan) {
229
+ if (!marker) return false;
230
+ if (marker.storageHash !== plan.destination.storageHash) return false;
231
+ if (plan.destination.profileHash && marker.profileHash !== plan.destination.profileHash) return false;
232
+ return true;
233
+ }
234
+ enforcePolicyCompatibility(policy, operations) {
235
+ const allowedClasses = new Set(policy.allowedOperationClasses);
236
+ for (const operation of operations) if (!allowedClasses.has(operation.operationClass)) return runnerFailure("POLICY_VIOLATION", `Operation ${operation.id} has class "${operation.operationClass}" which is not allowed by policy.`, {
237
+ why: `Policy only allows: ${policy.allowedOperationClasses.join(", ")}.`,
238
+ meta: {
239
+ operationId: operation.id,
240
+ operationClass: operation.operationClass,
241
+ allowedClasses: policy.allowedOperationClasses
242
+ }
243
+ });
244
+ return okVoid();
245
+ }
246
+ ensureMarkerCompatibility(marker, plan) {
247
+ const origin = plan.origin ?? null;
248
+ if (!origin) return okVoid();
249
+ if (!marker) return runnerFailure("MARKER_ORIGIN_MISMATCH", `Missing contract marker: expected origin storage hash ${origin.storageHash}.`, { meta: { expectedOriginStorageHash: origin.storageHash } });
250
+ if (marker.storageHash !== origin.storageHash) return runnerFailure("MARKER_ORIGIN_MISMATCH", `Existing contract marker (${marker.storageHash}) does not match plan origin (${origin.storageHash}).`, { meta: {
251
+ markerStorageHash: marker.storageHash,
252
+ expectedOriginStorageHash: origin.storageHash
253
+ } });
254
+ if (origin.profileHash && marker.profileHash !== origin.profileHash) return runnerFailure("MARKER_ORIGIN_MISMATCH", `Existing contract marker profile hash (${marker.profileHash}) does not match plan origin profile hash (${origin.profileHash}).`, { meta: {
255
+ markerProfileHash: marker.profileHash,
256
+ expectedOriginProfileHash: origin.profileHash
257
+ } });
258
+ return okVoid();
259
+ }
260
+ ensurePlanMatchesDestinationContract(destination, contract) {
261
+ if (destination.storageHash !== contract.storage.storageHash) return runnerFailure("DESTINATION_CONTRACT_MISMATCH", `Plan destination storage hash (${destination.storageHash}) does not match provided contract storage hash (${contract.storage.storageHash}).`, { meta: {
262
+ planStorageHash: destination.storageHash,
263
+ contractStorageHash: contract.storage.storageHash
264
+ } });
265
+ if (destination.profileHash && contract.profileHash && destination.profileHash !== contract.profileHash) return runnerFailure("DESTINATION_CONTRACT_MISMATCH", `Plan destination profile hash (${destination.profileHash}) does not match provided contract profile hash (${contract.profileHash}).`, { meta: {
266
+ planProfileHash: destination.profileHash,
267
+ contractProfileHash: contract.profileHash
268
+ } });
269
+ return okVoid();
270
+ }
271
+ async upsertMarker(driver, options, existingMarker) {
272
+ const merged = new Set(existingMarker?.invariants ?? []);
273
+ for (const inv of options.plan.providedInvariants) merged.add(inv);
274
+ const invariants = Array.from(merged).sort();
275
+ const writeStatements = buildWriteMarkerStatements({
276
+ storageHash: options.plan.destination.storageHash,
277
+ profileHash: options.plan.destination.profileHash ?? options.destinationContract.profileHash ?? options.plan.destination.storageHash,
278
+ contractJson: options.destinationContract,
279
+ canonicalVersion: null,
280
+ meta: {},
281
+ invariants
282
+ });
283
+ const statement = existingMarker ? writeStatements.update : writeStatements.insert;
284
+ await this.executeStatement(driver, statement);
285
+ }
286
+ async recordLedgerEntry(driver, options, existingMarker, executedOperations) {
287
+ const ledgerStatement = buildLedgerInsertStatement({
288
+ originStorageHash: existingMarker?.storageHash ?? null,
289
+ originProfileHash: existingMarker?.profileHash ?? null,
290
+ destinationStorageHash: options.plan.destination.storageHash,
291
+ destinationProfileHash: options.plan.destination.profileHash ?? options.destinationContract.profileHash ?? options.plan.destination.storageHash,
292
+ contractJsonBefore: existingMarker?.contractJson ?? null,
293
+ contractJsonAfter: options.destinationContract,
294
+ operations: executedOperations
295
+ });
296
+ await this.executeStatement(driver, ledgerStatement);
297
+ }
298
+ async beginExclusiveTransaction(driver) {
299
+ await driver.query("BEGIN EXCLUSIVE");
300
+ }
301
+ async commitTransaction(driver) {
302
+ await driver.query("COMMIT");
303
+ }
304
+ async rollbackTransaction(driver) {
305
+ await driver.query("ROLLBACK");
306
+ }
307
+ async executeStatement(driver, statement) {
308
+ if (statement.params.length > 0) {
309
+ await driver.query(statement.sql, statement.params);
310
+ return;
311
+ }
312
+ await driver.query(statement.sql);
313
+ }
314
+ };
315
+
316
+ //#endregion
3
317
  //#region src/core/control-target.ts
318
+ function sqliteRenderDefault(def, _column) {
319
+ if (def.kind === "function") {
320
+ if (def.expression === "now()") return "datetime('now')";
321
+ return def.expression;
322
+ }
323
+ return renderDefaultLiteral(def.value);
324
+ }
4
325
  const sqliteControlTargetDescriptor = {
5
326
  ...sqliteTargetDescriptorMeta,
327
+ migrations: {
328
+ createPlanner(_family) {
329
+ return createSqliteMigrationPlanner();
330
+ },
331
+ createRunner(family) {
332
+ return createSqliteMigrationRunner(family);
333
+ },
334
+ contractToSchema(contract, frameworkComponents) {
335
+ return contractToSchemaIR(contract, {
336
+ annotationNamespace: "sqlite",
337
+ renderDefault: sqliteRenderDefault,
338
+ frameworkComponents: frameworkComponents ?? []
339
+ });
340
+ }
341
+ },
6
342
  create() {
7
343
  return {
8
344
  familyId: "sql",
9
345
  targetId: "sqlite"
10
346
  };
347
+ },
348
+ createPlanner(_family) {
349
+ return createSqliteMigrationPlanner();
350
+ },
351
+ createRunner(family) {
352
+ return createSqliteMigrationRunner(family);
11
353
  }
12
354
  };
13
355
  var control_target_default = sqliteControlTargetDescriptor;
@@ -1 +1 @@
1
- {"version":3,"file":"control.mjs","names":["sqliteControlTargetDescriptor: ControlTargetDescriptor<\n 'sql',\n 'sqlite',\n ControlTargetInstance<'sql', 'sqlite'>\n>"],"sources":["../src/core/control-target.ts"],"sourcesContent":["import type {\n ControlTargetDescriptor,\n ControlTargetInstance,\n} from '@prisma-next/framework-components/control';\nimport { sqliteTargetDescriptorMeta } from './descriptor-meta';\n\nconst sqliteControlTargetDescriptor: ControlTargetDescriptor<\n 'sql',\n 'sqlite',\n ControlTargetInstance<'sql', 'sqlite'>\n> = {\n ...sqliteTargetDescriptorMeta,\n create(): ControlTargetInstance<'sql', 'sqlite'> {\n return { familyId: 'sql', targetId: 'sqlite' };\n },\n};\n\nexport default sqliteControlTargetDescriptor;\n"],"mappings":";;;AAMA,MAAMA,gCAIF;CACF,GAAG;CACH,SAAiD;AAC/C,SAAO;GAAE,UAAU;GAAO,UAAU;GAAU;;CAEjD;AAED,6BAAe"}
1
+ {"version":3,"file":"control.mjs","names":["family: SqlControlFamilyInstance","operationsExecuted: number","executedOperations: readonly SqlMigrationPlanOperation<SqlitePlanTargetDetails>[]","executedOperations: Array<SqlMigrationPlanOperation<SqlitePlanTargetDetails>>","error: unknown","sqliteControlTargetDescriptor: SqlControlTargetDescriptor<'sqlite', SqlitePlanTargetDetails>"],"sources":["../src/core/migrations/runner.ts","../src/core/control-target.ts"],"sourcesContent":["import type { ContractMarkerRecord } from '@prisma-next/contract/types';\nimport type {\n MigrationOperationPolicy,\n SqlControlFamilyInstance,\n SqlMigrationPlanContractInfo,\n SqlMigrationPlanOperation,\n SqlMigrationPlanOperationStep,\n SqlMigrationRunner,\n SqlMigrationRunnerExecuteOptions,\n SqlMigrationRunnerFailure,\n SqlMigrationRunnerResult,\n} from '@prisma-next/family-sql/control';\nimport { runnerFailure, runnerSuccess } from '@prisma-next/family-sql/control';\nimport { verifySqlSchema } from '@prisma-next/family-sql/schema-verify';\nimport { type ContractMarkerRow, parseContractMarkerRow } from '@prisma-next/family-sql/verify';\nimport { ifDefined } from '@prisma-next/utils/defined';\nimport type { Result } from '@prisma-next/utils/result';\nimport { ok, okVoid } from '@prisma-next/utils/result';\nimport { parseSqliteDefault } from '../default-normalizer';\nimport { normalizeSqliteNativeType } from '../native-type-normalizer';\nimport type { SqlitePlanTargetDetails } from './planner-target-details';\nimport {\n buildLedgerInsertStatement,\n buildWriteMarkerStatements,\n ensureLedgerTableStatement,\n ensureMarkerTableStatement,\n readMarkerStatement,\n type SqlStatement,\n} from './statement-builders';\n\nexport function createSqliteMigrationRunner(\n family: SqlControlFamilyInstance,\n): SqlMigrationRunner<SqlitePlanTargetDetails> {\n return new SqliteMigrationRunner(family);\n}\n\nclass SqliteMigrationRunner implements SqlMigrationRunner<SqlitePlanTargetDetails> {\n constructor(private readonly family: SqlControlFamilyInstance) {}\n\n async execute(\n options: SqlMigrationRunnerExecuteOptions<SqlitePlanTargetDetails>,\n ): Promise<SqlMigrationRunnerResult> {\n const driver = options.driver;\n\n const destinationCheck = this.ensurePlanMatchesDestinationContract(\n options.plan.destination,\n options.destinationContract,\n );\n if (!destinationCheck.ok) {\n return destinationCheck;\n }\n\n const policyCheck = this.enforcePolicyCompatibility(options.policy, options.plan.operations);\n if (!policyCheck.ok) {\n return policyCheck;\n }\n\n // SQLite recreate-table drops and rebuilds the table. If foreign_keys is ON,\n // dropping a referenced parent cascade-deletes child rows; we must disable FK\n // enforcement for the duration of the migration and validate integrity before\n // committing. PRAGMA foreign_keys is a no-op inside a transaction, so toggle\n // around BEGIN/COMMIT.\n const fkWasEnabled = await this.readForeignKeysEnabled(driver);\n if (fkWasEnabled) {\n await driver.query('PRAGMA foreign_keys = OFF');\n }\n\n try {\n await this.beginExclusiveTransaction(driver);\n let committed = false;\n try {\n await this.ensureControlTables(driver);\n const existingMarker = await this.readMarker(driver);\n\n const markerCheck = this.ensureMarkerCompatibility(existingMarker, options.plan);\n if (!markerCheck.ok) {\n return markerCheck;\n }\n\n const markerAtDestination = this.markerMatchesDestination(existingMarker, options.plan);\n const isSelfEdge =\n options.plan.origin?.storageHash === options.plan.destination.storageHash;\n const skipOperations = markerAtDestination && options.plan.origin != null && !isSelfEdge;\n\n let operationsExecuted: number;\n let executedOperations: readonly SqlMigrationPlanOperation<SqlitePlanTargetDetails>[];\n\n if (skipOperations) {\n operationsExecuted = 0;\n executedOperations = [];\n } else {\n const applyResult = await this.applyPlan(driver, options);\n if (!applyResult.ok) {\n return applyResult;\n }\n operationsExecuted = applyResult.value.operationsExecuted;\n executedOperations = applyResult.value.executedOperations;\n }\n\n const schemaIR = await this.family.introspect({\n driver,\n contract: options.destinationContract,\n });\n\n const schemaVerifyResult = verifySqlSchema({\n contract: options.destinationContract,\n schema: schemaIR,\n strict: options.strictVerification ?? true,\n context: options.context ?? {},\n typeMetadataRegistry: this.family.typeMetadataRegistry,\n frameworkComponents: options.frameworkComponents,\n normalizeDefault: parseSqliteDefault,\n normalizeNativeType: normalizeSqliteNativeType,\n });\n if (!schemaVerifyResult.ok) {\n return runnerFailure('SCHEMA_VERIFY_FAILED', schemaVerifyResult.summary, {\n why: 'The resulting database schema does not satisfy the destination contract.',\n meta: {\n issues: schemaVerifyResult.schema.issues,\n },\n });\n }\n\n // Self-edge no-op detection: a self-edge migration whose ops had no\n // ops to begin with and brings no new invariants produced no\n // observable change. Skip the marker + ledger writes so an idempotent\n // re-apply of a self-edge data transform doesn't churn updatedAt or\n // pile up empty ledger entries. db update no-ops still write a\n // ledger entry as audit trail.\n const incomingInvariants = options.plan.providedInvariants;\n const existingInvariants = new Set(existingMarker?.invariants ?? []);\n const incomingIsSubsetOfExisting = incomingInvariants.every((id) =>\n existingInvariants.has(id),\n );\n const isSelfEdgeNoOp = isSelfEdge && operationsExecuted === 0 && incomingIsSubsetOfExisting;\n\n if (!isSelfEdgeNoOp) {\n await this.upsertMarker(driver, options, existingMarker);\n await this.recordLedgerEntry(driver, options, existingMarker, executedOperations);\n }\n\n if (fkWasEnabled) {\n const fkIntegrityCheck = await this.verifyForeignKeyIntegrity(driver);\n if (!fkIntegrityCheck.ok) {\n return fkIntegrityCheck;\n }\n }\n\n await this.commitTransaction(driver);\n committed = true;\n return runnerSuccess({\n operationsPlanned: options.plan.operations.length,\n operationsExecuted,\n });\n } finally {\n if (!committed) {\n await this.rollbackTransaction(driver);\n }\n }\n } finally {\n if (fkWasEnabled) {\n await driver.query('PRAGMA foreign_keys = ON');\n }\n }\n }\n\n private async readForeignKeysEnabled(\n driver: SqlMigrationRunnerExecuteOptions<SqlitePlanTargetDetails>['driver'],\n ): Promise<boolean> {\n const result = await driver.query<{ foreign_keys: number }>('PRAGMA foreign_keys');\n const row = result.rows[0];\n return row?.foreign_keys === 1;\n }\n\n private async verifyForeignKeyIntegrity(\n driver: SqlMigrationRunnerExecuteOptions<SqlitePlanTargetDetails>['driver'],\n ): Promise<Result<void, SqlMigrationRunnerFailure>> {\n const result = await driver.query<Record<string, unknown>>('PRAGMA foreign_key_check');\n if (result.rows.length === 0) {\n return okVoid();\n }\n return runnerFailure(\n 'FOREIGN_KEY_VIOLATION',\n `Foreign key integrity check failed after migration: ${result.rows.length} violation(s).`,\n {\n why: 'PRAGMA foreign_key_check reported violations after applying recreate-table operations.',\n meta: { violations: result.rows },\n },\n );\n }\n\n private async applyPlan(\n driver: SqlMigrationRunnerExecuteOptions<SqlitePlanTargetDetails>['driver'],\n options: SqlMigrationRunnerExecuteOptions<SqlitePlanTargetDetails>,\n ): Promise<\n Result<\n {\n readonly operationsExecuted: number;\n readonly executedOperations: readonly SqlMigrationPlanOperation<SqlitePlanTargetDetails>[];\n },\n SqlMigrationRunnerFailure\n >\n > {\n const checks = options.executionChecks;\n const runPrechecks = checks?.prechecks !== false;\n const runPostchecks = checks?.postchecks !== false;\n const runIdempotency = checks?.idempotencyChecks !== false;\n\n let operationsExecuted = 0;\n const executedOperations: Array<SqlMigrationPlanOperation<SqlitePlanTargetDetails>> = [];\n\n for (const operation of options.plan.operations) {\n options.callbacks?.onOperationStart?.(operation);\n try {\n if (runPostchecks && runIdempotency) {\n const postcheckAlreadySatisfied = await this.expectationsAreSatisfied(\n driver,\n operation.postcheck,\n );\n if (postcheckAlreadySatisfied) {\n executedOperations.push(this.createSkipRecord(operation));\n continue;\n }\n }\n\n if (runPrechecks) {\n const precheckResult = await this.runExpectationSteps(\n driver,\n operation.precheck,\n operation,\n 'precheck',\n );\n if (!precheckResult.ok) {\n return precheckResult;\n }\n }\n\n const executeResult = await this.runExecuteSteps(driver, operation.execute, operation);\n if (!executeResult.ok) {\n return executeResult;\n }\n\n if (runPostchecks) {\n const postcheckResult = await this.runExpectationSteps(\n driver,\n operation.postcheck,\n operation,\n 'postcheck',\n );\n if (!postcheckResult.ok) {\n return postcheckResult;\n }\n }\n\n executedOperations.push(operation);\n operationsExecuted += 1;\n } finally {\n options.callbacks?.onOperationComplete?.(operation);\n }\n }\n return ok({ operationsExecuted, executedOperations });\n }\n\n private async ensureControlTables(\n driver: SqlMigrationRunnerExecuteOptions<SqlitePlanTargetDetails>['driver'],\n ): Promise<void> {\n await this.executeStatement(driver, ensureMarkerTableStatement);\n await this.executeStatement(driver, ensureLedgerTableStatement);\n }\n\n private async readMarker(\n driver: SqlMigrationRunnerExecuteOptions<SqlitePlanTargetDetails>['driver'],\n ): Promise<ContractMarkerRecord | null> {\n const stmt = readMarkerStatement();\n try {\n const result = await driver.query<ContractMarkerRow>(stmt.sql, stmt.params);\n const row = result.rows[0];\n if (!row) return null;\n // SQLite stores arrays as JSON-encoded TEXT (no native array type), so\n // the driver returns `invariants` as a string. Decode before delegating\n // to the shared row schema, which expects `string[]`.\n const invariants =\n typeof row.invariants === 'string'\n ? (JSON.parse(row.invariants) as unknown)\n : row.invariants;\n return parseContractMarkerRow({ ...row, invariants });\n } catch (error) {\n // Table might not exist yet\n if (error instanceof Error && error.message.includes('no such table')) {\n return null;\n }\n throw error;\n }\n }\n\n private async runExpectationSteps(\n driver: SqlMigrationRunnerExecuteOptions<SqlitePlanTargetDetails>['driver'],\n steps: readonly SqlMigrationPlanOperationStep[],\n operation: SqlMigrationPlanOperation<SqlitePlanTargetDetails>,\n phase: 'precheck' | 'postcheck',\n ): Promise<Result<void, SqlMigrationRunnerFailure>> {\n for (const step of steps) {\n const result = await driver.query(step.sql, step.params ?? []);\n if (!this.stepResultIsTrue(result.rows)) {\n const code = phase === 'precheck' ? 'PRECHECK_FAILED' : 'POSTCHECK_FAILED';\n return runnerFailure(\n code,\n `Operation ${operation.id} failed during ${phase}: ${step.description}`,\n {\n meta: {\n operationId: operation.id,\n phase,\n stepDescription: step.description,\n },\n },\n );\n }\n }\n return okVoid();\n }\n\n private async runExecuteSteps(\n driver: SqlMigrationRunnerExecuteOptions<SqlitePlanTargetDetails>['driver'],\n steps: readonly SqlMigrationPlanOperationStep[],\n operation: SqlMigrationPlanOperation<SqlitePlanTargetDetails>,\n ): Promise<Result<void, SqlMigrationRunnerFailure>> {\n for (const step of steps) {\n try {\n await driver.query(step.sql, step.params ?? []);\n } catch (error: unknown) {\n const message = error instanceof Error ? error.message : String(error);\n return runnerFailure(\n 'EXECUTION_FAILED',\n `Operation ${operation.id} failed during execution: ${step.description}`,\n {\n why: message,\n meta: {\n operationId: operation.id,\n stepDescription: step.description,\n sql: step.sql,\n },\n },\n );\n }\n }\n return okVoid();\n }\n\n private stepResultIsTrue(rows: readonly Record<string, unknown>[]): boolean {\n if (!rows || rows.length === 0) {\n return false;\n }\n const firstRow = rows[0];\n const firstValue = firstRow ? Object.values(firstRow)[0] : undefined;\n if (typeof firstValue === 'number') {\n return firstValue !== 0;\n }\n if (typeof firstValue === 'boolean') {\n return firstValue;\n }\n if (typeof firstValue === 'string') {\n const lower = firstValue.toLowerCase();\n if (lower === 'true' || lower === '1') return true;\n if (lower === 'false' || lower === '0') return false;\n return firstValue.length > 0;\n }\n return Boolean(firstValue);\n }\n\n private async expectationsAreSatisfied(\n driver: SqlMigrationRunnerExecuteOptions<SqlitePlanTargetDetails>['driver'],\n steps: readonly SqlMigrationPlanOperationStep[],\n ): Promise<boolean> {\n if (steps.length === 0) {\n return false;\n }\n for (const step of steps) {\n const result = await driver.query(step.sql, step.params ?? []);\n if (!this.stepResultIsTrue(result.rows)) {\n return false;\n }\n }\n return true;\n }\n\n private createSkipRecord(\n operation: SqlMigrationPlanOperation<SqlitePlanTargetDetails>,\n ): SqlMigrationPlanOperation<SqlitePlanTargetDetails> {\n return Object.freeze({\n id: operation.id,\n label: operation.label,\n ...ifDefined('summary', operation.summary),\n operationClass: operation.operationClass,\n target: operation.target,\n precheck: Object.freeze([]),\n execute: Object.freeze([]),\n postcheck: Object.freeze([...operation.postcheck]),\n meta: Object.freeze({\n ...(operation.meta ?? {}),\n runner: Object.freeze({ skipped: true, reason: 'postcheck_pre_satisfied' }),\n }),\n });\n }\n\n private markerMatchesDestination(\n marker: ContractMarkerRecord | null,\n plan: SqlMigrationRunnerExecuteOptions<SqlitePlanTargetDetails>['plan'],\n ): boolean {\n if (!marker) return false;\n if (marker.storageHash !== plan.destination.storageHash) return false;\n if (plan.destination.profileHash && marker.profileHash !== plan.destination.profileHash) {\n return false;\n }\n return true;\n }\n\n private enforcePolicyCompatibility(\n policy: MigrationOperationPolicy,\n operations: readonly SqlMigrationPlanOperation<SqlitePlanTargetDetails>[],\n ): Result<void, SqlMigrationRunnerFailure> {\n const allowedClasses = new Set(policy.allowedOperationClasses);\n for (const operation of operations) {\n if (!allowedClasses.has(operation.operationClass)) {\n return runnerFailure(\n 'POLICY_VIOLATION',\n `Operation ${operation.id} has class \"${operation.operationClass}\" which is not allowed by policy.`,\n {\n why: `Policy only allows: ${policy.allowedOperationClasses.join(', ')}.`,\n meta: {\n operationId: operation.id,\n operationClass: operation.operationClass,\n allowedClasses: policy.allowedOperationClasses,\n },\n },\n );\n }\n }\n return okVoid();\n }\n\n private ensureMarkerCompatibility(\n marker: ContractMarkerRecord | null,\n plan: SqlMigrationRunnerExecuteOptions<SqlitePlanTargetDetails>['plan'],\n ): Result<void, SqlMigrationRunnerFailure> {\n const origin = plan.origin ?? null;\n if (!origin) {\n return okVoid();\n }\n if (!marker) {\n return runnerFailure(\n 'MARKER_ORIGIN_MISMATCH',\n `Missing contract marker: expected origin storage hash ${origin.storageHash}.`,\n { meta: { expectedOriginStorageHash: origin.storageHash } },\n );\n }\n if (marker.storageHash !== origin.storageHash) {\n return runnerFailure(\n 'MARKER_ORIGIN_MISMATCH',\n `Existing contract marker (${marker.storageHash}) does not match plan origin (${origin.storageHash}).`,\n {\n meta: {\n markerStorageHash: marker.storageHash,\n expectedOriginStorageHash: origin.storageHash,\n },\n },\n );\n }\n if (origin.profileHash && marker.profileHash !== origin.profileHash) {\n return runnerFailure(\n 'MARKER_ORIGIN_MISMATCH',\n `Existing contract marker profile hash (${marker.profileHash}) does not match plan origin profile hash (${origin.profileHash}).`,\n {\n meta: {\n markerProfileHash: marker.profileHash,\n expectedOriginProfileHash: origin.profileHash,\n },\n },\n );\n }\n return okVoid();\n }\n\n private ensurePlanMatchesDestinationContract(\n destination: SqlMigrationPlanContractInfo,\n contract: SqlMigrationRunnerExecuteOptions<SqlitePlanTargetDetails>['destinationContract'],\n ): Result<void, SqlMigrationRunnerFailure> {\n if (destination.storageHash !== contract.storage.storageHash) {\n return runnerFailure(\n 'DESTINATION_CONTRACT_MISMATCH',\n `Plan destination storage hash (${destination.storageHash}) does not match provided contract storage hash (${contract.storage.storageHash}).`,\n {\n meta: {\n planStorageHash: destination.storageHash,\n contractStorageHash: contract.storage.storageHash,\n },\n },\n );\n }\n if (\n destination.profileHash &&\n contract.profileHash &&\n destination.profileHash !== contract.profileHash\n ) {\n return runnerFailure(\n 'DESTINATION_CONTRACT_MISMATCH',\n `Plan destination profile hash (${destination.profileHash}) does not match provided contract profile hash (${contract.profileHash}).`,\n {\n meta: {\n planProfileHash: destination.profileHash,\n contractProfileHash: contract.profileHash,\n },\n },\n );\n }\n return okVoid();\n }\n\n private async upsertMarker(\n driver: SqlMigrationRunnerExecuteOptions<SqlitePlanTargetDetails>['driver'],\n options: SqlMigrationRunnerExecuteOptions<SqlitePlanTargetDetails>,\n existingMarker: ContractMarkerRecord | null,\n ): Promise<void> {\n // SQLite has no native array type, so we can't merge invariants in SQL\n // the way Postgres does. Merge client-side under the runner's\n // BEGIN EXCLUSIVE — sort + dedupe so the JSON-encoded value is stable.\n const merged = new Set<string>(existingMarker?.invariants ?? []);\n for (const inv of options.plan.providedInvariants) merged.add(inv);\n const invariants = Array.from(merged).sort();\n const writeStatements = buildWriteMarkerStatements({\n storageHash: options.plan.destination.storageHash,\n profileHash:\n options.plan.destination.profileHash ??\n options.destinationContract.profileHash ??\n options.plan.destination.storageHash,\n contractJson: options.destinationContract,\n canonicalVersion: null,\n meta: {},\n invariants,\n });\n const statement = existingMarker ? writeStatements.update : writeStatements.insert;\n await this.executeStatement(driver, statement);\n }\n\n private async recordLedgerEntry(\n driver: SqlMigrationRunnerExecuteOptions<SqlitePlanTargetDetails>['driver'],\n options: SqlMigrationRunnerExecuteOptions<SqlitePlanTargetDetails>,\n existingMarker: ContractMarkerRecord | null,\n executedOperations: readonly SqlMigrationPlanOperation<SqlitePlanTargetDetails>[],\n ): Promise<void> {\n const ledgerStatement = buildLedgerInsertStatement({\n originStorageHash: existingMarker?.storageHash ?? null,\n originProfileHash: existingMarker?.profileHash ?? null,\n destinationStorageHash: options.plan.destination.storageHash,\n destinationProfileHash:\n options.plan.destination.profileHash ??\n options.destinationContract.profileHash ??\n options.plan.destination.storageHash,\n contractJsonBefore: existingMarker?.contractJson ?? null,\n contractJsonAfter: options.destinationContract,\n operations: executedOperations,\n });\n await this.executeStatement(driver, ledgerStatement);\n }\n\n private async beginExclusiveTransaction(\n driver: SqlMigrationRunnerExecuteOptions<SqlitePlanTargetDetails>['driver'],\n ): Promise<void> {\n await driver.query('BEGIN EXCLUSIVE');\n }\n\n private async commitTransaction(\n driver: SqlMigrationRunnerExecuteOptions<SqlitePlanTargetDetails>['driver'],\n ): Promise<void> {\n await driver.query('COMMIT');\n }\n\n private async rollbackTransaction(\n driver: SqlMigrationRunnerExecuteOptions<SqlitePlanTargetDetails>['driver'],\n ): Promise<void> {\n await driver.query('ROLLBACK');\n }\n\n private async executeStatement(\n driver: SqlMigrationRunnerExecuteOptions<SqlitePlanTargetDetails>['driver'],\n statement: SqlStatement,\n ): Promise<void> {\n if (statement.params.length > 0) {\n await driver.query(statement.sql, statement.params);\n return;\n }\n await driver.query(statement.sql);\n }\n}\n","import type { ColumnDefault, Contract } from '@prisma-next/contract/types';\nimport type {\n SqlControlFamilyInstance,\n SqlControlTargetDescriptor,\n} from '@prisma-next/family-sql/control';\nimport { contractToSchemaIR } from '@prisma-next/family-sql/control';\nimport type {\n ControlTargetInstance,\n MigrationPlanner,\n MigrationRunner,\n} from '@prisma-next/framework-components/control';\nimport type { SqlStorage, StorageColumn } from '@prisma-next/sql-contract/types';\nimport { sqliteTargetDescriptorMeta } from './descriptor-meta';\nimport { createSqliteMigrationPlanner } from './migrations/planner';\nimport { renderDefaultLiteral } from './migrations/planner-ddl-builders';\nimport type { SqlitePlanTargetDetails } from './migrations/planner-target-details';\nimport { createSqliteMigrationRunner } from './migrations/runner';\n\nfunction sqliteRenderDefault(def: ColumnDefault, _column: StorageColumn): string {\n if (def.kind === 'function') {\n if (def.expression === 'now()') {\n return \"datetime('now')\";\n }\n return def.expression;\n }\n return renderDefaultLiteral(def.value);\n}\n\nconst sqliteControlTargetDescriptor: SqlControlTargetDescriptor<'sqlite', SqlitePlanTargetDetails> =\n {\n ...sqliteTargetDescriptorMeta,\n migrations: {\n createPlanner(_family: SqlControlFamilyInstance): MigrationPlanner<'sql', 'sqlite'> {\n return createSqliteMigrationPlanner();\n },\n createRunner(family) {\n return createSqliteMigrationRunner(family) as MigrationRunner<'sql', 'sqlite'>;\n },\n contractToSchema(contract, frameworkComponents) {\n return contractToSchemaIR(contract as Contract<SqlStorage> | null, {\n annotationNamespace: 'sqlite',\n renderDefault: sqliteRenderDefault,\n frameworkComponents: frameworkComponents ?? [],\n });\n },\n },\n create(): ControlTargetInstance<'sql', 'sqlite'> {\n return {\n familyId: 'sql',\n targetId: 'sqlite',\n };\n },\n createPlanner(_family: SqlControlFamilyInstance) {\n return createSqliteMigrationPlanner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,KAAK,UAAU,OAAO;AACnD;;AAEF,QAAM,OAAO,MAAM,UAAU,IAAI;;;;;;AC5jBrC,SAAS,oBAAoB,KAAoB,SAAgC;AAC/E,KAAI,IAAI,SAAS,YAAY;AAC3B,MAAI,IAAI,eAAe,QACrB,QAAO;AAET,SAAO,IAAI;;AAEb,QAAO,qBAAqB,IAAI,MAAM;;AAGxC,MAAMC,gCACJ;CACE,GAAG;CACH,YAAY;EACV,cAAc,SAAsE;AAClF,UAAO,8BAA8B;;EAEvC,aAAa,QAAQ;AACnB,UAAO,4BAA4B,OAAO;;EAE5C,iBAAiB,UAAU,qBAAqB;AAC9C,UAAO,mBAAmB,UAAyC;IACjE,qBAAqB;IACrB,eAAe;IACf,qBAAqB,uBAAuB,EAAE;IAC/C,CAAC;;EAEL;CACD,SAAiD;AAC/C,SAAO;GACL,UAAU;GACV,UAAU;GACX;;CAEH,cAAc,SAAmC;AAC/C,SAAO,8BAA8B;;CAEvC,aAAa,QAAQ;AACnB,SAAO,4BAA4B,OAAO;;CAE7C;AAEH,6BAAe"}
@@ -0,0 +1,69 @@
1
+ //#region src/core/default-normalizer.ts
2
+ const NULL_PATTERN = /^NULL$/i;
3
+ const INTEGER_PATTERN = /^-?\d+$/;
4
+ const REAL_PATTERN = /^-?\d+\.\d+(?:[eE][+-]?\d+)?$/;
5
+ const HEX_PATTERN = /^0[xX][\dA-Fa-f]+$/;
6
+ const STRING_LITERAL_PATTERN = /^'((?:[^']|'')*)'$/;
7
+ function isNumericLiteral(value) {
8
+ return INTEGER_PATTERN.test(value) || REAL_PATTERN.test(value) || HEX_PATTERN.test(value);
9
+ }
10
+ /**
11
+ * Strips a single matched wrapping pair of outer parens from `s`. Conservative:
12
+ * only strips when the leading `(` is matched by the trailing `)` (so
13
+ * `(a) + (b)` is returned unchanged). Mirrors SQLite's own
14
+ * `pragma_table_info.dflt_value` normalization for expression defaults, and
15
+ * is shared with the recreate-table postcheck builder so both sides agree
16
+ * on the canonical form.
17
+ */
18
+ function stripOuterParens(s) {
19
+ if (!s.startsWith("(") || !s.endsWith(")")) return s;
20
+ let depth = 0;
21
+ for (let i = 0; i < s.length; i++) if (s[i] === "(") depth += 1;
22
+ else if (s[i] === ")") {
23
+ depth -= 1;
24
+ if (depth === 0 && i < s.length - 1) return s;
25
+ }
26
+ return s.slice(1, -1);
27
+ }
28
+ function parseSqliteDefault(rawDefault, nativeType) {
29
+ let trimmed = rawDefault.trim();
30
+ while (true) {
31
+ const stripped = stripOuterParens(trimmed).trim();
32
+ if (stripped === trimmed) break;
33
+ trimmed = stripped;
34
+ }
35
+ const lower = trimmed.toLowerCase();
36
+ if (lower === "current_timestamp" || lower === "datetime('now')" || lower === "datetime(\"now\")") return {
37
+ kind: "function",
38
+ expression: "now()"
39
+ };
40
+ if (NULL_PATTERN.test(trimmed)) return {
41
+ kind: "literal",
42
+ value: null
43
+ };
44
+ if (isNumericLiteral(trimmed)) {
45
+ const num = Number(trimmed);
46
+ if (!Number.isFinite(num)) return void 0;
47
+ if (nativeType?.toLowerCase() === "integer" && !Number.isSafeInteger(num)) return {
48
+ kind: "literal",
49
+ value: trimmed
50
+ };
51
+ return {
52
+ kind: "literal",
53
+ value: num
54
+ };
55
+ }
56
+ const stringMatch = trimmed.match(STRING_LITERAL_PATTERN);
57
+ if (stringMatch?.[1] !== void 0) return {
58
+ kind: "literal",
59
+ value: stringMatch[1].replace(/''/g, "'")
60
+ };
61
+ return {
62
+ kind: "function",
63
+ expression: trimmed
64
+ };
65
+ }
66
+
67
+ //#endregion
68
+ export { stripOuterParens as n, parseSqliteDefault as t };
69
+ //# sourceMappingURL=default-normalizer-R-sQXAYt.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"default-normalizer-R-sQXAYt.mjs","names":[],"sources":["../src/core/default-normalizer.ts"],"sourcesContent":["/**\n * Normalizes SQLite's stored default expressions back into the\n * `ColumnDefault` shape the verifier compares against. Lives target-side\n * (mirroring Postgres's `target-postgres/src/core/default-normalizer.ts`)\n * so both the control adapter (`SqliteControlAdapter.introspect`) and the\n * planner / runner schema-verify path can consume it without\n * `target-sqlite` reaching into `adapter-sqlite`.\n */\n\nimport type { ColumnDefault } from '@prisma-next/contract/types';\n\nconst NULL_PATTERN = /^NULL$/i;\nconst INTEGER_PATTERN = /^-?\\d+$/;\nconst REAL_PATTERN = /^-?\\d+\\.\\d+(?:[eE][+-]?\\d+)?$/;\nconst HEX_PATTERN = /^0[xX][\\dA-Fa-f]+$/;\nconst STRING_LITERAL_PATTERN = /^'((?:[^']|'')*)'$/;\n\nfunction isNumericLiteral(value: string): boolean {\n return INTEGER_PATTERN.test(value) || REAL_PATTERN.test(value) || HEX_PATTERN.test(value);\n}\n\n/**\n * Strips a single matched wrapping pair of outer parens from `s`. Conservative:\n * only strips when the leading `(` is matched by the trailing `)` (so\n * `(a) + (b)` is returned unchanged). Mirrors SQLite's own\n * `pragma_table_info.dflt_value` normalization for expression defaults, and\n * is shared with the recreate-table postcheck builder so both sides agree\n * on the canonical form.\n */\nexport function stripOuterParens(s: string): string {\n if (!s.startsWith('(') || !s.endsWith(')')) return s;\n let depth = 0;\n for (let i = 0; i < s.length; i++) {\n if (s[i] === '(') depth += 1;\n else if (s[i] === ')') {\n depth -= 1;\n if (depth === 0 && i < s.length - 1) return s;\n }\n }\n return s.slice(1, -1);\n}\n\nexport function parseSqliteDefault(\n rawDefault: string,\n nativeType?: string,\n): ColumnDefault | undefined {\n let trimmed = rawDefault.trim();\n\n // Strip outer parentheses that SQLite adds around expressions. Iterate to\n // fixpoint so accidental double-wrapping (e.g. `((expr))`) collapses too.\n while (true) {\n const stripped = stripOuterParens(trimmed).trim();\n if (stripped === trimmed) break;\n trimmed = stripped;\n }\n\n // SQLite has several spellings for \"current timestamp\" — `CURRENT_TIMESTAMP`\n // (keyword) and `datetime('now')` / `datetime(\"now\")` (function call). The\n // contract authoring side canonicalizes `dbgenerated(\"CURRENT_TIMESTAMP\")`\n // (and friends) to `now()` via `lowerDbgenerated`; mirror that here so a\n // schema produced by either spelling round-trips to the same canonical\n // form for verification.\n const lower = trimmed.toLowerCase();\n if (lower === 'current_timestamp' || lower === \"datetime('now')\" || lower === 'datetime(\"now\")') {\n return { kind: 'function', expression: 'now()' };\n }\n\n if (NULL_PATTERN.test(trimmed)) {\n return { kind: 'literal', value: null };\n }\n\n // SQLite integers are 64-bit, so values outside the JS safe-integer range can't\n // be faithfully represented as `number`. Mirror `parsePostgresDefault`'s bigint\n // handling: parse as JS `number` when safe, fall back to the raw text otherwise.\n if (isNumericLiteral(trimmed)) {\n const num = Number(trimmed);\n if (!Number.isFinite(num)) return undefined;\n if (nativeType?.toLowerCase() === 'integer' && !Number.isSafeInteger(num)) {\n return { kind: 'literal', value: trimmed };\n }\n return { kind: 'literal', value: num };\n }\n\n const stringMatch = trimmed.match(STRING_LITERAL_PATTERN);\n if (stringMatch?.[1] !== undefined) {\n const unescaped = stringMatch[1].replace(/''/g, \"'\");\n return { kind: 'literal', value: unescaped };\n }\n\n // Unrecognized expression — preserve as function\n return { kind: 'function', expression: trimmed };\n}\n"],"mappings":";AAWA,MAAM,eAAe;AACrB,MAAM,kBAAkB;AACxB,MAAM,eAAe;AACrB,MAAM,cAAc;AACpB,MAAM,yBAAyB;AAE/B,SAAS,iBAAiB,OAAwB;AAChD,QAAO,gBAAgB,KAAK,MAAM,IAAI,aAAa,KAAK,MAAM,IAAI,YAAY,KAAK,MAAM;;;;;;;;;;AAW3F,SAAgB,iBAAiB,GAAmB;AAClD,KAAI,CAAC,EAAE,WAAW,IAAI,IAAI,CAAC,EAAE,SAAS,IAAI,CAAE,QAAO;CACnD,IAAI,QAAQ;AACZ,MAAK,IAAI,IAAI,GAAG,IAAI,EAAE,QAAQ,IAC5B,KAAI,EAAE,OAAO,IAAK,UAAS;UAClB,EAAE,OAAO,KAAK;AACrB,WAAS;AACT,MAAI,UAAU,KAAK,IAAI,EAAE,SAAS,EAAG,QAAO;;AAGhD,QAAO,EAAE,MAAM,GAAG,GAAG;;AAGvB,SAAgB,mBACd,YACA,YAC2B;CAC3B,IAAI,UAAU,WAAW,MAAM;AAI/B,QAAO,MAAM;EACX,MAAM,WAAW,iBAAiB,QAAQ,CAAC,MAAM;AACjD,MAAI,aAAa,QAAS;AAC1B,YAAU;;CASZ,MAAM,QAAQ,QAAQ,aAAa;AACnC,KAAI,UAAU,uBAAuB,UAAU,qBAAqB,UAAU,oBAC5E,QAAO;EAAE,MAAM;EAAY,YAAY;EAAS;AAGlD,KAAI,aAAa,KAAK,QAAQ,CAC5B,QAAO;EAAE,MAAM;EAAW,OAAO;EAAM;AAMzC,KAAI,iBAAiB,QAAQ,EAAE;EAC7B,MAAM,MAAM,OAAO,QAAQ;AAC3B,MAAI,CAAC,OAAO,SAAS,IAAI,CAAE,QAAO;AAClC,MAAI,YAAY,aAAa,KAAK,aAAa,CAAC,OAAO,cAAc,IAAI,CACvE,QAAO;GAAE,MAAM;GAAW,OAAO;GAAS;AAE5C,SAAO;GAAE,MAAM;GAAW,OAAO;GAAK;;CAGxC,MAAM,cAAc,QAAQ,MAAM,uBAAuB;AACzD,KAAI,cAAc,OAAO,OAEvB,QAAO;EAAE,MAAM;EAAW,OADR,YAAY,GAAG,QAAQ,OAAO,IAAI;EACR;AAI9C,QAAO;EAAE,MAAM;EAAY,YAAY;EAAS"}
@@ -0,0 +1,8 @@
1
+ import { ColumnDefault } from "@prisma-next/contract/types";
2
+
3
+ //#region src/core/default-normalizer.d.ts
4
+
5
+ declare function parseSqliteDefault(rawDefault: string, nativeType?: string): ColumnDefault | undefined;
6
+ //#endregion
7
+ export { parseSqliteDefault };
8
+ //# sourceMappingURL=default-normalizer.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"default-normalizer.d.mts","names":[],"sources":["../src/core/default-normalizer.ts"],"sourcesContent":[],"mappings":";;;;iBA0CgB,kBAAA,2CAGb"}
@@ -0,0 +1,3 @@
1
+ import { t as parseSqliteDefault } from "./default-normalizer-R-sQXAYt.mjs";
2
+
3
+ export { parseSqliteDefault };
@@ -0,0 +1,24 @@
1
+ import { temporalAuthoringPresets } from "@prisma-next/family-sql/control";
2
+
3
+ //#region src/core/authoring.ts
4
+ const sqliteAuthoringFieldPresets = { temporal: temporalAuthoringPresets({
5
+ codecId: "sqlite/datetime@1",
6
+ nativeType: "text"
7
+ }) };
8
+
9
+ //#endregion
10
+ //#region src/core/descriptor-meta.ts
11
+ const sqliteTargetDescriptorMetaBase = {
12
+ kind: "target",
13
+ familyId: "sql",
14
+ targetId: "sqlite",
15
+ id: "sqlite",
16
+ version: "0.0.1",
17
+ capabilities: {},
18
+ authoring: { field: sqliteAuthoringFieldPresets }
19
+ };
20
+ const sqliteTargetDescriptorMeta = sqliteTargetDescriptorMetaBase;
21
+
22
+ //#endregion
23
+ export { sqliteTargetDescriptorMeta as t };
24
+ //# sourceMappingURL=descriptor-meta-BA2YAFQq.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"descriptor-meta-BA2YAFQq.mjs","names":["sqliteTargetDescriptorMeta: typeof sqliteTargetDescriptorMetaBase & {\n readonly __codecTypes?: CodecTypes;\n}"],"sources":["../src/core/authoring.ts","../src/core/descriptor-meta.ts"],"sourcesContent":["import { temporalAuthoringPresets } from '@prisma-next/family-sql/control';\nimport type { AuthoringFieldNamespace } from '@prisma-next/framework-components/authoring';\n\nexport const sqliteAuthoringFieldPresets = {\n temporal: temporalAuthoringPresets({\n codecId: 'sqlite/datetime@1',\n nativeType: 'text',\n }),\n} as const satisfies AuthoringFieldNamespace;\n","import type { CodecTypes } from '../exports/codec-types';\nimport { sqliteAuthoringFieldPresets } from './authoring';\n\nconst sqliteTargetDescriptorMetaBase = {\n kind: 'target',\n familyId: 'sql',\n targetId: 'sqlite',\n id: 'sqlite',\n version: '0.0.1',\n capabilities: {},\n authoring: {\n field: sqliteAuthoringFieldPresets,\n },\n} as const;\n\nexport const sqliteTargetDescriptorMeta: typeof sqliteTargetDescriptorMetaBase & {\n readonly __codecTypes?: CodecTypes;\n} = sqliteTargetDescriptorMetaBase;\n"],"mappings":";;;AAGA,MAAa,8BAA8B,EACzC,UAAU,yBAAyB;CACjC,SAAS;CACT,YAAY;CACb,CAAC,EACH;;;;ACLD,MAAM,iCAAiC;CACrC,MAAM;CACN,UAAU;CACV,UAAU;CACV,IAAI;CACJ,SAAS;CACT,cAAc,EAAE;CAChB,WAAW,EACT,OAAO,6BACR;CACF;AAED,MAAaA,6BAET"}
@@ -0,0 +1,76 @@
1
+ import { i as SqliteTableSpec, n as SqliteColumnSpec, r as SqliteIndexSpec, t as Op } from "./shared-D_1fFqLf.mjs";
2
+ import { t as SqliteMigration } from "./sqlite-migration-BeR1cikr.mjs";
3
+ import { MigrationOperationClass } from "@prisma-next/family-sql/control";
4
+ import { placeholder } from "@prisma-next/errors/migration";
5
+ import { MigrationCLI } from "@prisma-next/cli/migration-cli";
6
+
7
+ //#region src/core/migrations/operations/columns.d.ts
8
+ declare function addColumn(tableName: string, column: SqliteColumnSpec): Op;
9
+ declare function dropColumn(tableName: string, columnName: string): Op;
10
+ //#endregion
11
+ //#region src/core/migrations/operations/data-transform.d.ts
12
+
13
+ interface DataTransformOptions {
14
+ /** Stable id used in the ledger / for runner idempotency tracking. */
15
+ readonly id: string;
16
+ /** Human-readable label surfaced in CLI output. */
17
+ readonly label: string;
18
+ /** Table the backfill targets; informs `target.details`. */
19
+ readonly table: string;
20
+ /**
21
+ * Short description of the step (shown by the runner on execute). The
22
+ * planner leaves this as `placeholder(...)` for users to replace.
23
+ */
24
+ readonly description: string;
25
+ /**
26
+ * Producer of the SQL string to execute. Invoked eagerly by
27
+ * `dataTransform(...)`, mirroring the Postgres factory — by the time the
28
+ * user calls this factory in `migration.ts`, the SQL is expected to be
29
+ * ready. Planner-emitted stubs that need to defer until the user fills
30
+ * in the SQL go through `DataTransformCall.renderTypeScript()` instead;
31
+ * this factory is only for the post-fill, runnable form.
32
+ */
33
+ readonly run: () => string;
34
+ }
35
+ declare function dataTransform(opts: DataTransformOptions): Op;
36
+ //#endregion
37
+ //#region src/core/migrations/operations/indexes.d.ts
38
+ declare function createIndex(tableName: string, indexName: string, columns: readonly string[]): Op;
39
+ declare function dropIndex(tableName: string, indexName: string): Op;
40
+ //#endregion
41
+ //#region src/core/migrations/operations/tables.d.ts
42
+ declare function createTable(tableName: string, spec: SqliteTableSpec): Op;
43
+ declare function dropTable(tableName: string): Op;
44
+ interface RecreateTableArgs {
45
+ readonly tableName: string;
46
+ /** New (post-recreate) shape of the table. Same flat spec as `createTable`. */
47
+ readonly contractTable: SqliteTableSpec;
48
+ /**
49
+ * Names of columns that exist in the live (pre-recreate) schema. Used to
50
+ * compute the `INSERT INTO temp ... SELECT ... FROM old` column list — only
51
+ * shared columns are copied, so dropped columns are left behind and added
52
+ * columns come from defaults.
53
+ */
54
+ readonly schemaColumnNames: readonly string[];
55
+ /**
56
+ * Indexes (declared + FK-backing, deduped by column-set) to recreate after
57
+ * the table has been replaced. The planner pre-merges these.
58
+ */
59
+ readonly indexes: readonly SqliteIndexSpec[];
60
+ /** Human-readable summary of the change, built by the planner from issues. */
61
+ readonly summary: string;
62
+ /**
63
+ * Per-issue postcheck steps appended after the structural postchecks. The
64
+ * planner pre-builds these via `buildRecreatePostchecks` so the call IR
65
+ * carries flat, serializable data only — no `SchemaIssue` references.
66
+ */
67
+ readonly postchecks: readonly {
68
+ readonly description: string;
69
+ readonly sql: string;
70
+ }[];
71
+ readonly operationClass: MigrationOperationClass;
72
+ }
73
+ declare function recreateTable(args: RecreateTableArgs): Op;
74
+ //#endregion
75
+ export { type DataTransformOptions, SqliteMigration as Migration, MigrationCLI, addColumn, createIndex, createTable, dataTransform, dropColumn, dropIndex, dropTable, placeholder, recreateTable };
76
+ //# sourceMappingURL=migration.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"migration.d.mts","names":[],"sources":["../src/core/migrations/operations/columns.ts","../src/core/migrations/operations/data-transform.ts","../src/core/migrations/operations/indexes.ts","../src/core/migrations/operations/tables.ts"],"sourcesContent":[],"mappings":";;;;;;;iBAIgB,SAAA,4BAAqC,mBAAmB;iBA+BxD,UAAA,yCAAmD;;;;ACInD,UAvBC,oBAAA,CAuBmB;;;;EClCpB,SAAA,KAAW,EAAA,MAAA;EAyBX;;;;ACchB;AAuBA;EAuBiB,SAAA,WAAiB,EAAA,MAAA;EAGR;;;;AAwB1B;;;;;;iBF9EgB,aAAA,OAAoB,uBAAuB;;;iBClC3C,WAAA,oEAA+E;iBAyB/E,SAAA,wCAAiD;;;iBCcjD,WAAA,0BAAqC,kBAAkB;iBAuBvD,SAAA,qBAA8B;UAuB7B,iBAAA;;EHtFD;EA+BA,SAAA,aAAU,EG0DA,eH1D2C;;;;ACnBrE;AAuBA;;;;AClCA;AAyBA;;6BC2E6B;;EA7Db,SAAA,OAAW,EAAA,MAAA;EAuBX;AAuBhB;;;;EAwBkD,SAAA,UAAA,EAAA,SAAA;IAGlC,SAAA,WAAa,EAAA,MAAO;;;2BAHT;;iBAGX,aAAA,OAAoB,oBAAoB"}