@prisma/orm-target-sqlite 0.16.0-dev.36

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 (188) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +23 -0
  3. package/dist/adapter-DizMsGCb-n4h4w8ms.d.mts +22 -0
  4. package/dist/adapter-DizMsGCb-n4h4w8ms.d.mts.map +1 -0
  5. package/dist/adapter-m_BtnNSn.d.mts +2 -0
  6. package/dist/adapter-wc9p_v2Z-y8pzqMfG.mjs +997 -0
  7. package/dist/adapter-wc9p_v2Z-y8pzqMfG.mjs.map +1 -0
  8. package/dist/adapter.d.mts +14 -0
  9. package/dist/adapter.mjs +6 -0
  10. package/dist/adapter__adapter.d.mts +4 -0
  11. package/dist/adapter__adapter.mjs +2 -0
  12. package/dist/adapter__codec-types.d.mts +4 -0
  13. package/dist/adapter__codec-types.mjs +1 -0
  14. package/dist/adapter__column-types.d.mts +2 -0
  15. package/dist/adapter__column-types.mjs +2 -0
  16. package/dist/adapter__control.d.mts +5 -0
  17. package/dist/adapter__control.mjs +261 -0
  18. package/dist/adapter__control.mjs.map +1 -0
  19. package/dist/adapter__runtime.d.mts +2 -0
  20. package/dist/adapter__runtime.mjs +32 -0
  21. package/dist/adapter__runtime.mjs.map +1 -0
  22. package/dist/adapter__types.d.mts +3 -0
  23. package/dist/adapter__types.mjs +1 -0
  24. package/dist/codec-descriptor-BcgD9f3L-BjEkn9Ob.d.mts +31 -0
  25. package/dist/codec-descriptor-BcgD9f3L-BjEkn9Ob.d.mts.map +1 -0
  26. package/dist/codec-descriptor-CyCQXvSl.d.mts +2 -0
  27. package/dist/codec-descriptor-kVCSW1OR-CPatZUPM.mjs +104 -0
  28. package/dist/codec-descriptor-kVCSW1OR-CPatZUPM.mjs.map +1 -0
  29. package/dist/codec-descriptor-rFuZ9DzY-DO0k8l6N.d.mts +1 -0
  30. package/dist/codec-ids-ChRBs2aB.d.mts +1 -0
  31. package/dist/codec-ids-DocGjhs--CHhP1jNZ.d.mts +13 -0
  32. package/dist/codec-ids-DocGjhs--CHhP1jNZ.d.mts.map +1 -0
  33. package/dist/codec-ids-xicqpuAa-DHnKqnIs.mjs +13 -0
  34. package/dist/codec-ids-xicqpuAa-DHnKqnIs.mjs.map +1 -0
  35. package/dist/codec-types-DKB--ltR-CIuvX0zx.d.mts +24 -0
  36. package/dist/codec-types-DKB--ltR-CIuvX0zx.d.mts.map +1 -0
  37. package/dist/codec-types-Tw3EFTjf.d.mts +1 -0
  38. package/dist/codec-types-wPDlPoD7.d.mts +2 -0
  39. package/dist/codecs-1-oOsTPG-Bv518Lbm.d.mts +155 -0
  40. package/dist/codecs-1-oOsTPG-Bv518Lbm.d.mts.map +1 -0
  41. package/dist/codecs-CM_2W3uA.mjs +345 -0
  42. package/dist/codecs-CM_2W3uA.mjs.map +1 -0
  43. package/dist/codecs-j-8RDkOt.d.mts +1 -0
  44. package/dist/column-types-StKUDF6A.mjs +34 -0
  45. package/dist/column-types-StKUDF6A.mjs.map +1 -0
  46. package/dist/column-types-iWGuW-0W.d.mts +33 -0
  47. package/dist/column-types-iWGuW-0W.d.mts.map +1 -0
  48. package/dist/contract-free-CCLAXZV2.d.mts +88 -0
  49. package/dist/contract-free-CCLAXZV2.d.mts.map +1 -0
  50. package/dist/contract-free-DElSXD0q.mjs +90 -0
  51. package/dist/contract-free-DElSXD0q.mjs.map +1 -0
  52. package/dist/control--wMueaTg.d.mts +61 -0
  53. package/dist/control--wMueaTg.d.mts.map +1 -0
  54. package/dist/control-8G9x72lw.mjs +42 -0
  55. package/dist/control-8G9x72lw.mjs.map +1 -0
  56. package/dist/control-DLO163u8.d.mts +19 -0
  57. package/dist/control-DLO163u8.d.mts.map +1 -0
  58. package/dist/control-cahq7u71.d.mts +117 -0
  59. package/dist/control-cahq7u71.d.mts.map +1 -0
  60. package/dist/control-tables-D_o8dKRB-BXi43noL.mjs +12 -0
  61. package/dist/control-tables-D_o8dKRB-BXi43noL.mjs.map +1 -0
  62. package/dist/control-tables-Dua-YcJL.d.mts +12 -0
  63. package/dist/control-tables-Dua-YcJL.d.mts.map +1 -0
  64. package/dist/ddl-CW34JvfE-rd1ZIxOn.mjs +66 -0
  65. package/dist/ddl-CW34JvfE-rd1ZIxOn.mjs.map +1 -0
  66. package/dist/ddl-CfSqNT0M.d.mts +1 -0
  67. package/dist/default-normalizer-B9V7TY5u.d.mts +7 -0
  68. package/dist/default-normalizer-B9V7TY5u.d.mts.map +1 -0
  69. package/dist/default-normalizer-DuoHj9-O-DsK7lJZn.mjs +69 -0
  70. package/dist/default-normalizer-DuoHj9-O-DsK7lJZn.mjs.map +1 -0
  71. package/dist/descriptor-meta-CbYkqTkO-DEJNrICG.mjs +30 -0
  72. package/dist/descriptor-meta-CbYkqTkO-DEJNrICG.mjs.map +1 -0
  73. package/dist/descriptor-meta-DnwDwnGg-D3f936hn.mjs +23 -0
  74. package/dist/descriptor-meta-DnwDwnGg-D3f936hn.mjs.map +1 -0
  75. package/dist/descriptor-meta-runtime-BkXK3OjD-CxZdKHCw.mjs +13 -0
  76. package/dist/descriptor-meta-runtime-BkXK3OjD-CxZdKHCw.mjs.map +1 -0
  77. package/dist/descriptor-meta-vjJkUDsn-Hz3rnAnk.mjs +70 -0
  78. package/dist/descriptor-meta-vjJkUDsn-Hz3rnAnk.mjs.map +1 -0
  79. package/dist/driver.d.mts +3 -0
  80. package/dist/driver.mjs +2 -0
  81. package/dist/driver__control.d.mts +2 -0
  82. package/dist/driver__control.mjs +2 -0
  83. package/dist/driver__runtime.d.mts +2 -0
  84. package/dist/driver__runtime.mjs +197 -0
  85. package/dist/driver__runtime.mjs.map +1 -0
  86. package/dist/errors-CKsaaSnD-BeB4JS8h.mjs +38 -0
  87. package/dist/errors-CKsaaSnD-BeB4JS8h.mjs.map +1 -0
  88. package/dist/migration-jsmNRI_8.mjs +47 -0
  89. package/dist/migration-jsmNRI_8.mjs.map +1 -0
  90. package/dist/migration-uylRe5MP.d.mts +43 -0
  91. package/dist/migration-uylRe5MP.d.mts.map +1 -0
  92. package/dist/native-type-normalizer-CO2wKGL6.d.mts +12 -0
  93. package/dist/native-type-normalizer-CO2wKGL6.d.mts.map +1 -0
  94. package/dist/native-type-normalizer-GpQMEyN5.mjs +14 -0
  95. package/dist/native-type-normalizer-GpQMEyN5.mjs.map +1 -0
  96. package/dist/nodes-D8EC1yCx-rpfpuJ4T.d.mts +29 -0
  97. package/dist/nodes-D8EC1yCx-rpfpuJ4T.d.mts.map +1 -0
  98. package/dist/nodes-DUZSdX86-BBEEaxXY.mjs +33 -0
  99. package/dist/nodes-DUZSdX86-BBEEaxXY.mjs.map +1 -0
  100. package/dist/op-factory-call-C_or6163-B_LDzC37.mjs +829 -0
  101. package/dist/op-factory-call-C_or6163-B_LDzC37.mjs.map +1 -0
  102. package/dist/op-factory-call-DoHN7Q7L.d.mts +161 -0
  103. package/dist/op-factory-call-DoHN7Q7L.d.mts.map +1 -0
  104. package/dist/pack-BfwyQ0b3.d.mts +93 -0
  105. package/dist/pack-BfwyQ0b3.d.mts.map +1 -0
  106. package/dist/planner-Bxdi7jZF.d.mts +104 -0
  107. package/dist/planner-Bxdi7jZF.d.mts.map +1 -0
  108. package/dist/planner-DiGcIjl1-QnNAhVmX.mjs +811 -0
  109. package/dist/planner-DiGcIjl1-QnNAhVmX.mjs.map +1 -0
  110. package/dist/planner-produced-sqlite-migration-BuJysRxx-CaDUbNVx.d.mts +31 -0
  111. package/dist/planner-produced-sqlite-migration-BuJysRxx-CaDUbNVx.d.mts.map +1 -0
  112. package/dist/planner-produced-sqlite-migration-C8nxPT0P-DdBqfmAD.mjs +150 -0
  113. package/dist/planner-produced-sqlite-migration-C8nxPT0P-DdBqfmAD.mjs.map +1 -0
  114. package/dist/planner-produced-sqlite-migration-uySoqJO-.d.mts +1 -0
  115. package/dist/planner-target-details-CIQ789Gc-C5U4yVY9.mjs +15 -0
  116. package/dist/planner-target-details-CIQ789Gc-C5U4yVY9.mjs.map +1 -0
  117. package/dist/planner-target-details-xR6UfIcz-CMahymzq.d.mts +13 -0
  118. package/dist/planner-target-details-xR6UfIcz-CMahymzq.d.mts.map +1 -0
  119. package/dist/render-ops-B10yqmdG.d.mts +11 -0
  120. package/dist/render-ops-B10yqmdG.d.mts.map +1 -0
  121. package/dist/render-ops-DIOn_wOx-D33LOy3b.mjs +27 -0
  122. package/dist/render-ops-DIOn_wOx-D33LOy3b.mjs.map +1 -0
  123. package/dist/runtime-B1coahKC.d.mts +15 -0
  124. package/dist/runtime-B1coahKC.d.mts.map +1 -0
  125. package/dist/runtime-B99c4n56.d.mts +28 -0
  126. package/dist/runtime-B99c4n56.d.mts.map +1 -0
  127. package/dist/runtime-tbBYTw7Z.d.mts +10 -0
  128. package/dist/runtime-tbBYTw7Z.d.mts.map +1 -0
  129. package/dist/shared-BYAX0FaQ--VvRXVRC.d.mts +68 -0
  130. package/dist/shared-BYAX0FaQ--VvRXVRC.d.mts.map +1 -0
  131. package/dist/sql-utils-0SJZOd7Q.d.mts +18 -0
  132. package/dist/sql-utils-0SJZOd7Q.d.mts.map +1 -0
  133. package/dist/sql-utils-DqPXZBMA-Mm27NNjs.mjs +35 -0
  134. package/dist/sql-utils-DqPXZBMA-Mm27NNjs.mjs.map +1 -0
  135. package/dist/sqlite-contract-view-BpNMaU2m-COMDaGaq.d.mts +31 -0
  136. package/dist/sqlite-contract-view-BpNMaU2m-COMDaGaq.d.mts.map +1 -0
  137. package/dist/sqlite-contract-view-CnDITHEE-BvjSbmzL.mjs +151 -0
  138. package/dist/sqlite-contract-view-CnDITHEE-BvjSbmzL.mjs.map +1 -0
  139. package/dist/sqlite-migration-CV6LIqhx-D5eMTAbH.mjs +94 -0
  140. package/dist/sqlite-migration-CV6LIqhx-D5eMTAbH.mjs.map +1 -0
  141. package/dist/sqlite-migration-o23JHwzY-CwNJcqwl.d.mts +105 -0
  142. package/dist/sqlite-migration-o23JHwzY-CwNJcqwl.d.mts.map +1 -0
  143. package/dist/target.d.mts +28 -0
  144. package/dist/target.mjs +19 -0
  145. package/dist/target__codec-descriptor.d.mts +3 -0
  146. package/dist/target__codec-descriptor.mjs +2 -0
  147. package/dist/target__codec-ids.d.mts +3 -0
  148. package/dist/target__codec-ids.mjs +2 -0
  149. package/dist/target__codec-types.d.mts +4 -0
  150. package/dist/target__codec-types.mjs +1 -0
  151. package/dist/target__codecs.d.mts +3 -0
  152. package/dist/target__codecs.mjs +2 -0
  153. package/dist/target__contract-free.d.mts +2 -0
  154. package/dist/target__contract-free.mjs +3 -0
  155. package/dist/target__control-tables.d.mts +2 -0
  156. package/dist/target__control-tables.mjs +2 -0
  157. package/dist/target__control.d.mts +3 -0
  158. package/dist/target__control.mjs +432 -0
  159. package/dist/target__control.mjs.map +1 -0
  160. package/dist/target__ddl.d.mts +3 -0
  161. package/dist/target__ddl.mjs +2 -0
  162. package/dist/target__default-normalizer.d.mts +2 -0
  163. package/dist/target__default-normalizer.mjs +2 -0
  164. package/dist/target__migration.d.mts +3 -0
  165. package/dist/target__migration.mjs +3 -0
  166. package/dist/target__native-type-normalizer.d.mts +2 -0
  167. package/dist/target__native-type-normalizer.mjs +2 -0
  168. package/dist/target__op-factory-call.d.mts +2 -0
  169. package/dist/target__op-factory-call.mjs +2 -0
  170. package/dist/target__pack.d.mts +2 -0
  171. package/dist/target__pack.mjs +2 -0
  172. package/dist/target__planner-produced-sqlite-migration.d.mts +3 -0
  173. package/dist/target__planner-produced-sqlite-migration.mjs +2 -0
  174. package/dist/target__planner-target-details.d.mts +2 -0
  175. package/dist/target__planner-target-details.mjs +2 -0
  176. package/dist/target__planner.d.mts +2 -0
  177. package/dist/target__planner.mjs +2 -0
  178. package/dist/target__render-ops.d.mts +2 -0
  179. package/dist/target__render-ops.mjs +2 -0
  180. package/dist/target__runtime.d.mts +3 -0
  181. package/dist/target__runtime.mjs +17 -0
  182. package/dist/target__runtime.mjs.map +1 -0
  183. package/dist/target__sql-utils.d.mts +2 -0
  184. package/dist/target__sql-utils.mjs +2 -0
  185. package/dist/types-C5FSREvo-Bm6N5Kog.d.mts +25 -0
  186. package/dist/types-C5FSREvo-Bm6N5Kog.d.mts.map +1 -0
  187. package/dist/types-DiH2oWUJ.d.mts +1 -0
  188. package/package.json +78 -0
@@ -0,0 +1,829 @@
1
+ import { n as sqliteError } from "./errors-CKsaaSnD-BeB4JS8h.mjs";
2
+ import { i as tableExistsAst, n as createTable, r as indexExistsAst, t as columnExistsAst } from "./ddl-CW34JvfE-rd1ZIxOn.mjs";
3
+ import { n as quoteIdentifier, t as escapeLiteral } from "./sql-utils-DqPXZBMA-Mm27NNjs.mjs";
4
+ import { t as buildTargetDetails } from "./planner-target-details-CIQ789Gc-C5U4yVY9.mjs";
5
+ import { n as stripOuterParens } from "./default-normalizer-DuoHj9-O-DsK7lJZn.mjs";
6
+ import { blindCast } from "@prisma/orm-framework/utils/casts";
7
+ import { issueOutcome } from "@prisma/orm-framework/components/control";
8
+ import { ifDefined } from "@prisma/orm-framework/utils/defined";
9
+ import { RelationalSchemaNodeKind } from "@prisma/orm-family-sql/schema-ir/types";
10
+ import { errorUnfilledPlaceholder } from "@prisma/orm-framework/errors/migration";
11
+ import { TsExpression, jsonToTsSource } from "@prisma/orm-framework/ts-render";
12
+ import { REFERENTIAL_ACTION_SQL } from "@prisma/orm-family-sql/contract/referential-action-sql";
13
+ //#region ../../../3-targets/3-targets/sqlite/dist/op-factory-call-C_or6163.mjs
14
+ const SAFE_NATIVE_TYPE_PATTERN = /^[a-zA-Z][a-zA-Z0-9_ ]*$/;
15
+ function assertSafeNativeType(nativeType) {
16
+ if (!SAFE_NATIVE_TYPE_PATTERN.test(nativeType)) throw sqliteError("CONTRACT.NATIVE_TYPE_INVALID", `Unsafe native type name in contract: "${nativeType}". Native type names must match /^[a-zA-Z][a-zA-Z0-9_ ]*\$/`, { meta: { nativeType } });
17
+ }
18
+ function assertSafeDefaultExpression(expression) {
19
+ if (expression.includes(";") || /--|\/\*|\bSELECT\b/i.test(expression)) throw sqliteError("CONTRACT.DEFAULT_INVALID", `Unsafe default expression in contract: "${expression}". Default expressions must not contain semicolons, SQL comment tokens, or subqueries.`, { meta: { expression } });
20
+ }
21
+ /**
22
+ * Renders the column's DDL type token (e.g. `"INTEGER"`, `"TEXT"`).
23
+ * Resolves `typeRef` against `storageTypes` and validates the resulting
24
+ * native type against a safe-identifier pattern.
25
+ */
26
+ function buildColumnTypeSql(column, storageTypes = {}) {
27
+ const resolved = resolveColumnTypeMetadata(column, storageTypes);
28
+ assertSafeNativeType(resolved.nativeType);
29
+ return resolved.nativeType.toUpperCase();
30
+ }
31
+ /**
32
+ * Renders the column's `DEFAULT …` clause. Returns the empty string when
33
+ * there is no default, and also when the default is `autoincrement()` —
34
+ * SQLite encodes that as `INTEGER PRIMARY KEY AUTOINCREMENT` inline on the
35
+ * column definition, not as a separate DEFAULT.
36
+ */
37
+ function buildColumnDefaultSql(columnDefault) {
38
+ if (!columnDefault) return "";
39
+ switch (columnDefault.kind) {
40
+ case "literal": return `DEFAULT ${renderDefaultLiteral(columnDefault.value)}`;
41
+ case "function":
42
+ if (columnDefault.expression === "autoincrement()") return "";
43
+ if (columnDefault.expression === "now()") return "DEFAULT (datetime('now'))";
44
+ assertSafeDefaultExpression(columnDefault.expression);
45
+ return `DEFAULT (${columnDefault.expression})`;
46
+ }
47
+ }
48
+ function renderDefaultLiteral(value) {
49
+ if (value instanceof Date) return `'${escapeLiteral(value.toISOString())}'`;
50
+ if (typeof value === "string") return `'${escapeLiteral(value)}'`;
51
+ if (typeof value === "number" || typeof value === "bigint") return String(value);
52
+ if (typeof value === "boolean") return value ? "1" : "0";
53
+ if (value === null) return "NULL";
54
+ return `'${escapeLiteral(JSON.stringify(value))}'`;
55
+ }
56
+ function buildCreateIndexSql(tableName, indexName, columns, unique = false) {
57
+ return `CREATE ${unique ? "UNIQUE " : ""}INDEX ${quoteIdentifier(indexName)} ON ${quoteIdentifier(tableName)} (${columns.map(quoteIdentifier).join(", ")})`;
58
+ }
59
+ function buildDropIndexSql(indexName) {
60
+ return `DROP INDEX IF EXISTS ${quoteIdentifier(indexName)}`;
61
+ }
62
+ function resolveColumnTypeMetadata(column, storageTypes) {
63
+ if (!column.typeRef) return column;
64
+ const referencedType = storageTypes[column.typeRef];
65
+ if (!referencedType) throw sqliteError("CONTRACT.TYPE_UNKNOWN", `Storage type "${column.typeRef}" referenced by column is not defined in storage.types.`, { meta: { typeRef: column.typeRef } });
66
+ return {
67
+ codecId: referencedType.codecId,
68
+ nativeType: referencedType.nativeType,
69
+ typeParams: referencedType.typeParams
70
+ };
71
+ }
72
+ function step(description, sql, params) {
73
+ return {
74
+ description,
75
+ sql,
76
+ ...ifDefined("params", params)
77
+ };
78
+ }
79
+ /**
80
+ * Renders a single column's inline DDL fragment within a `CREATE TABLE`
81
+ * statement. Honours the `inlineAutoincrementPrimaryKey` flag — SQLite
82
+ * treats `INTEGER PRIMARY KEY AUTOINCREMENT` as a special form that aliases
83
+ * `rowid`, and the column must not carry a `DEFAULT` or repeat `NOT NULL`.
84
+ */
85
+ function renderColumnDefinition(column) {
86
+ const parts = [quoteIdentifier(column.name), column.typeSql];
87
+ if (column.inlineAutoincrementPrimaryKey) parts.push("PRIMARY KEY AUTOINCREMENT");
88
+ else {
89
+ if (column.defaultSql) parts.push(column.defaultSql);
90
+ if (!column.nullable) parts.push("NOT NULL");
91
+ }
92
+ return parts.join(" ");
93
+ }
94
+ /**
95
+ * Renders an inline FOREIGN KEY constraint clause for a `CREATE TABLE`
96
+ * body. Every `SqliteForeignKeySpec` is constraint-bearing by construction
97
+ * (`tableSpecFromNode` only ever builds specs from schema-IR FK nodes, which
98
+ * are themselves constraint-only — a non-constraint FK contributes no node).
99
+ */
100
+ function renderForeignKeyClause(fk) {
101
+ let sql = `${fk.name ? `CONSTRAINT ${quoteIdentifier(fk.name)} ` : ""}FOREIGN KEY (${fk.columns.map(quoteIdentifier).join(", ")}) REFERENCES ${quoteIdentifier(fk.references.table)} (${fk.references.columns.map(quoteIdentifier).join(", ")})`;
102
+ if (fk.onDelete !== void 0) sql += ` ON DELETE ${REFERENTIAL_ACTION_SQL[fk.onDelete]}`;
103
+ if (fk.onUpdate !== void 0) sql += ` ON UPDATE ${REFERENTIAL_ACTION_SQL[fk.onUpdate]}`;
104
+ return sql;
105
+ }
106
+ function addColumnExecuteSql(tableName, column) {
107
+ return [
108
+ `ALTER TABLE ${quoteIdentifier(tableName)}`,
109
+ `ADD COLUMN ${quoteIdentifier(column.name)} ${column.typeSql}`,
110
+ column.defaultSql,
111
+ column.nullable ? "" : "NOT NULL"
112
+ ].filter(Boolean).join(" ");
113
+ }
114
+ function dropColumnExecuteSql(tableName, columnName) {
115
+ return `ALTER TABLE ${quoteIdentifier(tableName)} DROP COLUMN ${quoteIdentifier(columnName)}`;
116
+ }
117
+ async function tableExistsSteps(lowerer, tableName) {
118
+ const checks = tableExistsAst(tableName);
119
+ return {
120
+ present: await lowerer.lowerToExecuteRequest(checks.tablePresent()),
121
+ absent: await lowerer.lowerToExecuteRequest(checks.tableAbsent())
122
+ };
123
+ }
124
+ /**
125
+ * Renders the body of a `CREATE TABLE <name> ( … )` statement from a flat
126
+ * `SqliteTableSpec`. SQLite's `INTEGER PRIMARY KEY AUTOINCREMENT` form is
127
+ * inline on the column; the table-level PRIMARY KEY clause is emitted only
128
+ * when no column carries `inlineAutoincrementPrimaryKey`.
129
+ */
130
+ function renderCreateTableSql(tableName, spec) {
131
+ const columnDefs = spec.columns.map(renderColumnDefinition);
132
+ const constraintDefs = [];
133
+ const hasInlinePk = spec.columns.some((c) => c.inlineAutoincrementPrimaryKey);
134
+ if (spec.primaryKey && !hasInlinePk) constraintDefs.push(`PRIMARY KEY (${spec.primaryKey.columns.map(quoteIdentifier).join(", ")})`);
135
+ for (const u of spec.uniques ?? []) {
136
+ const name = u.name ? `CONSTRAINT ${quoteIdentifier(u.name)} ` : "";
137
+ constraintDefs.push(`${name}UNIQUE (${u.columns.map(quoteIdentifier).join(", ")})`);
138
+ }
139
+ for (const fk of spec.foreignKeys ?? []) {
140
+ const clause = renderForeignKeyClause(fk);
141
+ if (clause) constraintDefs.push(clause);
142
+ }
143
+ const allDefs = [...columnDefs, ...constraintDefs];
144
+ return `CREATE TABLE ${quoteIdentifier(tableName)} (\n ${allDefs.join(",\n ")}\n)`;
145
+ }
146
+ async function recreateTable(args, lowerer) {
147
+ const { tableName, contractTable, schemaColumnNames, indexes, summary, postchecks, operationClass } = args;
148
+ const tempName = `_prisma_new_${tableName}`;
149
+ const liveSet = new Set(schemaColumnNames);
150
+ const sharedColumns = contractTable.columns.filter((c) => liveSet.has(c.name)).map((c) => c.name);
151
+ const columnList = sharedColumns.map(quoteIdentifier).join(", ");
152
+ const indexStatements = indexes.map((idx) => ({
153
+ description: `recreate index "${idx.name}" on "${tableName}"`,
154
+ sql: buildCreateIndexSql(tableName, idx.name, idx.columns)
155
+ }));
156
+ const copyStep = sharedColumns.length > 0 ? [step(`copy data from "${tableName}" to "${tempName}"`, `INSERT INTO ${quoteIdentifier(tempName)} (${columnList}) SELECT ${columnList} FROM ${quoteIdentifier(tableName)}`)] : [];
157
+ const tableSteps = await tableExistsSteps(lowerer, tableName);
158
+ const tempSteps = await tableExistsSteps(lowerer, tempName);
159
+ return {
160
+ id: `recreateTable.${tableName}`,
161
+ label: `Recreate table ${tableName}`,
162
+ summary,
163
+ operationClass,
164
+ target: {
165
+ id: "sqlite",
166
+ details: buildTargetDetails("table", tableName)
167
+ },
168
+ precheck: [step(`ensure table "${tableName}" exists`, tableSteps.present.sql, tableSteps.present.params), step(`ensure temp table "${tempName}" does not exist`, tempSteps.absent.sql, tempSteps.absent.params)],
169
+ execute: [
170
+ step(`create new table "${tempName}" with desired schema`, renderCreateTableSql(tempName, contractTable)),
171
+ ...copyStep,
172
+ step(`drop old table "${tableName}"`, `DROP TABLE ${quoteIdentifier(tableName)}`),
173
+ step(`rename "${tempName}" to "${tableName}"`, `ALTER TABLE ${quoteIdentifier(tempName)} RENAME TO ${quoteIdentifier(tableName)}`),
174
+ ...indexStatements
175
+ ],
176
+ postcheck: [
177
+ step(`verify table "${tableName}" exists`, tableSteps.present.sql, tableSteps.present.params),
178
+ step(`verify temp table "${tempName}" is gone`, tempSteps.absent.sql, tempSteps.absent.params),
179
+ ...postchecks
180
+ ]
181
+ };
182
+ }
183
+ /**
184
+ * Build a one-line summary of a recreate-table operation from the schema-diff
185
+ * issues that triggered it. Lives next to `recreateTable` so the planner
186
+ * (which has the issues) can produce the same description the factory
187
+ * used to build inline. Keeping the formatting target-side keeps
188
+ * `RecreateTableCall` issue-free at the IR layer. `SchemaDiffIssue` carries
189
+ * no rendered message, so this renders one from each issue's path.
190
+ */
191
+ function buildRecreateSummary(tableName, issues) {
192
+ return `Recreates table ${tableName} to apply schema changes: ${issues.map((i) => i.path.join("/")).join("; ")}`;
193
+ }
194
+ function nodeKindOf(issue) {
195
+ const node = issue.expected ?? issue.actual;
196
+ if (node === void 0) return void 0;
197
+ return blindCast(node).nodeKind;
198
+ }
199
+ /** Mirrors `SqlColumnIR.isEqualTo`'s type comparison, isolated so a `not-equal` column issue's postcheck can target type drift and nullability drift independently. */
200
+ function columnTypeChanged(expected, actual) {
201
+ if (expected.resolvedNativeType !== void 0 && actual.resolvedNativeType !== void 0) return expected.resolvedNativeType !== actual.resolvedNativeType;
202
+ return expected.nativeType !== actual.nativeType || Boolean(expected.many) !== Boolean(actual.many);
203
+ }
204
+ /**
205
+ * Returns the columns the contract expects as the table's primary key. Picks
206
+ * up SQLite's inline `INTEGER PRIMARY KEY AUTOINCREMENT` form when no
207
+ * explicit `primaryKey` clause is set on the spec.
208
+ */
209
+ function expectedPrimaryKeyColumns(spec) {
210
+ if (spec.primaryKey) return spec.primaryKey.columns;
211
+ const inlinePk = spec.columns.find((c) => c.inlineAutoincrementPrimaryKey);
212
+ return inlinePk ? [inlinePk.name] : [];
213
+ }
214
+ function quoteSqlList(values) {
215
+ return values.map((v) => `'${escapeLiteral(v)}'`).join(", ");
216
+ }
217
+ function columnNameFromNode(issue) {
218
+ const node = issue.expected ?? issue.actual;
219
+ if (node === void 0) return void 0;
220
+ return blindCast(node).name;
221
+ }
222
+ /**
223
+ * A column-default issue's own node has no back-reference to its owning
224
+ * column — it's a transient child built by `SqlColumnIR.children()`. The
225
+ * column's id (`column:<name>`) is always the diff path's second-to-last
226
+ * segment for a default issue (`[..., tableId, columnId, 'default']`), so
227
+ * the name is recovered from the path rather than the node.
228
+ */
229
+ function columnNameFromDefaultIssuePath(issue) {
230
+ const columnId = issue.path[issue.path.length - 2];
231
+ if (columnId === void 0) return void 0;
232
+ return columnId.startsWith("column:") ? columnId.slice(7) : columnId;
233
+ }
234
+ /**
235
+ * Per-issue postchecks verifying the recreated table's shape against the
236
+ * expected spec. Column-level issues (`sql-column` `not-equal`,
237
+ * `sql-column-default` any reason) emit one targeted check each;
238
+ * constraint-level issues (`sql-primary-key`, `sql-unique`, `sql-foreign-key`,
239
+ * any reason) emit one `pragma_*`-driven check per declared constraint in the
240
+ * expected spec, so a recreated table with the right columns but the wrong
241
+ * PK / unique / FK shape fails the postcheck instead of passing silently.
242
+ * Exported so the planner can pre-build the list at construction time and
243
+ * `RecreateTableCall` doesn't have to carry `SchemaDiffIssue` objects through
244
+ * to render time.
245
+ */
246
+ function buildRecreatePostchecks(tableName, issues, spec) {
247
+ const checks = [];
248
+ const t = escapeLiteral(tableName);
249
+ const byName = new Map(spec.columns.map((c) => [c.name, c]));
250
+ let hasPkIssue = false;
251
+ let hasUniqueIssue = false;
252
+ let hasFkIssue = false;
253
+ for (const issue of issues) {
254
+ const nodeKind = nodeKindOf(issue);
255
+ if (nodeKind === RelationalSchemaNodeKind.column && issueOutcome(issue) === "not-equal") {
256
+ const columnName = columnNameFromNode(issue);
257
+ if (columnName === void 0) continue;
258
+ const c = escapeLiteral(columnName);
259
+ const expected = blindCast(issue.expected);
260
+ const actual = blindCast(issue.actual);
261
+ if (expected.nullable !== actual.nullable) checks.push({
262
+ description: `verify "${columnName}" nullability on "${tableName}"`,
263
+ sql: `SELECT COUNT(*) > 0 FROM pragma_table_info('${t}') WHERE name = '${c}' AND "notnull" = ${expected.nullable ? 0 : 1}`
264
+ });
265
+ if (columnTypeChanged(expected, actual)) {
266
+ const colSpec = byName.get(columnName);
267
+ if (colSpec) checks.push({
268
+ description: `verify "${columnName}" type on "${tableName}"`,
269
+ sql: `SELECT COUNT(*) > 0 FROM pragma_table_info('${t}') WHERE name = '${c}' AND LOWER(type) = '${escapeLiteral(colSpec.typeSql.toLowerCase())}'`
270
+ });
271
+ }
272
+ continue;
273
+ }
274
+ if (nodeKind === RelationalSchemaNodeKind.columnDefault) {
275
+ const columnName = columnNameFromDefaultIssuePath(issue);
276
+ if (columnName === void 0) continue;
277
+ const c = escapeLiteral(columnName);
278
+ if (issueOutcome(issue) === "not-expected") {
279
+ checks.push({
280
+ description: `verify "${columnName}" has no default on "${tableName}"`,
281
+ sql: `SELECT COUNT(*) > 0 FROM pragma_table_info('${t}') WHERE name = '${c}' AND dflt_value IS NULL`
282
+ });
283
+ continue;
284
+ }
285
+ const colSpec = byName.get(columnName);
286
+ const expectedRaw = colSpec?.defaultSql.startsWith("DEFAULT ") ? stripOuterParens(colSpec.defaultSql.slice(8)) : null;
287
+ if (expectedRaw) checks.push({
288
+ description: `verify "${columnName}" default on "${tableName}"`,
289
+ sql: `SELECT COUNT(*) > 0 FROM pragma_table_info('${t}') WHERE name = '${c}' AND dflt_value = '${escapeLiteral(expectedRaw)}'`
290
+ });
291
+ continue;
292
+ }
293
+ if (nodeKind === RelationalSchemaNodeKind.primaryKey) hasPkIssue = true;
294
+ if (nodeKind === RelationalSchemaNodeKind.unique) hasUniqueIssue = true;
295
+ if (nodeKind === RelationalSchemaNodeKind.foreignKey) hasFkIssue = true;
296
+ }
297
+ if (hasPkIssue) {
298
+ const pkColumns = expectedPrimaryKeyColumns(spec);
299
+ const colCount = pkColumns.length;
300
+ if (colCount === 0) checks.push({
301
+ description: `verify "${tableName}" has no primary key`,
302
+ sql: `SELECT (SELECT COUNT(*) FROM pragma_table_info('${t}') WHERE pk > 0) = 0`
303
+ });
304
+ else checks.push({
305
+ description: `verify primary key on "${tableName}"`,
306
+ sql: `SELECT (SELECT COUNT(*) FROM pragma_table_info('${t}') WHERE pk > 0) = ${colCount} AND (SELECT COUNT(*) FROM pragma_table_info('${t}') WHERE pk > 0 AND name IN (${quoteSqlList(pkColumns)})) = ${colCount}`
307
+ });
308
+ }
309
+ if (hasUniqueIssue) for (const u of spec.uniques ?? []) {
310
+ const colCount = u.columns.length;
311
+ const description = u.name ? `verify unique constraint "${u.name}" on "${tableName}"` : `verify unique constraint (${u.columns.join(", ")}) on "${tableName}"`;
312
+ checks.push({
313
+ description,
314
+ sql: `SELECT EXISTS (SELECT 1 FROM pragma_index_list('${t}') l WHERE l."unique" = 1 AND (SELECT COUNT(*) FROM pragma_index_info(l.name)) = ${colCount} AND (SELECT COUNT(*) FROM pragma_index_info(l.name) WHERE name IN (${quoteSqlList(u.columns)})) = ${colCount})`
315
+ });
316
+ }
317
+ if (hasFkIssue) for (const fk of spec.foreignKeys ?? []) {
318
+ const refTable = escapeLiteral(fk.references.table);
319
+ const colCount = fk.columns.length;
320
+ const tuples = fk.columns.map((from, i) => {
321
+ const to = fk.references.columns[i] ?? from;
322
+ return `('${escapeLiteral(from)}', '${escapeLiteral(to)}')`;
323
+ }).join(", ");
324
+ const description = `verify foreign key (${fk.columns.join(", ")}) → ${fk.references.table}(${fk.references.columns.join(", ")}) on "${tableName}"`;
325
+ checks.push({
326
+ description,
327
+ sql: `SELECT EXISTS (SELECT 1 FROM pragma_foreign_key_list('${t}') f WHERE f."table" = '${refTable}' GROUP BY f.id HAVING COUNT(*) = ${colCount} AND SUM(CASE WHEN (f."from", f."to") IN (${tuples}) THEN 1 ELSE 0 END) = ${colCount})`
328
+ });
329
+ }
330
+ return checks;
331
+ }
332
+ /**
333
+ * SQLite migration IR: one concrete `*Call` class per pure factory under
334
+ * `operations/`, plus a shared `SqliteOpFactoryCallNode` abstract base.
335
+ *
336
+ * Each call class carries fully-resolved literal arguments. `CreateTableCall`
337
+ * holds structured `DdlColumn[]` + `DdlTableConstraint[]` and lowers via the
338
+ * adapter's DDL path; other call classes carry flat SQL fragments. Codec /
339
+ * `typeRef` / default expansion happens upstream in the issue-planner /
340
+ * strategies, mirroring the Postgres `ColumnSpec` pattern.
341
+ */
342
+ const TARGET_MIGRATION_MODULE = "@internal/sqlite/migration";
343
+ var SqliteOpFactoryCallNode = class extends TsExpression {
344
+ importRequirements() {
345
+ return [{
346
+ moduleSpecifier: TARGET_MIGRATION_MODULE,
347
+ symbol: this.factoryName
348
+ }];
349
+ }
350
+ freeze() {
351
+ Object.freeze(this);
352
+ }
353
+ };
354
+ function renderDdlColumnDefault(def) {
355
+ if (!def) return "";
356
+ if (def.kind === "literal") return `lit(${jsonToTsSource(def.value)})`;
357
+ return `fn(${jsonToTsSource(def.expression)})`;
358
+ }
359
+ function renderDdlColumnAsTsCall(column) {
360
+ const opts = [];
361
+ if (column.notNull) opts.push("notNull: true");
362
+ if (column.primaryKey) opts.push("primaryKey: true");
363
+ if (column.default) opts.push(`default: ${renderDdlColumnDefault(column.default)}`);
364
+ const optsStr = opts.length > 0 ? `, { ${opts.join(", ")} }` : "";
365
+ return `col(${jsonToTsSource(column.name)}, ${jsonToTsSource(column.type)}${optsStr})`;
366
+ }
367
+ function renderDdlConstraintAsTsCall(constraint) {
368
+ switch (constraint.kind) {
369
+ case "primary-key": {
370
+ const nameOpt = constraint.name ? `, { name: ${jsonToTsSource(constraint.name)} }` : "";
371
+ return `primaryKey(${jsonToTsSource(constraint.columns)}${nameOpt})`;
372
+ }
373
+ case "foreign-key": {
374
+ const opts = [];
375
+ if (constraint.name) opts.push(`name: ${jsonToTsSource(constraint.name)}`);
376
+ if (constraint.onDelete) opts.push(`onDelete: ${jsonToTsSource(constraint.onDelete)}`);
377
+ if (constraint.onUpdate) opts.push(`onUpdate: ${jsonToTsSource(constraint.onUpdate)}`);
378
+ const optsStr = opts.length > 0 ? `, { ${opts.join(", ")} }` : "";
379
+ return `foreignKey(${jsonToTsSource(constraint.columns)}, ${jsonToTsSource(constraint.refTable)}, ${jsonToTsSource(constraint.refColumns)}${optsStr})`;
380
+ }
381
+ case "unique": {
382
+ const nameOpt = constraint.name ? `, { name: ${jsonToTsSource(constraint.name)} }` : "";
383
+ return `unique(${jsonToTsSource(constraint.columns)}${nameOpt})`;
384
+ }
385
+ case "check-expression": throw sqliteError("CONTRACT.CONSTRAINT_INVALID", `SQLite does not support expression CHECK constraints (constraint "${constraint.name}"). Scalar-array columns and their element-non-null checks are Postgres-only.`, { meta: { constraintName: constraint.name } });
386
+ }
387
+ }
388
+ function constraintImportSymbols(constraints) {
389
+ if (!constraints || constraints.length === 0) return [];
390
+ const symbols = /* @__PURE__ */ new Set();
391
+ for (const c of constraints) if (c.kind === "primary-key") symbols.add("primaryKey");
392
+ else if (c.kind === "foreign-key") symbols.add("foreignKey");
393
+ else if (c.kind === "unique") symbols.add("unique");
394
+ return [...symbols];
395
+ }
396
+ function defaultImportSymbols(columns) {
397
+ const symbols = /* @__PURE__ */ new Set();
398
+ for (const col of columns) if (col.default?.kind === "literal") symbols.add("lit");
399
+ else if (col.default?.kind === "function") symbols.add("fn");
400
+ return [...symbols];
401
+ }
402
+ var CreateTableCall = class extends SqliteOpFactoryCallNode {
403
+ factoryName = "createTable";
404
+ operationClass = "additive";
405
+ tableName;
406
+ columns;
407
+ constraints;
408
+ label;
409
+ constructor(tableName, columns, constraints) {
410
+ super();
411
+ this.tableName = tableName;
412
+ this.columns = Object.freeze([...columns]);
413
+ this.constraints = constraints ? Object.freeze([...constraints]) : void 0;
414
+ this.label = `Create table ${tableName}`;
415
+ this.freeze();
416
+ }
417
+ async toOp(lowerer) {
418
+ if (lowerer === void 0) throw sqliteError("MIGRATION.SQLITE_CONTROL_STACK_MISSING", `CreateTableCall.toOp: a DDL lowerer is required on the SQLite planner path (table "${this.tableName}"). Pass the control adapter to createSqliteMigrationPlanner.`, { meta: {
419
+ factory: this.factoryName,
420
+ tableName: this.tableName
421
+ } });
422
+ const ddlNode = createTable({
423
+ table: this.tableName,
424
+ columns: this.columns,
425
+ ...ifDefined("constraints", this.constraints)
426
+ });
427
+ const statement = await lowerer.lowerToExecuteRequest(ddlNode);
428
+ const tableName = this.tableName;
429
+ const tableChecks = tableExistsAst(tableName);
430
+ const absent = await lowerer.lowerToExecuteRequest(tableChecks.tableAbsent());
431
+ const present = await lowerer.lowerToExecuteRequest(tableChecks.tablePresent());
432
+ return {
433
+ id: `table.${tableName}`,
434
+ label: `Create table ${tableName}`,
435
+ summary: `Creates table ${tableName} with required columns`,
436
+ operationClass: "additive",
437
+ target: {
438
+ id: "sqlite",
439
+ details: buildTargetDetails("table", tableName)
440
+ },
441
+ precheck: [step(`ensure table "${tableName}" does not exist`, absent.sql, absent.params)],
442
+ execute: [{
443
+ description: `create table "${tableName}"`,
444
+ sql: statement.sql,
445
+ params: statement.params ?? []
446
+ }],
447
+ postcheck: [step(`verify table "${tableName}" exists`, present.sql, present.params)]
448
+ };
449
+ }
450
+ renderTypeScript() {
451
+ const columnsList = this.columns.map(renderDdlColumnAsTsCall).join(", ");
452
+ const constraintsList = this.constraints ? this.constraints.map(renderDdlConstraintAsTsCall).join(", ") : void 0;
453
+ const opts = [];
454
+ opts.push(`table: ${jsonToTsSource(this.tableName)}`);
455
+ opts.push(`columns: [${columnsList}]`);
456
+ if (constraintsList) opts.push(`constraints: [${constraintsList}]`);
457
+ return `this.createTable({ ${opts.join(", ")} })`;
458
+ }
459
+ importRequirements() {
460
+ const req = [];
461
+ if (this.columns.length > 0) {
462
+ req.push({
463
+ moduleSpecifier: TARGET_MIGRATION_MODULE,
464
+ symbol: "col"
465
+ });
466
+ for (const sym of defaultImportSymbols(this.columns)) req.push({
467
+ moduleSpecifier: TARGET_MIGRATION_MODULE,
468
+ symbol: sym
469
+ });
470
+ }
471
+ for (const sym of constraintImportSymbols(this.constraints)) req.push({
472
+ moduleSpecifier: TARGET_MIGRATION_MODULE,
473
+ symbol: sym
474
+ });
475
+ return req;
476
+ }
477
+ };
478
+ var DropTableCall = class extends SqliteOpFactoryCallNode {
479
+ factoryName = "dropTable";
480
+ operationClass = "destructive";
481
+ tableName;
482
+ label;
483
+ constructor(tableName) {
484
+ super();
485
+ this.tableName = tableName;
486
+ this.label = `Drop table ${tableName}`;
487
+ this.freeze();
488
+ }
489
+ async toOp(lowerer) {
490
+ if (lowerer === void 0) throw sqliteError("MIGRATION.SQLITE_CONTROL_STACK_MISSING", `DropTableCall.toOp: a lowerer is required on the SQLite planner path (table "${this.tableName}"). Pass the control adapter to createSqliteMigrationPlanner.`, { meta: {
491
+ factory: this.factoryName,
492
+ tableName: this.tableName
493
+ } });
494
+ const checks = tableExistsAst(this.tableName);
495
+ const present = await lowerer.lowerToExecuteRequest(checks.tablePresent());
496
+ const absent = await lowerer.lowerToExecuteRequest(checks.tableAbsent());
497
+ return {
498
+ id: `dropTable.${this.tableName}`,
499
+ label: `Drop table ${this.tableName}`,
500
+ summary: `Drops table ${this.tableName} which is not in the contract`,
501
+ operationClass: "destructive",
502
+ target: {
503
+ id: "sqlite",
504
+ details: buildTargetDetails("table", this.tableName)
505
+ },
506
+ precheck: [step(`ensure table "${this.tableName}" exists`, present.sql, present.params)],
507
+ execute: [step(`drop table "${this.tableName}"`, `DROP TABLE ${quoteIdentifier(this.tableName)}`)],
508
+ postcheck: [step(`verify table "${this.tableName}" is gone`, absent.sql, absent.params)]
509
+ };
510
+ }
511
+ renderTypeScript() {
512
+ return `this.dropTable({ table: ${jsonToTsSource(this.tableName)} })`;
513
+ }
514
+ importRequirements() {
515
+ return [];
516
+ }
517
+ };
518
+ var RecreateTableCall = class extends SqliteOpFactoryCallNode {
519
+ factoryName = "recreateTable";
520
+ operationClass;
521
+ tableName;
522
+ contractTable;
523
+ schemaColumnNames;
524
+ indexes;
525
+ summary;
526
+ postchecks;
527
+ label;
528
+ constructor(args) {
529
+ super();
530
+ this.tableName = args.tableName;
531
+ this.contractTable = args.contractTable;
532
+ this.schemaColumnNames = args.schemaColumnNames;
533
+ this.indexes = args.indexes;
534
+ this.summary = args.summary;
535
+ this.postchecks = args.postchecks;
536
+ this.operationClass = args.operationClass;
537
+ this.label = `Recreate table ${args.tableName}`;
538
+ this.freeze();
539
+ }
540
+ async toOp(lowerer) {
541
+ if (lowerer === void 0) throw sqliteError("MIGRATION.SQLITE_CONTROL_STACK_MISSING", `RecreateTableCall.toOp: a lowerer is required on the SQLite planner path (table "${this.tableName}"). Pass the control adapter to createSqliteMigrationPlanner.`, { meta: {
542
+ factory: this.factoryName,
543
+ tableName: this.tableName
544
+ } });
545
+ return recreateTable({
546
+ tableName: this.tableName,
547
+ contractTable: this.contractTable,
548
+ schemaColumnNames: this.schemaColumnNames,
549
+ indexes: this.indexes,
550
+ summary: this.summary,
551
+ postchecks: this.postchecks,
552
+ operationClass: this.operationClass
553
+ }, lowerer);
554
+ }
555
+ renderTypeScript() {
556
+ return `this.recreateTable(${jsonToTsSource({
557
+ tableName: this.tableName,
558
+ contractTable: this.contractTable,
559
+ schemaColumnNames: this.schemaColumnNames,
560
+ indexes: this.indexes,
561
+ summary: this.summary,
562
+ postchecks: this.postchecks,
563
+ operationClass: this.operationClass
564
+ })})`;
565
+ }
566
+ importRequirements() {
567
+ return [];
568
+ }
569
+ };
570
+ var AddColumnCall = class extends SqliteOpFactoryCallNode {
571
+ factoryName = "addColumn";
572
+ operationClass = "additive";
573
+ tableName;
574
+ columnName;
575
+ column;
576
+ label;
577
+ constructor(tableName, column) {
578
+ super();
579
+ this.tableName = tableName;
580
+ this.columnName = column.name;
581
+ this.column = column;
582
+ this.label = `Add column ${column.name} on ${tableName}`;
583
+ this.freeze();
584
+ }
585
+ async toOp(lowerer) {
586
+ if (lowerer === void 0) throw sqliteError("MIGRATION.SQLITE_CONTROL_STACK_MISSING", `AddColumnCall.toOp: a lowerer is required on the SQLite planner path (column "${this.column.name}" on table "${this.tableName}"). Pass the control adapter to createSqliteMigrationPlanner.`, { meta: {
587
+ factory: this.factoryName,
588
+ tableName: this.tableName,
589
+ columnName: this.column.name
590
+ } });
591
+ const checks = columnExistsAst(this.tableName, this.column.name);
592
+ const absent = await lowerer.lowerToExecuteRequest(checks.columnAbsent());
593
+ const present = await lowerer.lowerToExecuteRequest(checks.columnPresent());
594
+ return {
595
+ id: `column.${this.tableName}.${this.column.name}`,
596
+ label: `Add column ${this.column.name} on ${this.tableName}`,
597
+ summary: `Adds column ${this.column.name} on ${this.tableName}`,
598
+ operationClass: "additive",
599
+ target: {
600
+ id: "sqlite",
601
+ details: buildTargetDetails("column", this.column.name, this.tableName)
602
+ },
603
+ precheck: [step(`ensure column "${this.column.name}" is missing`, absent.sql, absent.params)],
604
+ execute: [step(`add column "${this.column.name}"`, addColumnExecuteSql(this.tableName, this.column))],
605
+ postcheck: [step(`verify column "${this.column.name}" exists`, present.sql, present.params)]
606
+ };
607
+ }
608
+ renderTypeScript() {
609
+ return `this.addColumn({ table: ${jsonToTsSource(this.tableName)}, column: ${jsonToTsSource(this.column)} })`;
610
+ }
611
+ importRequirements() {
612
+ return [];
613
+ }
614
+ };
615
+ var DropColumnCall = class extends SqliteOpFactoryCallNode {
616
+ factoryName = "dropColumn";
617
+ operationClass = "destructive";
618
+ tableName;
619
+ columnName;
620
+ label;
621
+ constructor(tableName, columnName) {
622
+ super();
623
+ this.tableName = tableName;
624
+ this.columnName = columnName;
625
+ this.label = `Drop column ${columnName} on ${tableName}`;
626
+ this.freeze();
627
+ }
628
+ async toOp(lowerer) {
629
+ if (lowerer === void 0) throw sqliteError("MIGRATION.SQLITE_CONTROL_STACK_MISSING", `DropColumnCall.toOp: a lowerer is required on the SQLite planner path (column "${this.columnName}" on table "${this.tableName}"). Pass the control adapter to createSqliteMigrationPlanner.`, { meta: {
630
+ factory: this.factoryName,
631
+ tableName: this.tableName,
632
+ columnName: this.columnName
633
+ } });
634
+ const checks = columnExistsAst(this.tableName, this.columnName);
635
+ const present = await lowerer.lowerToExecuteRequest(checks.columnPresent());
636
+ const absent = await lowerer.lowerToExecuteRequest(checks.columnAbsent());
637
+ return {
638
+ id: `dropColumn.${this.tableName}.${this.columnName}`,
639
+ label: `Drop column ${this.columnName} on ${this.tableName}`,
640
+ summary: `Drops column ${this.columnName} on ${this.tableName} which is not in the contract`,
641
+ operationClass: "destructive",
642
+ target: {
643
+ id: "sqlite",
644
+ details: buildTargetDetails("column", this.columnName, this.tableName)
645
+ },
646
+ precheck: [step(`ensure column "${this.columnName}" exists on "${this.tableName}"`, present.sql, present.params)],
647
+ execute: [step(`drop column "${this.columnName}" from "${this.tableName}"`, dropColumnExecuteSql(this.tableName, this.columnName))],
648
+ postcheck: [step(`verify column "${this.columnName}" is gone from "${this.tableName}"`, absent.sql, absent.params)]
649
+ };
650
+ }
651
+ renderTypeScript() {
652
+ return `this.dropColumn({ table: ${jsonToTsSource(this.tableName)}, column: ${jsonToTsSource(this.columnName)} })`;
653
+ }
654
+ importRequirements() {
655
+ return [];
656
+ }
657
+ };
658
+ var CreateIndexCall = class extends SqliteOpFactoryCallNode {
659
+ factoryName = "createIndex";
660
+ operationClass = "additive";
661
+ tableName;
662
+ indexName;
663
+ columns;
664
+ label;
665
+ constructor(tableName, indexName, columns) {
666
+ super();
667
+ this.tableName = tableName;
668
+ this.indexName = indexName;
669
+ this.columns = columns;
670
+ this.label = `Create index ${indexName} on ${tableName}`;
671
+ this.freeze();
672
+ }
673
+ async toOp(lowerer) {
674
+ if (lowerer === void 0) throw sqliteError("MIGRATION.SQLITE_CONTROL_STACK_MISSING", `CreateIndexCall.toOp: a lowerer is required on the SQLite planner path (index "${this.indexName}" on table "${this.tableName}"). Pass the control adapter to createSqliteMigrationPlanner.`, { meta: {
675
+ factory: this.factoryName,
676
+ tableName: this.tableName,
677
+ indexName: this.indexName
678
+ } });
679
+ const checks = indexExistsAst(this.indexName);
680
+ const absent = await lowerer.lowerToExecuteRequest(checks.indexAbsent());
681
+ const present = await lowerer.lowerToExecuteRequest(checks.indexPresent());
682
+ return {
683
+ id: `index.${this.tableName}.${this.indexName}`,
684
+ label: `Create index ${this.indexName} on ${this.tableName}`,
685
+ summary: `Creates index ${this.indexName} on ${this.tableName}`,
686
+ operationClass: "additive",
687
+ target: {
688
+ id: "sqlite",
689
+ details: buildTargetDetails("index", this.indexName, this.tableName)
690
+ },
691
+ precheck: [step(`ensure index "${this.indexName}" is missing`, absent.sql, absent.params)],
692
+ execute: [step(`create index "${this.indexName}"`, buildCreateIndexSql(this.tableName, this.indexName, this.columns))],
693
+ postcheck: [step(`verify index "${this.indexName}" exists`, present.sql, present.params)]
694
+ };
695
+ }
696
+ renderTypeScript() {
697
+ return `this.createIndex({ table: ${jsonToTsSource(this.tableName)}, index: ${jsonToTsSource(this.indexName)}, columns: ${jsonToTsSource(this.columns)} })`;
698
+ }
699
+ importRequirements() {
700
+ return [];
701
+ }
702
+ };
703
+ var DropIndexCall = class extends SqliteOpFactoryCallNode {
704
+ factoryName = "dropIndex";
705
+ operationClass = "destructive";
706
+ tableName;
707
+ indexName;
708
+ label;
709
+ constructor(tableName, indexName) {
710
+ super();
711
+ this.tableName = tableName;
712
+ this.indexName = indexName;
713
+ this.label = `Drop index ${indexName} on ${tableName}`;
714
+ this.freeze();
715
+ }
716
+ async toOp(lowerer) {
717
+ if (lowerer === void 0) throw sqliteError("MIGRATION.SQLITE_CONTROL_STACK_MISSING", `DropIndexCall.toOp: a lowerer is required on the SQLite planner path (index "${this.indexName}" on table "${this.tableName}"). Pass the control adapter to createSqliteMigrationPlanner.`, { meta: {
718
+ factory: this.factoryName,
719
+ tableName: this.tableName,
720
+ indexName: this.indexName
721
+ } });
722
+ const checks = indexExistsAst(this.indexName);
723
+ const present = await lowerer.lowerToExecuteRequest(checks.indexPresent());
724
+ const absent = await lowerer.lowerToExecuteRequest(checks.indexAbsent());
725
+ return {
726
+ id: `dropIndex.${this.tableName}.${this.indexName}`,
727
+ label: `Drop index ${this.indexName} on ${this.tableName}`,
728
+ summary: `Drops index ${this.indexName} on ${this.tableName} which is not in the contract`,
729
+ operationClass: "destructive",
730
+ target: {
731
+ id: "sqlite",
732
+ details: buildTargetDetails("index", this.indexName, this.tableName)
733
+ },
734
+ precheck: [step(`ensure index "${this.indexName}" exists`, present.sql, present.params)],
735
+ execute: [step(`drop index "${this.indexName}"`, buildDropIndexSql(this.indexName))],
736
+ postcheck: [step(`verify index "${this.indexName}" is gone`, absent.sql, absent.params)]
737
+ };
738
+ }
739
+ renderTypeScript() {
740
+ return `this.dropIndex({ table: ${jsonToTsSource(this.tableName)}, index: ${jsonToTsSource(this.indexName)} })`;
741
+ }
742
+ importRequirements() {
743
+ return [];
744
+ }
745
+ };
746
+ /**
747
+ * A planner-generated data-transform stub. The current default strategy
748
+ * (`nullabilityTighteningBackfillStrategy`) emits one of these with a
749
+ * backfill-flavored `id`/`label` when the policy allows `'data'` and the
750
+ * contract tightens a column's nullability, but the op itself is generic —
751
+ * any future strategy that needs a placeholder data step can construct one
752
+ * with its own id/label.
753
+ *
754
+ * `toOp()` always throws `MIGRATION.UNFILLED_PLACEHOLDER`: the planner cannot lower a stubbed
755
+ * transform to a runtime op — the user must edit the rendered
756
+ * `migration.ts` and re-emit.
757
+ */
758
+ var DataTransformCall = class extends SqliteOpFactoryCallNode {
759
+ factoryName = "dataTransform";
760
+ operationClass = "data";
761
+ id;
762
+ label;
763
+ tableName;
764
+ columnName;
765
+ constructor(id, label, tableName, columnName) {
766
+ super();
767
+ this.id = id;
768
+ this.label = label;
769
+ this.tableName = tableName;
770
+ this.columnName = columnName;
771
+ this.freeze();
772
+ }
773
+ toOp(_lowerer) {
774
+ throw errorUnfilledPlaceholder(this.label);
775
+ }
776
+ renderTypeScript() {
777
+ const slot = `${this.tableName}-${this.columnName}-backfill-sql`;
778
+ return [
779
+ "dataTransform({",
780
+ ` id: ${jsonToTsSource(this.id)},`,
781
+ ` label: ${jsonToTsSource(this.label)},`,
782
+ ` table: ${jsonToTsSource(this.tableName)},`,
783
+ ` description: ${jsonToTsSource(`Backfill NULL ${this.columnName} values in ${this.tableName}`)},`,
784
+ ` run: () => placeholder(${jsonToTsSource(slot)}),`,
785
+ "})"
786
+ ].join("\n");
787
+ }
788
+ importRequirements() {
789
+ return [{
790
+ moduleSpecifier: TARGET_MIGRATION_MODULE,
791
+ symbol: this.factoryName
792
+ }, {
793
+ moduleSpecifier: TARGET_MIGRATION_MODULE,
794
+ symbol: "placeholder"
795
+ }];
796
+ }
797
+ };
798
+ /**
799
+ * Laundered pre-built operation. Mirrors Postgres's `RawSqlCall`: wraps an
800
+ * already-materialized `SqlMigrationPlanOperation` (typically produced by a
801
+ * SQL-family helper or a codec lifecycle hook) so the planner can carry it
802
+ * alongside structured call IR. `toOp()` returns the stored op unchanged;
803
+ * `renderTypeScript()` emits `rawSql({...})` with the op serialized as a
804
+ * JSON literal — round-tripping requires every field on the op to be
805
+ * JSON-serializable (no closures).
806
+ */
807
+ var RawSqlCall = class extends SqliteOpFactoryCallNode {
808
+ factoryName = "rawSql";
809
+ operationClass;
810
+ label;
811
+ op;
812
+ constructor(op) {
813
+ super();
814
+ this.op = op;
815
+ this.label = op.label;
816
+ this.operationClass = op.operationClass;
817
+ this.freeze();
818
+ }
819
+ toOp(_lowerer) {
820
+ return this.op;
821
+ }
822
+ renderTypeScript() {
823
+ return `rawSql(${jsonToTsSource(this.op)})`;
824
+ }
825
+ };
826
+ //#endregion
827
+ export { DropColumnCall as a, RawSqlCall as c, buildColumnTypeSql as d, buildRecreatePostchecks as f, step as h, DataTransformCall as i, RecreateTableCall as l, renderDefaultLiteral as m, CreateIndexCall as n, DropIndexCall as o, buildRecreateSummary as p, CreateTableCall as r, DropTableCall as s, AddColumnCall as t, buildColumnDefaultSql as u };
828
+
829
+ //# sourceMappingURL=op-factory-call-C_or6163-B_LDzC37.mjs.map