@prisma-next/target-sqlite 0.5.0-dev.4 → 0.5.0-dev.41
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/codec-ids-B1-OiN8Q.mjs +14 -0
- package/dist/codec-ids-B1-OiN8Q.mjs.map +1 -0
- package/dist/codec-ids.d.mts +13 -0
- package/dist/codec-ids.d.mts.map +1 -0
- package/dist/codec-ids.mjs +3 -0
- package/dist/codec-types.d.mts +7 -0
- package/dist/codec-types.d.mts.map +1 -0
- package/dist/codec-types.mjs +3 -0
- package/dist/codecs-5GJysiEg.mjs +95 -0
- package/dist/codecs-5GJysiEg.mjs.map +1 -0
- package/dist/codecs-D4jgBM6T.d.mts +139 -0
- package/dist/codecs-D4jgBM6T.d.mts.map +1 -0
- package/dist/codecs.d.mts +2 -0
- package/dist/codecs.mjs +3 -0
- package/dist/control.d.mts +4 -3
- package/dist/control.d.mts.map +1 -1
- package/dist/control.mjs +343 -1
- package/dist/control.mjs.map +1 -1
- package/dist/default-normalizer-R-sQXAYt.mjs +69 -0
- package/dist/default-normalizer-R-sQXAYt.mjs.map +1 -0
- package/dist/default-normalizer.d.mts +8 -0
- package/dist/default-normalizer.d.mts.map +1 -0
- package/dist/default-normalizer.mjs +3 -0
- package/dist/{descriptor-meta-DbuuziYA.mjs → descriptor-meta-CzGTszoH.mjs} +1 -1
- package/dist/descriptor-meta-CzGTszoH.mjs.map +1 -0
- package/dist/migration.d.mts +76 -0
- package/dist/migration.d.mts.map +1 -0
- package/dist/migration.mjs +38 -0
- package/dist/migration.mjs.map +1 -0
- package/dist/native-type-normalizer-BMovohPm.mjs +14 -0
- package/dist/native-type-normalizer-BMovohPm.mjs.map +1 -0
- package/dist/native-type-normalizer.d.mts +11 -0
- package/dist/native-type-normalizer.d.mts.map +1 -0
- package/dist/native-type-normalizer.mjs +3 -0
- package/dist/op-factory-call-BPPSCdTB.d.mts +134 -0
- package/dist/op-factory-call-BPPSCdTB.d.mts.map +1 -0
- package/dist/op-factory-call-BUVV-W9F.mjs +252 -0
- package/dist/op-factory-call-BUVV-W9F.mjs.map +1 -0
- package/dist/op-factory-call.d.mts +3 -0
- package/dist/op-factory-call.mjs +3 -0
- package/dist/pack.d.mts +1 -1
- package/dist/pack.mjs +1 -1
- package/dist/planner-CuchCrpN.mjs +522 -0
- package/dist/planner-CuchCrpN.mjs.map +1 -0
- package/dist/planner-produced-sqlite-migration-C3AAaQoW.mjs +107 -0
- package/dist/planner-produced-sqlite-migration-C3AAaQoW.mjs.map +1 -0
- package/dist/planner-produced-sqlite-migration-RVneETNy.d.mts +24 -0
- package/dist/planner-produced-sqlite-migration-RVneETNy.d.mts.map +1 -0
- package/dist/planner-produced-sqlite-migration.d.mts +5 -0
- package/dist/planner-produced-sqlite-migration.mjs +3 -0
- package/dist/planner-target-details-BQIWQlBu.mjs +16 -0
- package/dist/planner-target-details-BQIWQlBu.mjs.map +1 -0
- package/dist/planner-target-details-DTIFFx4L.d.mts +12 -0
- package/dist/planner-target-details-DTIFFx4L.d.mts.map +1 -0
- package/dist/planner-target-details.d.mts +2 -0
- package/dist/planner-target-details.mjs +3 -0
- package/dist/planner.d.mts +56 -0
- package/dist/planner.d.mts.map +1 -0
- package/dist/planner.mjs +3 -0
- package/dist/render-ops-CXOv7SRC.mjs +8 -0
- package/dist/render-ops-CXOv7SRC.mjs.map +1 -0
- package/dist/render-ops.d.mts +11 -0
- package/dist/render-ops.d.mts.map +1 -0
- package/dist/render-ops.mjs +3 -0
- package/dist/runtime.mjs +1 -1
- package/dist/shared-BNtoZqdo.d.mts +69 -0
- package/dist/shared-BNtoZqdo.d.mts.map +1 -0
- package/dist/sql-utils-D3SMPFDD.mjs +33 -0
- package/dist/sql-utils-D3SMPFDD.mjs.map +1 -0
- package/dist/sql-utils.d.mts +22 -0
- package/dist/sql-utils.d.mts.map +1 -0
- package/dist/sql-utils.mjs +3 -0
- package/dist/sqlite-migration-BYgrMZdR.d.mts +18 -0
- package/dist/sqlite-migration-BYgrMZdR.d.mts.map +1 -0
- package/dist/sqlite-migration-CnLhIrJF.mjs +17 -0
- package/dist/sqlite-migration-CnLhIrJF.mjs.map +1 -0
- package/dist/statement-builders-B3OGOp7n.mjs +148 -0
- package/dist/statement-builders-B3OGOp7n.mjs.map +1 -0
- package/dist/statement-builders.d.mts +48 -0
- package/dist/statement-builders.d.mts.map +1 -0
- package/dist/statement-builders.mjs +3 -0
- package/dist/tables-sKIg_lWE.mjs +408 -0
- package/dist/tables-sKIg_lWE.mjs.map +1 -0
- package/package.json +30 -9
- package/src/core/codec-ids.ts +13 -0
- package/src/core/codecs.ts +119 -0
- package/src/core/control-target.ts +54 -11
- package/src/core/default-normalizer.ts +92 -0
- package/src/core/descriptor-meta.ts +1 -1
- package/src/core/migrations/issue-planner.ts +586 -0
- package/src/core/migrations/op-factory-call.ts +332 -0
- package/src/core/migrations/operations/columns.ts +62 -0
- package/src/core/migrations/operations/data-transform.ts +51 -0
- package/src/core/migrations/operations/indexes.ts +52 -0
- package/src/core/migrations/operations/shared.ts +120 -0
- package/src/core/migrations/operations/tables.ts +388 -0
- package/src/core/migrations/planner-ddl-builders.ts +142 -0
- package/src/core/migrations/planner-produced-sqlite-migration.ts +56 -0
- package/src/core/migrations/planner-strategies.ts +231 -0
- package/src/core/migrations/planner-target-details.ts +33 -0
- package/src/core/migrations/planner.ts +149 -0
- package/src/core/migrations/render-ops.ts +9 -0
- package/src/core/migrations/render-typescript.ts +91 -0
- package/src/core/migrations/runner.ts +593 -0
- package/src/core/migrations/sqlite-migration.ts +13 -0
- package/src/core/migrations/statement-builders.ts +190 -0
- package/src/core/native-type-normalizer.ts +9 -0
- package/src/core/sql-utils.ts +47 -0
- package/src/exports/codec-ids.ts +13 -0
- package/src/exports/codec-types.ts +6 -0
- package/src/exports/codecs.ts +1 -0
- package/src/exports/control.ts +1 -0
- package/src/exports/default-normalizer.ts +1 -0
- package/src/exports/migration.ts +23 -0
- package/src/exports/native-type-normalizer.ts +1 -0
- package/src/exports/op-factory-call.ts +11 -0
- package/src/exports/planner-produced-sqlite-migration.ts +4 -0
- package/src/exports/planner-target-details.ts +2 -0
- package/src/exports/planner.ts +2 -0
- package/src/exports/render-ops.ts +1 -0
- package/src/exports/sql-utils.ts +1 -0
- package/src/exports/statement-builders.ts +11 -0
- package/dist/descriptor-meta-DbuuziYA.mjs.map +0 -1
|
@@ -0,0 +1,522 @@
|
|
|
1
|
+
import { t as parseSqliteDefault } from "./default-normalizer-R-sQXAYt.mjs";
|
|
2
|
+
import { t as normalizeSqliteNativeType } from "./native-type-normalizer-BMovohPm.mjs";
|
|
3
|
+
import { c as buildColumnDefaultSql, l as buildColumnTypeSql, n as buildRecreateSummary, t as buildRecreatePostchecks, u as isInlineAutoincrementPrimaryKey } from "./tables-sKIg_lWE.mjs";
|
|
4
|
+
import { a as DropColumnCall, c as RecreateTableCall, i as DataTransformCall, n as CreateIndexCall, o as DropIndexCall, r as CreateTableCall, s as DropTableCall, t as AddColumnCall } from "./op-factory-call-BUVV-W9F.mjs";
|
|
5
|
+
import { t as CONTROL_TABLE_NAMES } from "./statement-builders-B3OGOp7n.mjs";
|
|
6
|
+
import { t as TypeScriptRenderableSqliteMigration } from "./planner-produced-sqlite-migration-C3AAaQoW.mjs";
|
|
7
|
+
import { extractCodecControlHooks, plannerFailure } from "@prisma-next/family-sql/control";
|
|
8
|
+
import { verifySqlSchema } from "@prisma-next/family-sql/schema-verify";
|
|
9
|
+
import { defaultIndexName } from "@prisma-next/sql-schema-ir/naming";
|
|
10
|
+
import { notOk, ok } from "@prisma-next/utils/result";
|
|
11
|
+
|
|
12
|
+
//#region src/core/migrations/planner-strategies.ts
|
|
13
|
+
const WIDENING_ISSUE_KINDS = new Set(["default_mismatch", "default_missing"]);
|
|
14
|
+
const DESTRUCTIVE_ISSUE_KINDS = new Set([
|
|
15
|
+
"extra_default",
|
|
16
|
+
"type_mismatch",
|
|
17
|
+
"primary_key_mismatch",
|
|
18
|
+
"foreign_key_mismatch",
|
|
19
|
+
"unique_constraint_mismatch",
|
|
20
|
+
"extra_foreign_key",
|
|
21
|
+
"extra_unique_constraint",
|
|
22
|
+
"extra_primary_key"
|
|
23
|
+
]);
|
|
24
|
+
function classifyIssue(issue) {
|
|
25
|
+
if (issue.kind === "enum_values_changed") return null;
|
|
26
|
+
if (!issue.table) return null;
|
|
27
|
+
if (issue.kind === "nullability_mismatch") return issue.expected === "true" ? "widening" : "destructive";
|
|
28
|
+
if (WIDENING_ISSUE_KINDS.has(issue.kind)) return "widening";
|
|
29
|
+
if (DESTRUCTIVE_ISSUE_KINDS.has(issue.kind)) return "destructive";
|
|
30
|
+
return null;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Groups recreate-eligible issues by table, decides per-table operation class
|
|
34
|
+
* (destructive wins over widening), and emits one `RecreateTableCall` per
|
|
35
|
+
* table. Returns unchanged-or-smaller issue list — issues the strategy
|
|
36
|
+
* consumed are removed so `mapIssueToCall` doesn't double-handle them.
|
|
37
|
+
*/
|
|
38
|
+
const recreateTableStrategy = (issues, ctx) => {
|
|
39
|
+
const byTable = /* @__PURE__ */ new Map();
|
|
40
|
+
const consumed = /* @__PURE__ */ new Set();
|
|
41
|
+
for (const issue of issues) {
|
|
42
|
+
const cls = classifyIssue(issue);
|
|
43
|
+
if (!cls) continue;
|
|
44
|
+
if (issue.kind === "enum_values_changed") continue;
|
|
45
|
+
if (!issue.table) continue;
|
|
46
|
+
const table = issue.table;
|
|
47
|
+
const entry = byTable.get(table);
|
|
48
|
+
if (entry) {
|
|
49
|
+
entry.issues.push(issue);
|
|
50
|
+
if (cls === "destructive") entry.hasDestructive = true;
|
|
51
|
+
} else byTable.set(table, {
|
|
52
|
+
issues: [issue],
|
|
53
|
+
hasDestructive: cls === "destructive"
|
|
54
|
+
});
|
|
55
|
+
consumed.add(issue);
|
|
56
|
+
}
|
|
57
|
+
if (byTable.size === 0) return { kind: "no_match" };
|
|
58
|
+
const calls = [];
|
|
59
|
+
for (const [tableName, entry] of byTable) {
|
|
60
|
+
const contractTable = ctx.toContract.storage.tables[tableName];
|
|
61
|
+
const schemaTable = ctx.schema.tables[tableName];
|
|
62
|
+
if (!contractTable || !schemaTable) continue;
|
|
63
|
+
const operationClass = entry.hasDestructive ? "destructive" : "widening";
|
|
64
|
+
const tableSpec = toTableSpec(contractTable, ctx.storageTypes);
|
|
65
|
+
const seenIndexColumnKeys = /* @__PURE__ */ new Set();
|
|
66
|
+
const indexes = [];
|
|
67
|
+
for (const idx of contractTable.indexes) {
|
|
68
|
+
const key = idx.columns.join(",");
|
|
69
|
+
if (seenIndexColumnKeys.has(key)) continue;
|
|
70
|
+
seenIndexColumnKeys.add(key);
|
|
71
|
+
indexes.push({
|
|
72
|
+
name: idx.name ?? defaultIndexName(tableName, idx.columns),
|
|
73
|
+
columns: idx.columns
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
for (const fk of contractTable.foreignKeys) {
|
|
77
|
+
if (fk.index === false) continue;
|
|
78
|
+
const key = fk.columns.join(",");
|
|
79
|
+
if (seenIndexColumnKeys.has(key)) continue;
|
|
80
|
+
seenIndexColumnKeys.add(key);
|
|
81
|
+
indexes.push({
|
|
82
|
+
name: defaultIndexName(tableName, fk.columns),
|
|
83
|
+
columns: fk.columns
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
calls.push(new RecreateTableCall({
|
|
87
|
+
tableName,
|
|
88
|
+
contractTable: tableSpec,
|
|
89
|
+
schemaColumnNames: Object.keys(schemaTable.columns),
|
|
90
|
+
indexes,
|
|
91
|
+
summary: buildRecreateSummary(tableName, entry.issues),
|
|
92
|
+
postchecks: buildRecreatePostchecks(tableName, entry.issues, tableSpec),
|
|
93
|
+
operationClass
|
|
94
|
+
}));
|
|
95
|
+
}
|
|
96
|
+
return {
|
|
97
|
+
kind: "match",
|
|
98
|
+
issues: issues.filter((i) => !consumed.has(i)),
|
|
99
|
+
calls,
|
|
100
|
+
recipe: true
|
|
101
|
+
};
|
|
102
|
+
};
|
|
103
|
+
/**
|
|
104
|
+
* When the policy allows `'data'` and the contract tightens one or more
|
|
105
|
+
* columns from nullable to NOT NULL, emit a `DataTransformCall` stub per
|
|
106
|
+
* tightened column. The user fills the backfill `UPDATE` in the rendered
|
|
107
|
+
* `migration.ts` before the subsequent `RecreateTableCall` copies data into
|
|
108
|
+
* the tightened schema (whose `INSERT INTO temp SELECT … FROM old` would
|
|
109
|
+
* otherwise fail at runtime if any `NULL`s remain).
|
|
110
|
+
*
|
|
111
|
+
* Does NOT consume the tightening issue — `recreateTableStrategy` still
|
|
112
|
+
* needs it to produce the actual recreate that enforces the NOT NULL at
|
|
113
|
+
* the schema level. The backfill op and the recreate op end up in the
|
|
114
|
+
* recipe slot in strategy order (backfill first, recreate second), which
|
|
115
|
+
* matches the required execution order.
|
|
116
|
+
*
|
|
117
|
+
* Mirrors Postgres's `nullableTighteningCallStrategy` / `'data'`-class
|
|
118
|
+
* gating. When `'data'` is not in the policy (the default `db update` /
|
|
119
|
+
* `db init` path), the strategy short-circuits and the recreate alone
|
|
120
|
+
* runs with its current destructive-class gating — preserving today's
|
|
121
|
+
* behavior where a tightening blows up at runtime if NULLs are present.
|
|
122
|
+
*/
|
|
123
|
+
const nullabilityTighteningBackfillStrategy = (issues, ctx) => {
|
|
124
|
+
if (!ctx.policy.allowedOperationClasses.includes("data")) return { kind: "no_match" };
|
|
125
|
+
const calls = [];
|
|
126
|
+
for (const issue of issues) {
|
|
127
|
+
if (issue.kind !== "nullability_mismatch") continue;
|
|
128
|
+
if (!issue.table || !issue.column) continue;
|
|
129
|
+
if (issue.expected === "true") continue;
|
|
130
|
+
const column = ctx.toContract.storage.tables[issue.table]?.columns[issue.column];
|
|
131
|
+
if (!column || column.nullable === true) continue;
|
|
132
|
+
calls.push(new DataTransformCall(`data_migration.backfill-${issue.table}-${issue.column}`, `Backfill NULLs in "${issue.table}"."${issue.column}" before NOT NULL tightening`, issue.table, issue.column));
|
|
133
|
+
}
|
|
134
|
+
if (calls.length === 0) return { kind: "no_match" };
|
|
135
|
+
return {
|
|
136
|
+
kind: "match",
|
|
137
|
+
issues,
|
|
138
|
+
calls,
|
|
139
|
+
recipe: true
|
|
140
|
+
};
|
|
141
|
+
};
|
|
142
|
+
const sqlitePlannerStrategies = [nullabilityTighteningBackfillStrategy, recreateTableStrategy];
|
|
143
|
+
|
|
144
|
+
//#endregion
|
|
145
|
+
//#region src/core/migrations/issue-planner.ts
|
|
146
|
+
const ISSUE_KIND_ORDER = {
|
|
147
|
+
extra_foreign_key: 10,
|
|
148
|
+
extra_unique_constraint: 11,
|
|
149
|
+
extra_primary_key: 12,
|
|
150
|
+
extra_index: 13,
|
|
151
|
+
extra_default: 14,
|
|
152
|
+
extra_column: 15,
|
|
153
|
+
extra_table: 16,
|
|
154
|
+
missing_table: 20,
|
|
155
|
+
missing_column: 30,
|
|
156
|
+
type_mismatch: 40,
|
|
157
|
+
nullability_mismatch: 41,
|
|
158
|
+
default_missing: 42,
|
|
159
|
+
default_mismatch: 43,
|
|
160
|
+
primary_key_mismatch: 50,
|
|
161
|
+
unique_constraint_mismatch: 51,
|
|
162
|
+
index_mismatch: 52,
|
|
163
|
+
foreign_key_mismatch: 60
|
|
164
|
+
};
|
|
165
|
+
function issueOrder(issue) {
|
|
166
|
+
return ISSUE_KIND_ORDER[issue.kind] ?? 99;
|
|
167
|
+
}
|
|
168
|
+
function issueKey(issue) {
|
|
169
|
+
return `${"table" in issue && typeof issue.table === "string" ? issue.table : ""}\u0000${"column" in issue && typeof issue.column === "string" ? issue.column : ""}\u0000${"indexOrConstraint" in issue && typeof issue.indexOrConstraint === "string" ? issue.indexOrConstraint : ""}`;
|
|
170
|
+
}
|
|
171
|
+
function issueConflict(kind, summary, location) {
|
|
172
|
+
return {
|
|
173
|
+
kind,
|
|
174
|
+
summary,
|
|
175
|
+
why: "Use `migration new` to author a custom migration for this change.",
|
|
176
|
+
...location ? { location } : {}
|
|
177
|
+
};
|
|
178
|
+
}
|
|
179
|
+
function conflictKindForIssue(issue) {
|
|
180
|
+
switch (issue.kind) {
|
|
181
|
+
case "type_mismatch": return "typeMismatch";
|
|
182
|
+
case "nullability_mismatch": return "nullabilityConflict";
|
|
183
|
+
case "primary_key_mismatch":
|
|
184
|
+
case "unique_constraint_mismatch":
|
|
185
|
+
case "index_mismatch":
|
|
186
|
+
case "extra_primary_key":
|
|
187
|
+
case "extra_unique_constraint": return "indexIncompatible";
|
|
188
|
+
case "foreign_key_mismatch":
|
|
189
|
+
case "extra_foreign_key": return "foreignKeyConflict";
|
|
190
|
+
default: return "missingButNonAdditive";
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
function issueLocation(issue) {
|
|
194
|
+
if (issue.kind === "enum_values_changed") return void 0;
|
|
195
|
+
const location = {};
|
|
196
|
+
if (issue.table) location.table = issue.table;
|
|
197
|
+
if (issue.column) location.column = issue.column;
|
|
198
|
+
if (issue.indexOrConstraint) location.constraint = issue.indexOrConstraint;
|
|
199
|
+
return Object.keys(location).length > 0 ? location : void 0;
|
|
200
|
+
}
|
|
201
|
+
function conflictForDisallowedCall(call, allowed) {
|
|
202
|
+
const summary = `Operation "${call.label}" requires class "${call.operationClass}", but policy allows only: ${allowed.join(", ")}`;
|
|
203
|
+
const location = locationForCall(call);
|
|
204
|
+
return {
|
|
205
|
+
kind: conflictKindForCall(call),
|
|
206
|
+
summary,
|
|
207
|
+
why: "Use `migration new` to author a custom migration for this change.",
|
|
208
|
+
...location ? { location } : {}
|
|
209
|
+
};
|
|
210
|
+
}
|
|
211
|
+
function conflictKindForCall(call) {
|
|
212
|
+
switch (call.factoryName) {
|
|
213
|
+
case "createIndex":
|
|
214
|
+
case "dropIndex": return "indexIncompatible";
|
|
215
|
+
default: return "missingButNonAdditive";
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
function locationForCall(call) {
|
|
219
|
+
const location = {};
|
|
220
|
+
if ("tableName" in call) location.table = call.tableName;
|
|
221
|
+
if ("columnName" in call) location.column = call.columnName;
|
|
222
|
+
if ("indexName" in call) location.index = call.indexName;
|
|
223
|
+
return Object.keys(location).length > 0 ? location : void 0;
|
|
224
|
+
}
|
|
225
|
+
function isMissing(issue) {
|
|
226
|
+
if (issue.kind === "enum_values_changed") return false;
|
|
227
|
+
return issue.actual === void 0;
|
|
228
|
+
}
|
|
229
|
+
/**
|
|
230
|
+
* Resolves codec / `typeRef` / default rendering into a flat
|
|
231
|
+
* `SqliteColumnSpec`. Mirrors Postgres's `toColumnSpec`. Once a column is
|
|
232
|
+
* flattened, downstream Calls and operation factories never see
|
|
233
|
+
* `StorageColumn` again — they deal in pre-rendered SQL fragments.
|
|
234
|
+
*/
|
|
235
|
+
function toColumnSpec(name, column, storageTypes, inlineAutoincrementPrimaryKey = false) {
|
|
236
|
+
return {
|
|
237
|
+
name,
|
|
238
|
+
typeSql: buildColumnTypeSql(column, storageTypes),
|
|
239
|
+
defaultSql: buildColumnDefaultSql(column.default),
|
|
240
|
+
nullable: column.nullable,
|
|
241
|
+
...inlineAutoincrementPrimaryKey ? { inlineAutoincrementPrimaryKey: true } : {}
|
|
242
|
+
};
|
|
243
|
+
}
|
|
244
|
+
/**
|
|
245
|
+
* Flattens a `StorageTable` into a `SqliteTableSpec` ready for
|
|
246
|
+
* `CreateTableCall` / `RecreateTableCall`. Sole-column AUTOINCREMENT
|
|
247
|
+
* primary keys are detected here and marked on the column spec so the
|
|
248
|
+
* renderer emits `INTEGER PRIMARY KEY AUTOINCREMENT` inline.
|
|
249
|
+
*/
|
|
250
|
+
function toTableSpec(table, storageTypes) {
|
|
251
|
+
const columns = Object.entries(table.columns).map(([name, column]) => toColumnSpec(name, column, storageTypes, isInlineAutoincrementPrimaryKey(table, name)));
|
|
252
|
+
const uniques = table.uniques.map((u) => ({
|
|
253
|
+
columns: u.columns,
|
|
254
|
+
...u.name !== void 0 ? { name: u.name } : {}
|
|
255
|
+
}));
|
|
256
|
+
const foreignKeys = table.foreignKeys.map((fk) => ({
|
|
257
|
+
columns: fk.columns,
|
|
258
|
+
references: {
|
|
259
|
+
table: fk.references.table,
|
|
260
|
+
columns: fk.references.columns
|
|
261
|
+
},
|
|
262
|
+
constraint: fk.constraint !== false,
|
|
263
|
+
...fk.name !== void 0 ? { name: fk.name } : {},
|
|
264
|
+
...fk.onDelete !== void 0 ? { onDelete: fk.onDelete } : {},
|
|
265
|
+
...fk.onUpdate !== void 0 ? { onUpdate: fk.onUpdate } : {}
|
|
266
|
+
}));
|
|
267
|
+
return {
|
|
268
|
+
columns,
|
|
269
|
+
...table.primaryKey ? { primaryKey: { columns: table.primaryKey.columns } } : {},
|
|
270
|
+
uniques,
|
|
271
|
+
foreignKeys
|
|
272
|
+
};
|
|
273
|
+
}
|
|
274
|
+
const DEFAULT_POLICY = { allowedOperationClasses: [
|
|
275
|
+
"additive",
|
|
276
|
+
"widening",
|
|
277
|
+
"destructive",
|
|
278
|
+
"data"
|
|
279
|
+
] };
|
|
280
|
+
function emptySchemaIR() {
|
|
281
|
+
return {
|
|
282
|
+
tables: {},
|
|
283
|
+
dependencies: []
|
|
284
|
+
};
|
|
285
|
+
}
|
|
286
|
+
function mapIssueToCall(issue, ctx) {
|
|
287
|
+
switch (issue.kind) {
|
|
288
|
+
case "missing_table": {
|
|
289
|
+
if (!issue.table) return notOk(issueConflict("unsupportedOperation", "Missing table issue has no table name"));
|
|
290
|
+
const contractTable = ctx.toContract.storage.tables[issue.table];
|
|
291
|
+
if (!contractTable) return notOk(issueConflict("unsupportedOperation", `Table "${issue.table}" reported missing but not found in destination contract`));
|
|
292
|
+
const tableSpec = toTableSpec(contractTable, ctx.storageTypes);
|
|
293
|
+
const calls = [new CreateTableCall(issue.table, tableSpec)];
|
|
294
|
+
const declaredIndexColumnKeys = /* @__PURE__ */ new Set();
|
|
295
|
+
for (const index of contractTable.indexes) {
|
|
296
|
+
const indexName = index.name ?? defaultIndexName(issue.table, index.columns);
|
|
297
|
+
declaredIndexColumnKeys.add(index.columns.join(","));
|
|
298
|
+
calls.push(new CreateIndexCall(issue.table, indexName, index.columns));
|
|
299
|
+
}
|
|
300
|
+
for (const fk of contractTable.foreignKeys) {
|
|
301
|
+
if (fk.index === false) continue;
|
|
302
|
+
if (declaredIndexColumnKeys.has(fk.columns.join(","))) continue;
|
|
303
|
+
const indexName = defaultIndexName(issue.table, fk.columns);
|
|
304
|
+
calls.push(new CreateIndexCall(issue.table, indexName, fk.columns));
|
|
305
|
+
}
|
|
306
|
+
return ok(calls);
|
|
307
|
+
}
|
|
308
|
+
case "missing_column": {
|
|
309
|
+
if (!issue.table || !issue.column) return notOk(issueConflict("unsupportedOperation", "Missing column issue has no table/column name"));
|
|
310
|
+
const column = ctx.toContract.storage.tables[issue.table]?.columns[issue.column];
|
|
311
|
+
if (!column) return notOk(issueConflict("unsupportedOperation", `Column "${issue.table}"."${issue.column}" not in destination contract`));
|
|
312
|
+
const contractTable = ctx.toContract.storage.tables[issue.table];
|
|
313
|
+
const columnSpec = toColumnSpec(issue.column, column, ctx.storageTypes, contractTable ? isInlineAutoincrementPrimaryKey(contractTable, issue.column) : false);
|
|
314
|
+
return ok([new AddColumnCall(issue.table, columnSpec)]);
|
|
315
|
+
}
|
|
316
|
+
case "index_mismatch": {
|
|
317
|
+
if (!issue.table) return notOk(issueConflict("indexIncompatible", "Index issue has no table name"));
|
|
318
|
+
if (!isMissing(issue) || !issue.expected) return notOk(issueConflict("indexIncompatible", `Index on "${issue.table}" differs (expected: ${issue.expected}, actual: ${issue.actual})`, { table: issue.table }));
|
|
319
|
+
const columns = issue.expected.split(", ");
|
|
320
|
+
const contractTable = ctx.toContract.storage.tables[issue.table];
|
|
321
|
+
if (!contractTable) return notOk(issueConflict("unsupportedOperation", `Table "${issue.table}" not found in destination contract`));
|
|
322
|
+
const indexName = contractTable.indexes.find((idx) => idx.columns.join(",") === columns.join(","))?.name ?? defaultIndexName(issue.table, columns);
|
|
323
|
+
return ok([new CreateIndexCall(issue.table, indexName, columns)]);
|
|
324
|
+
}
|
|
325
|
+
case "extra_table":
|
|
326
|
+
if (!issue.table) return notOk(issueConflict("unsupportedOperation", "Extra table issue has no table name"));
|
|
327
|
+
if (CONTROL_TABLE_NAMES.has(issue.table)) return ok([]);
|
|
328
|
+
return ok([new DropTableCall(issue.table)]);
|
|
329
|
+
case "extra_column":
|
|
330
|
+
if (!issue.table || !issue.column) return notOk(issueConflict("unsupportedOperation", "Extra column issue has no table/column name"));
|
|
331
|
+
return ok([new DropColumnCall(issue.table, issue.column)]);
|
|
332
|
+
case "extra_index":
|
|
333
|
+
if (!issue.table || !issue.indexOrConstraint) return notOk(issueConflict("unsupportedOperation", "Extra index issue has no table/index name"));
|
|
334
|
+
return ok([new DropIndexCall(issue.table, issue.indexOrConstraint)]);
|
|
335
|
+
case "enum_values_changed": return notOk(issueConflict("unsupportedOperation", "Received enum_values_changed against a SQLite schema (sql.enums: false) — verifier bug"));
|
|
336
|
+
case "type_mismatch":
|
|
337
|
+
case "nullability_mismatch":
|
|
338
|
+
case "default_mismatch":
|
|
339
|
+
case "default_missing":
|
|
340
|
+
case "extra_default":
|
|
341
|
+
case "primary_key_mismatch":
|
|
342
|
+
case "unique_constraint_mismatch":
|
|
343
|
+
case "foreign_key_mismatch":
|
|
344
|
+
case "extra_foreign_key":
|
|
345
|
+
case "extra_unique_constraint":
|
|
346
|
+
case "extra_primary_key": return notOk(issueConflict(conflictKindForIssue(issue), issue.message, issueLocation(issue)));
|
|
347
|
+
default: return notOk(issueConflict("unsupportedOperation", `Unhandled issue kind: ${issue.kind}`));
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
function classifyCall(call) {
|
|
351
|
+
switch (call.factoryName) {
|
|
352
|
+
case "createTable": return "create-table";
|
|
353
|
+
case "addColumn": return "add-column";
|
|
354
|
+
case "createIndex": return "create-index";
|
|
355
|
+
case "dropColumn": return "drop-column";
|
|
356
|
+
case "dropIndex": return "drop-index";
|
|
357
|
+
case "dropTable": return "drop-table";
|
|
358
|
+
case "recreateTable": return null;
|
|
359
|
+
default: return null;
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
function planIssues(options) {
|
|
363
|
+
const policyProvided = options.policy !== void 0;
|
|
364
|
+
const policy = options.policy ?? DEFAULT_POLICY;
|
|
365
|
+
const schema = options.schema ?? emptySchemaIR();
|
|
366
|
+
const frameworkComponents = options.frameworkComponents ?? [];
|
|
367
|
+
const context = {
|
|
368
|
+
toContract: options.toContract,
|
|
369
|
+
fromContract: options.fromContract,
|
|
370
|
+
codecHooks: options.codecHooks,
|
|
371
|
+
storageTypes: options.storageTypes,
|
|
372
|
+
schema,
|
|
373
|
+
policy,
|
|
374
|
+
frameworkComponents
|
|
375
|
+
};
|
|
376
|
+
const strategies = options.strategies ?? sqlitePlannerStrategies;
|
|
377
|
+
let remaining = options.issues;
|
|
378
|
+
const recipeCalls = [];
|
|
379
|
+
const bucketableCalls = [];
|
|
380
|
+
for (const strategy of strategies) {
|
|
381
|
+
const result = strategy(remaining, context);
|
|
382
|
+
if (result.kind === "match") {
|
|
383
|
+
remaining = result.issues;
|
|
384
|
+
if (result.recipe) recipeCalls.push(...result.calls);
|
|
385
|
+
else bucketableCalls.push(...result.calls);
|
|
386
|
+
}
|
|
387
|
+
}
|
|
388
|
+
const sorted = [...remaining].sort((a, b) => {
|
|
389
|
+
const kindDelta = issueOrder(a) - issueOrder(b);
|
|
390
|
+
if (kindDelta !== 0) return kindDelta;
|
|
391
|
+
const keyA = issueKey(a);
|
|
392
|
+
const keyB = issueKey(b);
|
|
393
|
+
return keyA < keyB ? -1 : keyA > keyB ? 1 : 0;
|
|
394
|
+
});
|
|
395
|
+
const defaultCalls = [];
|
|
396
|
+
const conflicts = [];
|
|
397
|
+
for (const issue of sorted) {
|
|
398
|
+
const result = mapIssueToCall(issue, context);
|
|
399
|
+
if (result.ok) defaultCalls.push(...result.value);
|
|
400
|
+
else conflicts.push(result.failure);
|
|
401
|
+
}
|
|
402
|
+
const allowed = policy.allowedOperationClasses;
|
|
403
|
+
let gatedRecipe = recipeCalls;
|
|
404
|
+
let gatedBucketable = bucketableCalls;
|
|
405
|
+
let gatedDefault = defaultCalls;
|
|
406
|
+
if (policyProvided) {
|
|
407
|
+
const sink = (acc) => (call) => {
|
|
408
|
+
if (allowed.includes(call.operationClass)) {
|
|
409
|
+
acc.push(call);
|
|
410
|
+
return;
|
|
411
|
+
}
|
|
412
|
+
conflicts.push(conflictForDisallowedCall(call, allowed));
|
|
413
|
+
};
|
|
414
|
+
const gatedRecipeBucket = [];
|
|
415
|
+
const gatedBucketableBucket = [];
|
|
416
|
+
const gatedDefaultBucket = [];
|
|
417
|
+
recipeCalls.forEach(sink(gatedRecipeBucket));
|
|
418
|
+
bucketableCalls.forEach(sink(gatedBucketableBucket));
|
|
419
|
+
defaultCalls.forEach(sink(gatedDefaultBucket));
|
|
420
|
+
gatedRecipe = gatedRecipeBucket;
|
|
421
|
+
gatedBucketable = gatedBucketableBucket;
|
|
422
|
+
gatedDefault = gatedDefaultBucket;
|
|
423
|
+
}
|
|
424
|
+
if (conflicts.length > 0) return notOk(conflicts);
|
|
425
|
+
const combined = [...gatedDefault, ...gatedBucketable];
|
|
426
|
+
const byCategory = (cat) => combined.filter((c) => classifyCall(c) === cat);
|
|
427
|
+
return ok({ calls: [
|
|
428
|
+
...byCategory("create-table"),
|
|
429
|
+
...byCategory("add-column"),
|
|
430
|
+
...byCategory("create-index"),
|
|
431
|
+
...gatedRecipe,
|
|
432
|
+
...byCategory("drop-column"),
|
|
433
|
+
...byCategory("drop-index"),
|
|
434
|
+
...byCategory("drop-table")
|
|
435
|
+
] });
|
|
436
|
+
}
|
|
437
|
+
|
|
438
|
+
//#endregion
|
|
439
|
+
//#region src/core/migrations/planner.ts
|
|
440
|
+
function createSqliteMigrationPlanner() {
|
|
441
|
+
return new SqliteMigrationPlanner();
|
|
442
|
+
}
|
|
443
|
+
/**
|
|
444
|
+
* SQLite migration planner — a thin wrapper over `planIssues`.
|
|
445
|
+
*
|
|
446
|
+
* `plan()` verifies the live schema against the target contract (producing
|
|
447
|
+
* `SchemaIssue[]`) and delegates to `planIssues` with the registered
|
|
448
|
+
* strategies. Strategies absorb groups of related issues into composite
|
|
449
|
+
* recipes (e.g. recreating a table to apply type/nullability/default/
|
|
450
|
+
* constraint changes at once); anything not absorbed by a strategy flows
|
|
451
|
+
* through `mapIssueToCall` in the issue planner as a one-off call.
|
|
452
|
+
*
|
|
453
|
+
* FK-backing indexes are surfaced by `verifySqlSchema`'s index expansion
|
|
454
|
+
* (see `verify-sql-schema.ts:459-469`), so `mapIssueToCall` handles them
|
|
455
|
+
* uniformly alongside user-declared indexes.
|
|
456
|
+
*/
|
|
457
|
+
var SqliteMigrationPlanner = class {
|
|
458
|
+
plan(options) {
|
|
459
|
+
return this.planSql(options);
|
|
460
|
+
}
|
|
461
|
+
emptyMigration(context) {
|
|
462
|
+
return new TypeScriptRenderableSqliteMigration([], {
|
|
463
|
+
from: context.fromHash,
|
|
464
|
+
to: context.toHash
|
|
465
|
+
});
|
|
466
|
+
}
|
|
467
|
+
planSql(options) {
|
|
468
|
+
const policyResult = this.ensureAdditivePolicy(options.policy);
|
|
469
|
+
if (policyResult) return policyResult;
|
|
470
|
+
const schemaIssues = this.collectSchemaIssues(options);
|
|
471
|
+
const codecHooks = extractCodecControlHooks(options.frameworkComponents);
|
|
472
|
+
const storageTypes = options.contract.storage.types ?? {};
|
|
473
|
+
const result = planIssues({
|
|
474
|
+
issues: schemaIssues,
|
|
475
|
+
toContract: options.contract,
|
|
476
|
+
fromContract: options.fromContract,
|
|
477
|
+
codecHooks,
|
|
478
|
+
storageTypes,
|
|
479
|
+
schema: options.schema,
|
|
480
|
+
policy: options.policy,
|
|
481
|
+
frameworkComponents: options.frameworkComponents,
|
|
482
|
+
strategies: sqlitePlannerStrategies
|
|
483
|
+
});
|
|
484
|
+
if (!result.ok) return plannerFailure(result.failure);
|
|
485
|
+
const destination = {
|
|
486
|
+
storageHash: options.contract.storage.storageHash,
|
|
487
|
+
...options.contract.profileHash !== void 0 ? { profileHash: options.contract.profileHash } : {}
|
|
488
|
+
};
|
|
489
|
+
return {
|
|
490
|
+
kind: "success",
|
|
491
|
+
plan: new TypeScriptRenderableSqliteMigration(result.value.calls, {
|
|
492
|
+
from: options.fromContract?.storage.storageHash ?? null,
|
|
493
|
+
to: options.contract.storage.storageHash
|
|
494
|
+
}, destination)
|
|
495
|
+
};
|
|
496
|
+
}
|
|
497
|
+
ensureAdditivePolicy(policy) {
|
|
498
|
+
if (!policy.allowedOperationClasses.includes("additive")) return plannerFailure([{
|
|
499
|
+
kind: "unsupportedOperation",
|
|
500
|
+
summary: "Migration planner requires additive operations be allowed",
|
|
501
|
+
why: "The planner requires the \"additive\" operation class to be allowed in the policy."
|
|
502
|
+
}]);
|
|
503
|
+
return null;
|
|
504
|
+
}
|
|
505
|
+
collectSchemaIssues(options) {
|
|
506
|
+
const allowed = options.policy.allowedOperationClasses;
|
|
507
|
+
const strict = allowed.includes("widening") || allowed.includes("destructive");
|
|
508
|
+
return verifySqlSchema({
|
|
509
|
+
contract: options.contract,
|
|
510
|
+
schema: options.schema,
|
|
511
|
+
strict,
|
|
512
|
+
typeMetadataRegistry: /* @__PURE__ */ new Map(),
|
|
513
|
+
frameworkComponents: options.frameworkComponents,
|
|
514
|
+
normalizeDefault: parseSqliteDefault,
|
|
515
|
+
normalizeNativeType: normalizeSqliteNativeType
|
|
516
|
+
}).schema.issues;
|
|
517
|
+
}
|
|
518
|
+
};
|
|
519
|
+
|
|
520
|
+
//#endregion
|
|
521
|
+
export { createSqliteMigrationPlanner as n, SqliteMigrationPlanner as t };
|
|
522
|
+
//# sourceMappingURL=planner-CuchCrpN.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"planner-CuchCrpN.mjs","names":["recreateTableStrategy: CallMigrationStrategy","calls: SqliteOpFactoryCall[]","operationClass: MigrationOperationClass","indexes: SqliteIndexSpec[]","nullabilityTighteningBackfillStrategy: CallMigrationStrategy","sqlitePlannerStrategies: readonly CallMigrationStrategy[]","ISSUE_KIND_ORDER: Record<string, number>","location: {\n table?: string;\n column?: string;\n constraint?: string;\n }","location: { table?: string; column?: string; index?: string }","columns: SqliteColumnSpec[]","uniques: SqliteUniqueSpec[]","foreignKeys: SqliteForeignKeySpec[]","DEFAULT_POLICY: MigrationOperationPolicy","calls: SqliteOpFactoryCall[]","context: StrategyContext","recipeCalls: SqliteOpFactoryCall[]","bucketableCalls: SqliteOpFactoryCall[]","defaultCalls: SqliteOpFactoryCall[]","conflicts: SqlPlannerConflict[]","gatedRecipeBucket: SqliteOpFactoryCall[]","gatedBucketableBucket: SqliteOpFactoryCall[]","gatedDefaultBucket: SqliteOpFactoryCall[]","destination: SqliteMigrationDestinationInfo"],"sources":["../src/core/migrations/planner-strategies.ts","../src/core/migrations/issue-planner.ts","../src/core/migrations/planner.ts"],"sourcesContent":["/**\n * SQLite migration strategies.\n *\n * Each strategy examines the issue list, consumes issues it handles, and\n * returns the `SqliteOpFactoryCall[]` to address them. The issue planner\n * runs each strategy in order and routes whatever's left through\n * `mapIssueToCall`.\n *\n * SQLite has no enums, no data-safe backfill, and no component-declared\n * database dependencies. The only recipe that needs strategy-level\n * multi-issue consumption is `recreateTable` (added in a later phase), which\n * absorbs type/nullability/default/constraint mismatches for a given table\n * into a single recreate operation.\n */\n\nimport type { Contract } from '@prisma-next/contract/types';\nimport type {\n CodecControlHooks,\n MigrationOperationClass,\n MigrationOperationPolicy,\n} from '@prisma-next/family-sql/control';\nimport type { TargetBoundComponentDescriptor } from '@prisma-next/framework-components/components';\nimport type { SchemaIssue } from '@prisma-next/framework-components/control';\nimport type { SqlStorage, StorageTypeInstance } from '@prisma-next/sql-contract/types';\nimport { defaultIndexName } from '@prisma-next/sql-schema-ir/naming';\nimport type { SqlSchemaIR } from '@prisma-next/sql-schema-ir/types';\nimport { toTableSpec } from './issue-planner';\nimport { DataTransformCall, RecreateTableCall, type SqliteOpFactoryCall } from './op-factory-call';\nimport type { SqliteIndexSpec } from './operations/shared';\nimport { buildRecreatePostchecks, buildRecreateSummary } from './operations/tables';\n\nexport interface StrategyContext {\n readonly toContract: Contract<SqlStorage>;\n readonly fromContract: Contract<SqlStorage> | null;\n readonly codecHooks: ReadonlyMap<string, CodecControlHooks>;\n readonly storageTypes: Readonly<Record<string, StorageTypeInstance>>;\n readonly schema: SqlSchemaIR;\n readonly policy: MigrationOperationPolicy;\n readonly frameworkComponents: ReadonlyArray<TargetBoundComponentDescriptor<'sql', string>>;\n}\n\nexport type CallMigrationStrategy = (\n issues: readonly SchemaIssue[],\n context: StrategyContext,\n) =>\n | {\n kind: 'match';\n issues: readonly SchemaIssue[];\n calls: readonly SqliteOpFactoryCall[];\n recipe?: boolean;\n }\n | { kind: 'no_match' };\n\n// ============================================================================\n// Recreate-table strategy\n// ============================================================================\n\nconst WIDENING_ISSUE_KINDS = new Set<SchemaIssue['kind']>(['default_mismatch', 'default_missing']);\n\nconst DESTRUCTIVE_ISSUE_KINDS = new Set<SchemaIssue['kind']>([\n 'extra_default',\n 'type_mismatch',\n 'primary_key_mismatch',\n 'foreign_key_mismatch',\n 'unique_constraint_mismatch',\n 'extra_foreign_key',\n 'extra_unique_constraint',\n 'extra_primary_key',\n]);\n\nfunction classifyIssue(issue: SchemaIssue): 'widening' | 'destructive' | null {\n if (issue.kind === 'enum_values_changed') return null;\n if (!issue.table) return null;\n if (issue.kind === 'nullability_mismatch') {\n // Relaxing (NOT NULL → nullable) is widening; tightening is destructive.\n return issue.expected === 'true' ? 'widening' : 'destructive';\n }\n if (WIDENING_ISSUE_KINDS.has(issue.kind)) return 'widening';\n if (DESTRUCTIVE_ISSUE_KINDS.has(issue.kind)) return 'destructive';\n return null;\n}\n\n/**\n * Groups recreate-eligible issues by table, decides per-table operation class\n * (destructive wins over widening), and emits one `RecreateTableCall` per\n * table. Returns unchanged-or-smaller issue list — issues the strategy\n * consumed are removed so `mapIssueToCall` doesn't double-handle them.\n */\nexport const recreateTableStrategy: CallMigrationStrategy = (issues, ctx) => {\n const byTable = new Map<string, { issues: SchemaIssue[]; hasDestructive: boolean }>();\n const consumed = new Set<SchemaIssue>();\n\n for (const issue of issues) {\n const cls = classifyIssue(issue);\n if (!cls) continue;\n if (issue.kind === 'enum_values_changed') continue;\n if (!issue.table) continue;\n const table = issue.table;\n const entry = byTable.get(table);\n if (entry) {\n entry.issues.push(issue);\n if (cls === 'destructive') entry.hasDestructive = true;\n } else {\n byTable.set(table, { issues: [issue], hasDestructive: cls === 'destructive' });\n }\n consumed.add(issue);\n }\n\n if (byTable.size === 0) return { kind: 'no_match' };\n\n const calls: SqliteOpFactoryCall[] = [];\n for (const [tableName, entry] of byTable) {\n const contractTable = ctx.toContract.storage.tables[tableName];\n const schemaTable = ctx.schema.tables[tableName];\n if (!contractTable || !schemaTable) continue;\n const operationClass: MigrationOperationClass = entry.hasDestructive\n ? 'destructive'\n : 'widening';\n\n // Flatten the contract table to a self-contained spec — the Call holds\n // pre-rendered SQL fragments only, no `StorageColumn` or `storageTypes`.\n const tableSpec = toTableSpec(contractTable, ctx.storageTypes);\n\n const seenIndexColumnKeys = new Set<string>();\n const indexes: SqliteIndexSpec[] = [];\n for (const idx of contractTable.indexes) {\n const key = idx.columns.join(',');\n if (seenIndexColumnKeys.has(key)) continue;\n seenIndexColumnKeys.add(key);\n indexes.push({\n name: idx.name ?? defaultIndexName(tableName, idx.columns),\n columns: idx.columns,\n });\n }\n for (const fk of contractTable.foreignKeys) {\n if (fk.index === false) continue;\n const key = fk.columns.join(',');\n if (seenIndexColumnKeys.has(key)) continue;\n seenIndexColumnKeys.add(key);\n indexes.push({\n name: defaultIndexName(tableName, fk.columns),\n columns: fk.columns,\n });\n }\n\n calls.push(\n new RecreateTableCall({\n tableName,\n contractTable: tableSpec,\n schemaColumnNames: Object.keys(schemaTable.columns),\n indexes,\n summary: buildRecreateSummary(tableName, entry.issues),\n postchecks: buildRecreatePostchecks(tableName, entry.issues, tableSpec),\n operationClass,\n }),\n );\n }\n\n return {\n kind: 'match',\n issues: issues.filter((i) => !consumed.has(i)),\n calls,\n recipe: true,\n };\n};\n\n// ============================================================================\n// Nullability-tightening backfill strategy\n// ============================================================================\n\n/**\n * When the policy allows `'data'` and the contract tightens one or more\n * columns from nullable to NOT NULL, emit a `DataTransformCall` stub per\n * tightened column. The user fills the backfill `UPDATE` in the rendered\n * `migration.ts` before the subsequent `RecreateTableCall` copies data into\n * the tightened schema (whose `INSERT INTO temp SELECT … FROM old` would\n * otherwise fail at runtime if any `NULL`s remain).\n *\n * Does NOT consume the tightening issue — `recreateTableStrategy` still\n * needs it to produce the actual recreate that enforces the NOT NULL at\n * the schema level. The backfill op and the recreate op end up in the\n * recipe slot in strategy order (backfill first, recreate second), which\n * matches the required execution order.\n *\n * Mirrors Postgres's `nullableTighteningCallStrategy` / `'data'`-class\n * gating. When `'data'` is not in the policy (the default `db update` /\n * `db init` path), the strategy short-circuits and the recreate alone\n * runs with its current destructive-class gating — preserving today's\n * behavior where a tightening blows up at runtime if NULLs are present.\n */\nexport const nullabilityTighteningBackfillStrategy: CallMigrationStrategy = (issues, ctx) => {\n if (!ctx.policy.allowedOperationClasses.includes('data')) {\n return { kind: 'no_match' };\n }\n\n const calls: SqliteOpFactoryCall[] = [];\n for (const issue of issues) {\n if (issue.kind !== 'nullability_mismatch') continue;\n if (!issue.table || !issue.column) continue;\n // Tightening only: `expected === 'true'` means the contract wants the\n // column nullable (relaxing from NOT NULL → nullable), which is safe and\n // needs no backfill.\n if (issue.expected === 'true') continue;\n\n const column = ctx.toContract.storage.tables[issue.table]?.columns[issue.column];\n if (!column || column.nullable === true) continue;\n\n calls.push(\n new DataTransformCall(\n `data_migration.backfill-${issue.table}-${issue.column}`,\n `Backfill NULLs in \"${issue.table}\".\"${issue.column}\" before NOT NULL tightening`,\n issue.table,\n issue.column,\n ),\n );\n }\n\n if (calls.length === 0) return { kind: 'no_match' };\n\n return {\n kind: 'match',\n issues,\n calls,\n recipe: true,\n };\n};\n\nexport const sqlitePlannerStrategies: readonly CallMigrationStrategy[] = [\n nullabilityTighteningBackfillStrategy,\n recreateTableStrategy,\n];\n","/**\n * SQLite migration issue planner.\n *\n * Takes schema issues (from `verifySqlSchema`) and emits migration IR\n * (`SqliteOpFactoryCall[]`). Strategies consume issues they recognize and\n * produce specialized call sequences (e.g. recreateTableStrategy absorbs\n * type/nullability/default/constraint mismatches into a single recreate op);\n * remaining issues flow through `mapIssueToCall` for the default case.\n */\n\nimport type { Contract } from '@prisma-next/contract/types';\nimport type {\n CodecControlHooks,\n MigrationOperationPolicy,\n SqlPlannerConflict,\n SqlPlannerConflictLocation,\n} from '@prisma-next/family-sql/control';\nimport type { TargetBoundComponentDescriptor } from '@prisma-next/framework-components/components';\nimport type { SchemaIssue } from '@prisma-next/framework-components/control';\nimport type {\n SqlStorage,\n StorageColumn,\n StorageTable,\n StorageTypeInstance,\n} from '@prisma-next/sql-contract/types';\nimport { defaultIndexName } from '@prisma-next/sql-schema-ir/naming';\nimport type { SqlSchemaIR } from '@prisma-next/sql-schema-ir/types';\nimport type { Result } from '@prisma-next/utils/result';\nimport { notOk, ok } from '@prisma-next/utils/result';\nimport {\n AddColumnCall,\n CreateIndexCall,\n CreateTableCall,\n DropColumnCall,\n DropIndexCall,\n DropTableCall,\n type SqliteOpFactoryCall,\n} from './op-factory-call';\nimport type {\n SqliteColumnSpec,\n SqliteForeignKeySpec,\n SqliteTableSpec,\n SqliteUniqueSpec,\n} from './operations/shared';\nimport {\n buildColumnDefaultSql,\n buildColumnTypeSql,\n isInlineAutoincrementPrimaryKey,\n} from './planner-ddl-builders';\nimport {\n type CallMigrationStrategy,\n type StrategyContext,\n sqlitePlannerStrategies,\n} from './planner-strategies';\nimport { CONTROL_TABLE_NAMES } from './statement-builders';\n\nexport type { CallMigrationStrategy, StrategyContext };\n\n// ============================================================================\n// Issue kind ordering (dependency order)\n// ============================================================================\n\nconst ISSUE_KIND_ORDER: Record<string, number> = {\n // Drops (reconciliation — clear the way for creates)\n extra_foreign_key: 10,\n extra_unique_constraint: 11,\n extra_primary_key: 12,\n extra_index: 13,\n extra_default: 14,\n extra_column: 15,\n extra_table: 16,\n\n // Tables before columns\n missing_table: 20,\n\n // Columns before constraints\n missing_column: 30,\n\n // Reconciliation alters (on existing objects)\n type_mismatch: 40,\n nullability_mismatch: 41,\n default_missing: 42,\n default_mismatch: 43,\n\n // Constraints after columns exist\n primary_key_mismatch: 50,\n unique_constraint_mismatch: 51,\n index_mismatch: 52,\n foreign_key_mismatch: 60,\n};\n\nfunction issueOrder(issue: SchemaIssue): number {\n return ISSUE_KIND_ORDER[issue.kind] ?? 99;\n}\n\nfunction issueKey(issue: SchemaIssue): string {\n const table = 'table' in issue && typeof issue.table === 'string' ? issue.table : '';\n const column = 'column' in issue && typeof issue.column === 'string' ? issue.column : '';\n const name =\n 'indexOrConstraint' in issue && typeof issue.indexOrConstraint === 'string'\n ? issue.indexOrConstraint\n : '';\n return `${table}\\u0000${column}\\u0000${name}`;\n}\n\n// ============================================================================\n// Conflict helpers\n// ============================================================================\n\nfunction issueConflict(\n kind: SqlPlannerConflict['kind'],\n summary: string,\n location?: SqlPlannerConflict['location'],\n): SqlPlannerConflict {\n return {\n kind,\n summary,\n why: 'Use `migration new` to author a custom migration for this change.',\n ...(location ? { location } : {}),\n };\n}\n\nfunction conflictKindForIssue(issue: SchemaIssue): SqlPlannerConflict['kind'] {\n switch (issue.kind) {\n case 'type_mismatch':\n return 'typeMismatch';\n case 'nullability_mismatch':\n return 'nullabilityConflict';\n case 'primary_key_mismatch':\n case 'unique_constraint_mismatch':\n case 'index_mismatch':\n case 'extra_primary_key':\n case 'extra_unique_constraint':\n return 'indexIncompatible';\n case 'foreign_key_mismatch':\n case 'extra_foreign_key':\n return 'foreignKeyConflict';\n default:\n return 'missingButNonAdditive';\n }\n}\n\nfunction issueLocation(issue: SchemaIssue): SqlPlannerConflictLocation | undefined {\n if (issue.kind === 'enum_values_changed') return undefined;\n const location: {\n table?: string;\n column?: string;\n constraint?: string;\n } = {};\n if (issue.table) location.table = issue.table;\n if (issue.column) location.column = issue.column;\n if (issue.indexOrConstraint) location.constraint = issue.indexOrConstraint;\n return Object.keys(location).length > 0 ? (location as SqlPlannerConflictLocation) : undefined;\n}\n\nfunction conflictForDisallowedCall(\n call: SqliteOpFactoryCall,\n allowed: readonly string[],\n): SqlPlannerConflict {\n const summary = `Operation \"${call.label}\" requires class \"${call.operationClass}\", but policy allows only: ${allowed.join(', ')}`;\n const location = locationForCall(call);\n return {\n kind: conflictKindForCall(call),\n summary,\n why: 'Use `migration new` to author a custom migration for this change.',\n ...(location ? { location } : {}),\n };\n}\n\nfunction conflictKindForCall(call: SqliteOpFactoryCall): SqlPlannerConflict['kind'] {\n switch (call.factoryName) {\n case 'createIndex':\n case 'dropIndex':\n return 'indexIncompatible';\n default:\n return 'missingButNonAdditive';\n }\n}\n\nfunction locationForCall(call: SqliteOpFactoryCall): SqlPlannerConflictLocation | undefined {\n const location: { table?: string; column?: string; index?: string } = {};\n if ('tableName' in call) location.table = call.tableName;\n if ('columnName' in call) location.column = call.columnName;\n if ('indexName' in call) location.index = call.indexName;\n return Object.keys(location).length > 0 ? (location as SqlPlannerConflictLocation) : undefined;\n}\n\nfunction isMissing(issue: SchemaIssue): boolean {\n if (issue.kind === 'enum_values_changed') return false;\n return issue.actual === undefined;\n}\n\n// ============================================================================\n// StorageTable / StorageColumn → flat SqliteTableSpec\n// ============================================================================\n\n/**\n * Resolves codec / `typeRef` / default rendering into a flat\n * `SqliteColumnSpec`. Mirrors Postgres's `toColumnSpec`. Once a column is\n * flattened, downstream Calls and operation factories never see\n * `StorageColumn` again — they deal in pre-rendered SQL fragments.\n */\nexport function toColumnSpec(\n name: string,\n column: StorageColumn,\n storageTypes: Readonly<Record<string, StorageTypeInstance>>,\n inlineAutoincrementPrimaryKey = false,\n): SqliteColumnSpec {\n const typeSql = buildColumnTypeSql(column, storageTypes as Record<string, StorageTypeInstance>);\n const defaultSql = buildColumnDefaultSql(column.default);\n return {\n name,\n typeSql,\n defaultSql,\n nullable: column.nullable,\n ...(inlineAutoincrementPrimaryKey ? { inlineAutoincrementPrimaryKey: true } : {}),\n };\n}\n\n/**\n * Flattens a `StorageTable` into a `SqliteTableSpec` ready for\n * `CreateTableCall` / `RecreateTableCall`. Sole-column AUTOINCREMENT\n * primary keys are detected here and marked on the column spec so the\n * renderer emits `INTEGER PRIMARY KEY AUTOINCREMENT` inline.\n */\nexport function toTableSpec(\n table: StorageTable,\n storageTypes: Readonly<Record<string, StorageTypeInstance>>,\n): SqliteTableSpec {\n const columns: SqliteColumnSpec[] = Object.entries(table.columns).map(([name, column]) =>\n toColumnSpec(name, column, storageTypes, isInlineAutoincrementPrimaryKey(table, name)),\n );\n const uniques: SqliteUniqueSpec[] = table.uniques.map((u) => ({\n columns: u.columns,\n ...(u.name !== undefined ? { name: u.name } : {}),\n }));\n const foreignKeys: SqliteForeignKeySpec[] = table.foreignKeys.map((fk) => ({\n columns: fk.columns,\n references: { table: fk.references.table, columns: fk.references.columns },\n constraint: fk.constraint !== false,\n ...(fk.name !== undefined ? { name: fk.name } : {}),\n ...(fk.onDelete !== undefined ? { onDelete: fk.onDelete } : {}),\n ...(fk.onUpdate !== undefined ? { onUpdate: fk.onUpdate } : {}),\n }));\n return {\n columns,\n ...(table.primaryKey ? { primaryKey: { columns: table.primaryKey.columns } } : {}),\n uniques,\n foreignKeys,\n };\n}\n\n// ============================================================================\n// Issue planner\n// ============================================================================\n\nexport interface IssuePlannerOptions {\n readonly issues: readonly SchemaIssue[];\n readonly toContract: Contract<SqlStorage>;\n readonly fromContract: Contract<SqlStorage> | null;\n readonly codecHooks: ReadonlyMap<string, CodecControlHooks>;\n readonly storageTypes: Readonly<Record<string, StorageTypeInstance>>;\n readonly schema?: SqlSchemaIR;\n readonly policy?: MigrationOperationPolicy;\n readonly frameworkComponents?: ReadonlyArray<TargetBoundComponentDescriptor<'sql', string>>;\n readonly strategies?: readonly CallMigrationStrategy[];\n}\n\nexport interface IssuePlannerValue {\n readonly calls: readonly SqliteOpFactoryCall[];\n}\n\nconst DEFAULT_POLICY: MigrationOperationPolicy = {\n allowedOperationClasses: ['additive', 'widening', 'destructive', 'data'],\n};\n\nfunction emptySchemaIR(): SqlSchemaIR {\n return { tables: {}, dependencies: [] };\n}\n\n// ============================================================================\n// Issue → Call mapping (per-issue default path)\n// ============================================================================\n\nfunction mapIssueToCall(\n issue: SchemaIssue,\n ctx: StrategyContext,\n): Result<readonly SqliteOpFactoryCall[], SqlPlannerConflict> {\n switch (issue.kind) {\n case 'missing_table': {\n if (!issue.table) {\n return notOk(\n issueConflict('unsupportedOperation', 'Missing table issue has no table name'),\n );\n }\n const contractTable = ctx.toContract.storage.tables[issue.table];\n if (!contractTable) {\n return notOk(\n issueConflict(\n 'unsupportedOperation',\n `Table \"${issue.table}\" reported missing but not found in destination contract`,\n ),\n );\n }\n const tableSpec = toTableSpec(contractTable, ctx.storageTypes);\n const calls: SqliteOpFactoryCall[] = [new CreateTableCall(issue.table, tableSpec)];\n const declaredIndexColumnKeys = new Set<string>();\n for (const index of contractTable.indexes) {\n const indexName = index.name ?? defaultIndexName(issue.table, index.columns);\n declaredIndexColumnKeys.add(index.columns.join(','));\n calls.push(new CreateIndexCall(issue.table, indexName, index.columns));\n }\n for (const fk of contractTable.foreignKeys) {\n if (fk.index === false) continue;\n if (declaredIndexColumnKeys.has(fk.columns.join(','))) continue;\n const indexName = defaultIndexName(issue.table, fk.columns);\n calls.push(new CreateIndexCall(issue.table, indexName, fk.columns));\n }\n return ok(calls);\n }\n\n case 'missing_column': {\n if (!issue.table || !issue.column) {\n return notOk(\n issueConflict('unsupportedOperation', 'Missing column issue has no table/column name'),\n );\n }\n const column = ctx.toContract.storage.tables[issue.table]?.columns[issue.column];\n if (!column) {\n return notOk(\n issueConflict(\n 'unsupportedOperation',\n `Column \"${issue.table}\".\"${issue.column}\" not in destination contract`,\n ),\n );\n }\n const contractTable = ctx.toContract.storage.tables[issue.table];\n const columnSpec = toColumnSpec(\n issue.column,\n column,\n ctx.storageTypes,\n contractTable ? isInlineAutoincrementPrimaryKey(contractTable, issue.column) : false,\n );\n return ok([new AddColumnCall(issue.table, columnSpec)]);\n }\n\n case 'index_mismatch': {\n if (!issue.table) {\n return notOk(issueConflict('indexIncompatible', 'Index issue has no table name'));\n }\n if (!isMissing(issue) || !issue.expected) {\n return notOk(\n issueConflict(\n 'indexIncompatible',\n `Index on \"${issue.table}\" differs (expected: ${issue.expected}, actual: ${issue.actual})`,\n { table: issue.table },\n ),\n );\n }\n const columns = issue.expected.split(', ');\n const contractTable = ctx.toContract.storage.tables[issue.table];\n if (!contractTable) {\n return notOk(\n issueConflict(\n 'unsupportedOperation',\n `Table \"${issue.table}\" not found in destination contract`,\n ),\n );\n }\n // Use the explicit-index name if one is declared for these columns;\n // otherwise fall back to `defaultIndexName` (which is also what\n // `verifySqlSchema` synthesizes for FK-backing indexes). Whether the\n // missing index originates from `contractTable.indexes` or from an FK\n // with `index: true` doesn't change the emitted DDL.\n const explicitIndex = contractTable.indexes.find(\n (idx) => idx.columns.join(',') === columns.join(','),\n );\n const indexName = explicitIndex?.name ?? defaultIndexName(issue.table, columns);\n return ok([new CreateIndexCall(issue.table, indexName, columns)]);\n }\n\n case 'extra_table': {\n if (!issue.table) {\n return notOk(issueConflict('unsupportedOperation', 'Extra table issue has no table name'));\n }\n // Runner-owned control tables must never be dropped.\n if (CONTROL_TABLE_NAMES.has(issue.table)) return ok([]);\n return ok([new DropTableCall(issue.table)]);\n }\n\n case 'extra_column': {\n if (!issue.table || !issue.column) {\n return notOk(\n issueConflict('unsupportedOperation', 'Extra column issue has no table/column name'),\n );\n }\n return ok([new DropColumnCall(issue.table, issue.column)]);\n }\n\n case 'extra_index': {\n if (!issue.table || !issue.indexOrConstraint) {\n return notOk(\n issueConflict('unsupportedOperation', 'Extra index issue has no table/index name'),\n );\n }\n return ok([new DropIndexCall(issue.table, issue.indexOrConstraint)]);\n }\n\n // SQLite has no enum types (capability `sql.enums: false`). The verifier\n // should never emit `enum_values_changed` against a SQLite schema, so if\n // we receive one it is a verifier bug — surface it as an explicit\n // conflict rather than silently dropping it.\n case 'enum_values_changed':\n return notOk(\n issueConflict(\n 'unsupportedOperation',\n 'Received enum_values_changed against a SQLite schema (sql.enums: false) — verifier bug',\n ),\n );\n\n // Everything below is absorbed by recreateTableStrategy. If it falls\n // through here, policy or context didn't allow the recreate — surface as\n // a conflict.\n case 'type_mismatch':\n case 'nullability_mismatch':\n case 'default_mismatch':\n case 'default_missing':\n case 'extra_default':\n case 'primary_key_mismatch':\n case 'unique_constraint_mismatch':\n case 'foreign_key_mismatch':\n case 'extra_foreign_key':\n case 'extra_unique_constraint':\n case 'extra_primary_key':\n return notOk(issueConflict(conflictKindForIssue(issue), issue.message, issueLocation(issue)));\n\n default:\n return notOk(\n issueConflict(\n 'unsupportedOperation',\n `Unhandled issue kind: ${(issue as SchemaIssue).kind}`,\n ),\n );\n }\n}\n\n// ============================================================================\n// Call categorization for final emission order\n// ============================================================================\n\ntype CallCategory =\n | 'drop-column'\n | 'drop-index'\n | 'drop-table'\n | 'create-table'\n | 'add-column'\n | 'create-index';\n\nfunction classifyCall(call: SqliteOpFactoryCall): CallCategory | null {\n switch (call.factoryName) {\n case 'createTable':\n return 'create-table';\n case 'addColumn':\n return 'add-column';\n case 'createIndex':\n return 'create-index';\n case 'dropColumn':\n return 'drop-column';\n case 'dropIndex':\n return 'drop-index';\n case 'dropTable':\n return 'drop-table';\n // recreateTable goes into the recipe slot; return null for bucketable.\n case 'recreateTable':\n return null;\n default:\n return null;\n }\n}\n\n// ============================================================================\n// Top-level planIssues\n// ============================================================================\n\nexport function planIssues(\n options: IssuePlannerOptions,\n): Result<IssuePlannerValue, readonly SqlPlannerConflict[]> {\n const policyProvided = options.policy !== undefined;\n const policy = options.policy ?? DEFAULT_POLICY;\n const schema = options.schema ?? emptySchemaIR();\n const frameworkComponents = options.frameworkComponents ?? [];\n\n const context: StrategyContext = {\n toContract: options.toContract,\n fromContract: options.fromContract,\n codecHooks: options.codecHooks,\n storageTypes: options.storageTypes,\n schema,\n policy,\n frameworkComponents,\n };\n\n const strategies = options.strategies ?? sqlitePlannerStrategies;\n\n let remaining = options.issues;\n const recipeCalls: SqliteOpFactoryCall[] = [];\n const bucketableCalls: SqliteOpFactoryCall[] = [];\n\n for (const strategy of strategies) {\n const result = strategy(remaining, context);\n if (result.kind === 'match') {\n remaining = result.issues;\n if (result.recipe) {\n recipeCalls.push(...result.calls);\n } else {\n bucketableCalls.push(...result.calls);\n }\n }\n }\n\n const sorted = [...remaining].sort((a, b) => {\n const kindDelta = issueOrder(a) - issueOrder(b);\n if (kindDelta !== 0) return kindDelta;\n const keyA = issueKey(a);\n const keyB = issueKey(b);\n return keyA < keyB ? -1 : keyA > keyB ? 1 : 0;\n });\n\n const defaultCalls: SqliteOpFactoryCall[] = [];\n const conflicts: SqlPlannerConflict[] = [];\n\n for (const issue of sorted) {\n const result = mapIssueToCall(issue, context);\n if (result.ok) {\n defaultCalls.push(...result.value);\n } else {\n conflicts.push(result.failure);\n }\n }\n\n // Policy gating for recipe + bucketable. Default-mapped calls for disallowed\n // classes never get here (they're surfaced as per-issue conflicts above).\n const allowed = policy.allowedOperationClasses;\n let gatedRecipe = recipeCalls;\n let gatedBucketable = bucketableCalls;\n let gatedDefault = defaultCalls;\n if (policyProvided) {\n const sink = (acc: SqliteOpFactoryCall[]) => (call: SqliteOpFactoryCall) => {\n if (allowed.includes(call.operationClass)) {\n acc.push(call);\n return;\n }\n conflicts.push(conflictForDisallowedCall(call, allowed));\n };\n const gatedRecipeBucket: SqliteOpFactoryCall[] = [];\n const gatedBucketableBucket: SqliteOpFactoryCall[] = [];\n const gatedDefaultBucket: SqliteOpFactoryCall[] = [];\n recipeCalls.forEach(sink(gatedRecipeBucket));\n bucketableCalls.forEach(sink(gatedBucketableBucket));\n defaultCalls.forEach(sink(gatedDefaultBucket));\n gatedRecipe = gatedRecipeBucket;\n gatedBucketable = gatedBucketableBucket;\n gatedDefault = gatedDefaultBucket;\n }\n\n if (conflicts.length > 0) {\n return notOk(conflicts);\n }\n\n // Final emission order matches the current monolithic planner:\n // create-table → add-column → create-index → recreate → drop-column → drop-index → drop-table\n const combined = [...gatedDefault, ...gatedBucketable];\n const byCategory = (cat: CallCategory) => combined.filter((c) => classifyCall(c) === cat);\n\n const calls: SqliteOpFactoryCall[] = [\n ...byCategory('create-table'),\n ...byCategory('add-column'),\n ...byCategory('create-index'),\n ...gatedRecipe,\n ...byCategory('drop-column'),\n ...byCategory('drop-index'),\n ...byCategory('drop-table'),\n ];\n\n return ok({ calls });\n}\n","import type { Contract } from '@prisma-next/contract/types';\nimport type {\n MigrationOperationPolicy,\n SqlMigrationPlanner,\n SqlMigrationPlannerPlanOptions,\n SqlPlannerFailureResult,\n} from '@prisma-next/family-sql/control';\nimport { extractCodecControlHooks, plannerFailure } 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 MigrationScaffoldContext,\n SchemaIssue,\n} from '@prisma-next/framework-components/control';\nimport { parseSqliteDefault } from '../default-normalizer';\nimport { normalizeSqliteNativeType } from '../native-type-normalizer';\nimport { planIssues } from './issue-planner';\nimport {\n type SqliteMigrationDestinationInfo,\n TypeScriptRenderableSqliteMigration,\n} from './planner-produced-sqlite-migration';\nimport { sqlitePlannerStrategies } from './planner-strategies';\nimport type { SqlitePlanTargetDetails } from './planner-target-details';\n\nexport function createSqliteMigrationPlanner(): SqliteMigrationPlanner {\n return new SqliteMigrationPlanner();\n}\n\nexport type SqlitePlanResult =\n | { readonly kind: 'success'; readonly plan: TypeScriptRenderableSqliteMigration }\n | SqlPlannerFailureResult;\n\n/**\n * SQLite 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 registered\n * strategies. Strategies absorb groups of related issues into composite\n * recipes (e.g. recreating a table to apply type/nullability/default/\n * constraint changes at once); anything not absorbed by a strategy flows\n * through `mapIssueToCall` in the issue planner as a one-off call.\n *\n * FK-backing indexes are surfaced by `verifySqlSchema`'s index expansion\n * (see `verify-sql-schema.ts:459-469`), so `mapIssueToCall` handles them\n * uniformly alongside user-declared indexes.\n */\nexport class SqliteMigrationPlanner\n implements SqlMigrationPlanner<SqlitePlanTargetDetails>, MigrationPlanner<'sql', 'sqlite'>\n{\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 at),\n * or `null` for reconciliation flows.\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 frameworkComponents: ReadonlyArray<TargetBoundComponentDescriptor<'sql', string>>;\n }): SqlitePlanResult {\n return this.planSql(options as SqlMigrationPlannerPlanOptions);\n }\n\n emptyMigration(context: MigrationScaffoldContext): TypeScriptRenderableSqliteMigration {\n return new TypeScriptRenderableSqliteMigration([], {\n from: context.fromHash,\n to: context.toHash,\n });\n }\n\n private planSql(options: SqlMigrationPlannerPlanOptions): SqlitePlanResult {\n const policyResult = this.ensureAdditivePolicy(options.policy);\n if (policyResult) return policyResult;\n\n const schemaIssues = this.collectSchemaIssues(options);\n const codecHooks = extractCodecControlHooks(options.frameworkComponents);\n const storageTypes = options.contract.storage.types ?? {};\n\n const result = planIssues({\n issues: schemaIssues,\n toContract: options.contract,\n fromContract: options.fromContract,\n codecHooks,\n storageTypes,\n schema: options.schema,\n policy: options.policy,\n frameworkComponents: options.frameworkComponents,\n strategies: sqlitePlannerStrategies,\n });\n\n if (!result.ok) {\n return plannerFailure(result.failure);\n }\n\n const destination: SqliteMigrationDestinationInfo = {\n storageHash: options.contract.storage.storageHash,\n ...(options.contract.profileHash !== undefined\n ? { profileHash: options.contract.profileHash }\n : {}),\n };\n\n return {\n kind: 'success' as const,\n plan: new TypeScriptRenderableSqliteMigration(\n result.value.calls,\n {\n from: options.fromContract?.storage.storageHash ?? null,\n to: options.contract.storage.storageHash,\n },\n destination,\n ),\n };\n }\n\n private ensureAdditivePolicy(policy: MigrationOperationPolicy): SqlPlannerFailureResult | null {\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: SqlMigrationPlannerPlanOptions): readonly SchemaIssue[] {\n const allowed = options.policy.allowedOperationClasses;\n const strict = allowed.includes('widening') || allowed.includes('destructive');\n const verifyResult = verifySqlSchema({\n contract: options.contract,\n schema: options.schema,\n strict,\n typeMetadataRegistry: new Map(),\n frameworkComponents: options.frameworkComponents,\n normalizeDefault: parseSqliteDefault,\n normalizeNativeType: normalizeSqliteNativeType,\n });\n return verifyResult.schema.issues;\n }\n}\n"],"mappings":";;;;;;;;;;;;AAyDA,MAAM,uBAAuB,IAAI,IAAyB,CAAC,oBAAoB,kBAAkB,CAAC;AAElG,MAAM,0BAA0B,IAAI,IAAyB;CAC3D;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACD,CAAC;AAEF,SAAS,cAAc,OAAuD;AAC5E,KAAI,MAAM,SAAS,sBAAuB,QAAO;AACjD,KAAI,CAAC,MAAM,MAAO,QAAO;AACzB,KAAI,MAAM,SAAS,uBAEjB,QAAO,MAAM,aAAa,SAAS,aAAa;AAElD,KAAI,qBAAqB,IAAI,MAAM,KAAK,CAAE,QAAO;AACjD,KAAI,wBAAwB,IAAI,MAAM,KAAK,CAAE,QAAO;AACpD,QAAO;;;;;;;;AAST,MAAaA,yBAAgD,QAAQ,QAAQ;CAC3E,MAAM,0BAAU,IAAI,KAAiE;CACrF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