@prisma/orm-target-sqlite 8.0.0-rc.17-dev.37 → 8.0.0-rc.17-dev.39

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 (69) hide show
  1. package/dist/{adapter-Cfp6xn4m-BtODbERC.mjs → adapter-Cfp6xn4m-CqnRsbnV.mjs} +2 -2
  2. package/dist/{adapter-Cfp6xn4m-BtODbERC.mjs.map → adapter-Cfp6xn4m-CqnRsbnV.mjs.map} +1 -1
  3. package/dist/adapter.mjs +2 -2
  4. package/dist/adapter__adapter.mjs +1 -1
  5. package/dist/adapter__control.mjs +3 -3
  6. package/dist/adapter__runtime.mjs +1 -1
  7. package/dist/adapter__sql-renderer.mjs +1 -1
  8. package/dist/{control-DJq7MF_s.mjs → control-CVmnzYUI.mjs} +113 -18
  9. package/dist/control-CVmnzYUI.mjs.map +1 -0
  10. package/dist/{control-4njwExvT.mjs → control-DKT_rL3s.mjs} +11 -3
  11. package/dist/control-DKT_rL3s.mjs.map +1 -0
  12. package/dist/driver.mjs +1 -1
  13. package/dist/driver__control.mjs +1 -1
  14. package/dist/{migration-CIKnw9my.mjs → migration-DOkUBr8w.mjs} +2 -2
  15. package/dist/{migration-CIKnw9my.mjs.map → migration-DOkUBr8w.mjs.map} +1 -1
  16. package/dist/{migration-BsYgVFeM.d.mts → migration-wH0Hw2VD.d.mts} +3 -3
  17. package/dist/{migration-BsYgVFeM.d.mts.map → migration-wH0Hw2VD.d.mts.map} +1 -1
  18. package/dist/{op-factory-call-C-6Lxtlm.d.mts → op-factory-call-DAI1NqNz.d.mts} +16 -10
  19. package/dist/op-factory-call-DAI1NqNz.d.mts.map +1 -0
  20. package/dist/{op-factory-call-gwVgzGbc-caCULmpj.mjs → op-factory-call-hxIbAMSY-CinxsQHg.mjs} +234 -25
  21. package/dist/op-factory-call-hxIbAMSY-CinxsQHg.mjs.map +1 -0
  22. package/dist/{planner-Ddpm7j-w-BzyQ-raY.mjs → planner-BENMBCnG-CW6-1do-.mjs} +65 -23
  23. package/dist/planner-BENMBCnG-CW6-1do-.mjs.map +1 -0
  24. package/dist/planner-produced-sqlite-migration-CB9UDEdR.d.mts +1 -0
  25. package/dist/{planner-produced-sqlite-migration-D50U99OT--9-v0jj6.d.mts → planner-produced-sqlite-migration-CkHb8T4n-SM_tztzo.d.mts} +3 -3
  26. package/dist/planner-produced-sqlite-migration-CkHb8T4n-SM_tztzo.d.mts.map +1 -0
  27. package/dist/{planner-produced-sqlite-migration-Cj_QCROn-0eatEGzt.mjs → planner-produced-sqlite-migration-DjEZTiif-DpC6rk_q.mjs} +4 -4
  28. package/dist/{planner-produced-sqlite-migration-Cj_QCROn-0eatEGzt.mjs.map → planner-produced-sqlite-migration-DjEZTiif-DpC6rk_q.mjs.map} +1 -1
  29. package/dist/{planner-DRDXnFF-.d.mts → planner-tv5z1cn8.d.mts} +5 -4
  30. package/dist/planner-tv5z1cn8.d.mts.map +1 -0
  31. package/dist/{render-ops-CBkWzmKj-6vfxyU3K.mjs → render-ops-B889CY71-JvEeW9B4.mjs} +3 -3
  32. package/dist/{render-ops-CBkWzmKj-6vfxyU3K.mjs.map → render-ops-B889CY71-JvEeW9B4.mjs.map} +1 -1
  33. package/dist/{sql-utils-C2O4zVkP-Dz3Hb85I.mjs → sql-utils-XGT5Esi2-5k9pvJeF.mjs} +30 -3
  34. package/dist/sql-utils-XGT5Esi2-5k9pvJeF.mjs.map +1 -0
  35. package/dist/{sqlite-contract-view-BrXalcTm-DYDH4LQC.mjs → sqlite-contract-view-TELBWEt4-CVsdZnpX.mjs} +3 -3
  36. package/dist/{sqlite-contract-view-BrXalcTm-DYDH4LQC.mjs.map → sqlite-contract-view-TELBWEt4-CVsdZnpX.mjs.map} +1 -1
  37. package/dist/{sqlite-migration-omhBdJEh-CizoFjMg.d.mts → sqlite-migration-BqbQmUY1-CTmurARU.d.mts} +9 -3
  38. package/dist/{sqlite-migration-omhBdJEh-CizoFjMg.d.mts.map → sqlite-migration-BqbQmUY1-CTmurARU.d.mts.map} +1 -1
  39. package/dist/{sqlite-migration-D7DWt0JL-D_5jFkOx.mjs → sqlite-migration-CTNkjYJ1-eRdmsbpK.mjs} +235 -66
  40. package/dist/sqlite-migration-CTNkjYJ1-eRdmsbpK.mjs.map +1 -0
  41. package/dist/{tables-CvLOKCiJ-DYQkJ90L.d.mts → tables-DD_EmImp-B8ZaVBMr.d.mts} +16 -7
  42. package/dist/tables-DD_EmImp-B8ZaVBMr.d.mts.map +1 -0
  43. package/dist/target.d.mts +6 -6
  44. package/dist/target.mjs +9 -9
  45. package/dist/target__control.mjs +2 -2
  46. package/dist/target__migration.d.mts +2 -2
  47. package/dist/target__migration.mjs +2 -2
  48. package/dist/target__op-factory-call.d.mts +1 -1
  49. package/dist/target__op-factory-call.mjs +1 -1
  50. package/dist/target__planner-produced-sqlite-migration.d.mts +2 -2
  51. package/dist/target__planner-produced-sqlite-migration.mjs +1 -1
  52. package/dist/target__planner.d.mts +1 -1
  53. package/dist/target__planner.mjs +1 -1
  54. package/dist/target__render-ops.mjs +1 -1
  55. package/dist/target__runtime.mjs +1 -1
  56. package/dist/target__runtime.mjs.map +1 -1
  57. package/dist/target__sql-utils.mjs +1 -1
  58. package/package.json +9 -9
  59. package/dist/control-4njwExvT.mjs.map +0 -1
  60. package/dist/control-DJq7MF_s.mjs.map +0 -1
  61. package/dist/op-factory-call-C-6Lxtlm.d.mts.map +0 -1
  62. package/dist/op-factory-call-gwVgzGbc-caCULmpj.mjs.map +0 -1
  63. package/dist/planner-DRDXnFF-.d.mts.map +0 -1
  64. package/dist/planner-Ddpm7j-w-BzyQ-raY.mjs.map +0 -1
  65. package/dist/planner-produced-sqlite-migration-CWUahMOX.d.mts +0 -1
  66. package/dist/planner-produced-sqlite-migration-D50U99OT--9-v0jj6.d.mts.map +0 -1
  67. package/dist/sql-utils-C2O4zVkP-Dz3Hb85I.mjs.map +0 -1
  68. package/dist/sqlite-migration-D7DWt0JL-D_5jFkOx.mjs.map +0 -1
  69. package/dist/tables-CvLOKCiJ-DYQkJ90L.d.mts.map +0 -1
@@ -1,8 +1,8 @@
1
1
  import { n as sqliteError } from "./errors-DnR-sMHS-KkMLIP2U.mjs";
2
- import { g as isSqliteOpFactoryCall } from "./op-factory-call-gwVgzGbc-caCULmpj.mjs";
2
+ import { v as isSqliteOpFactoryCall } from "./op-factory-call-hxIbAMSY-CinxsQHg.mjs";
3
3
  import { blindCast } from "@prisma/orm-framework/utils/casts";
4
4
  import { isThenable } from "@prisma/orm-framework/utils/promise";
5
- //#region ../../../3-targets/3-targets/sqlite/dist/render-ops-CBkWzmKj.mjs
5
+ //#region ../../../3-targets/3-targets/sqlite/dist/render-ops-B889CY71.mjs
6
6
  function assertSqliteOp(op, callFactoryName) {
7
7
  const targetId = blindCast(op).target?.id;
8
8
  if (targetId !== "sqlite") throw sqliteError("MIGRATION.TARGET_MISMATCH", `renderOps: expected sqlite op but got target.id="${String(targetId)}" for op.id="${op.id}" (factoryName="${callFactoryName}"). An OpFactoryCall produced an op for a different target on the sqlite planner path; check the call's target binding.`, { meta: {
@@ -31,4 +31,4 @@ function renderOps(calls, lowerer) {
31
31
  //#endregion
32
32
  export { renderOps as t };
33
33
 
34
- //# sourceMappingURL=render-ops-CBkWzmKj-6vfxyU3K.mjs.map
34
+ //# sourceMappingURL=render-ops-B889CY71-JvEeW9B4.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"render-ops-CBkWzmKj-6vfxyU3K.mjs","names":[],"sources":["../../../../3-targets/3-targets/sqlite/dist/render-ops-CBkWzmKj.mjs"],"sourcesContent":["import { n as sqliteError } from \"./errors-DnR-sMHS.mjs\";\nimport { p as isSqliteOpFactoryCall } from \"./op-factory-call-gwVgzGbc.mjs\";\nimport { blindCast } from \"@internal/utils/casts\";\nimport { isThenable } from \"@internal/utils/promise\";\n//#region src/core/migrations/render-ops.ts\nfunction assertSqliteOp(op, callFactoryName) {\n\tconst targetId = blindCast(op).target?.id;\n\tif (targetId !== \"sqlite\") throw sqliteError(\"MIGRATION.TARGET_MISMATCH\", `renderOps: expected sqlite op but got target.id=\"${String(targetId)}\" for op.id=\"${op.id}\" (factoryName=\"${callFactoryName}\"). An OpFactoryCall produced an op for a different target on the sqlite planner path; check the call's target binding.`, { meta: {\n\t\topId: op.id,\n\t\ttargetId: String(targetId),\n\t\tfactoryName: callFactoryName\n\t} });\n}\nfunction checkedOp(opOrPromise, callFactoryName) {\n\tif (isThenable(opOrPromise)) {\n\t\tconst checked = opOrPromise.then((op) => {\n\t\t\tassertSqliteOp(op, callFactoryName);\n\t\t\treturn op;\n\t\t});\n\t\tchecked.catch(() => void 0);\n\t\treturn checked;\n\t}\n\tassertSqliteOp(opOrPromise, callFactoryName);\n\treturn opOrPromise;\n}\nfunction renderOps(calls, lowerer) {\n\treturn calls.flatMap((c) => {\n\t\treturn (isSqliteOpFactoryCall(c) ? c.toOps(lowerer) : [blindCast(c).toOp(lowerer)]).map((opOrPromise) => checkedOp(opOrPromise, c.factoryName));\n\t});\n}\n//#endregion\nexport { renderOps as t };\n\n//# sourceMappingURL=render-ops-CBkWzmKj.mjs.map"],"mappings":";;;;;AAKA,SAAS,eAAe,IAAI,iBAAiB;CAC5C,MAAM,WAAW,UAAU,EAAE,CAAC,CAAC,QAAQ;CACvC,IAAI,aAAa,UAAU,MAAM,YAAY,6BAA6B,oDAAoD,OAAO,QAAQ,EAAE,eAAe,GAAG,GAAG,kBAAkB,gBAAgB,0HAA0H,EAAE,MAAM;EACvU,MAAM,GAAG;EACT,UAAU,OAAO,QAAQ;EACzB,aAAa;CACd,EAAE,CAAC;AACJ;AACA,SAAS,UAAU,aAAa,iBAAiB;CAChD,IAAI,WAAW,WAAW,GAAG;EAC5B,MAAM,UAAU,YAAY,MAAM,OAAO;GACxC,eAAe,IAAI,eAAe;GAClC,OAAO;EACR,CAAC;EACD,QAAQ,YAAY,KAAK,CAAC;EAC1B,OAAO;CACR;CACA,eAAe,aAAa,eAAe;CAC3C,OAAO;AACR;AACA,SAAS,UAAU,OAAO,SAAS;CAClC,OAAO,MAAM,SAAS,MAAM;EAC3B,QAAQ,sBAAsB,CAAC,IAAI,EAAE,MAAM,OAAO,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC,KAAK,OAAO,CAAC,EAAA,CAAG,KAAK,gBAAgB,UAAU,aAAa,EAAE,WAAW,CAAC;CAC/I,CAAC;AACF"}
1
+ {"version":3,"file":"render-ops-B889CY71-JvEeW9B4.mjs","names":[],"sources":["../../../../3-targets/3-targets/sqlite/dist/render-ops-B889CY71.mjs"],"sourcesContent":["import { n as sqliteError } from \"./errors-DnR-sMHS.mjs\";\nimport { p as isSqliteOpFactoryCall } from \"./op-factory-call-hxIbAMSY.mjs\";\nimport { blindCast } from \"@internal/utils/casts\";\nimport { isThenable } from \"@internal/utils/promise\";\n//#region src/core/migrations/render-ops.ts\nfunction assertSqliteOp(op, callFactoryName) {\n\tconst targetId = blindCast(op).target?.id;\n\tif (targetId !== \"sqlite\") throw sqliteError(\"MIGRATION.TARGET_MISMATCH\", `renderOps: expected sqlite op but got target.id=\"${String(targetId)}\" for op.id=\"${op.id}\" (factoryName=\"${callFactoryName}\"). An OpFactoryCall produced an op for a different target on the sqlite planner path; check the call's target binding.`, { meta: {\n\t\topId: op.id,\n\t\ttargetId: String(targetId),\n\t\tfactoryName: callFactoryName\n\t} });\n}\nfunction checkedOp(opOrPromise, callFactoryName) {\n\tif (isThenable(opOrPromise)) {\n\t\tconst checked = opOrPromise.then((op) => {\n\t\t\tassertSqliteOp(op, callFactoryName);\n\t\t\treturn op;\n\t\t});\n\t\tchecked.catch(() => void 0);\n\t\treturn checked;\n\t}\n\tassertSqliteOp(opOrPromise, callFactoryName);\n\treturn opOrPromise;\n}\nfunction renderOps(calls, lowerer) {\n\treturn calls.flatMap((c) => {\n\t\treturn (isSqliteOpFactoryCall(c) ? c.toOps(lowerer) : [blindCast(c).toOp(lowerer)]).map((opOrPromise) => checkedOp(opOrPromise, c.factoryName));\n\t});\n}\n//#endregion\nexport { renderOps as t };\n\n//# sourceMappingURL=render-ops-B889CY71.mjs.map"],"mappings":";;;;;AAKA,SAAS,eAAe,IAAI,iBAAiB;CAC5C,MAAM,WAAW,UAAU,EAAE,CAAC,CAAC,QAAQ;CACvC,IAAI,aAAa,UAAU,MAAM,YAAY,6BAA6B,oDAAoD,OAAO,QAAQ,EAAE,eAAe,GAAG,GAAG,kBAAkB,gBAAgB,0HAA0H,EAAE,MAAM;EACvU,MAAM,GAAG;EACT,UAAU,OAAO,QAAQ;EACzB,aAAa;CACd,EAAE,CAAC;AACJ;AACA,SAAS,UAAU,aAAa,iBAAiB;CAChD,IAAI,WAAW,WAAW,GAAG;EAC5B,MAAM,UAAU,YAAY,MAAM,OAAO;GACxC,eAAe,IAAI,eAAe;GAClC,OAAO;EACR,CAAC;EACD,QAAQ,YAAY,KAAK,CAAC;EAC1B,OAAO;CACR;CACA,eAAe,aAAa,eAAe;CAC3C,OAAO;AACR;AACA,SAAS,UAAU,OAAO,SAAS;CAClC,OAAO,MAAM,SAAS,MAAM;EAC3B,QAAQ,sBAAsB,CAAC,IAAI,EAAE,MAAM,OAAO,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC,KAAK,OAAO,CAAC,EAAA,CAAG,KAAK,gBAAgB,UAAU,aAAa,EAAE,WAAW,CAAC;CAC/I,CAAC;AACF"}
@@ -1,5 +1,5 @@
1
1
  import { n as sqliteError } from "./errors-DnR-sMHS-KkMLIP2U.mjs";
2
- //#region ../../../3-targets/3-targets/sqlite/dist/sql-utils-C2O4zVkP.mjs
2
+ //#region ../../../3-targets/3-targets/sqlite/dist/sql-utils-XGT5Esi2.mjs
3
3
  /**
4
4
  * Shared SQL utility functions for the SQLite target.
5
5
  *
@@ -29,7 +29,34 @@ function escapeLiteral(value) {
29
29
  } });
30
30
  return value.replace(/'/g, "''");
31
31
  }
32
+ /** The quotes this target's SQL knows, for the check of SQL a migration writes into a statement. */
33
+ const SQLITE_QUOTING = [
34
+ {
35
+ open: "'",
36
+ close: "'",
37
+ doubledCloseEscapes: true,
38
+ backslashEscapes: false
39
+ },
40
+ {
41
+ open: "\"",
42
+ close: "\"",
43
+ doubledCloseEscapes: true,
44
+ backslashEscapes: false
45
+ },
46
+ {
47
+ open: "`",
48
+ close: "`",
49
+ doubledCloseEscapes: true,
50
+ backslashEscapes: false
51
+ },
52
+ {
53
+ open: "[",
54
+ close: "]",
55
+ doubledCloseEscapes: false,
56
+ backslashEscapes: false
57
+ }
58
+ ];
32
59
  //#endregion
33
- export { quoteIdentifier as n, escapeLiteral as t };
60
+ export { escapeLiteral as n, quoteIdentifier as r, SQLITE_QUOTING as t };
34
61
 
35
- //# sourceMappingURL=sql-utils-C2O4zVkP-Dz3Hb85I.mjs.map
62
+ //# sourceMappingURL=sql-utils-XGT5Esi2-5k9pvJeF.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sql-utils-XGT5Esi2-5k9pvJeF.mjs","names":[],"sources":["../../../../3-targets/3-targets/sqlite/dist/sql-utils-XGT5Esi2.mjs"],"sourcesContent":["import { n as sqliteError } from \"./errors-DnR-sMHS.mjs\";\n//#region src/core/sql-utils.ts\n/**\n* Shared SQL utility functions for the SQLite target.\n*\n* These functions handle safe SQL identifier and literal escaping. They\n* live in `target-sqlite` (mirroring `target-postgres/src/core/sql-utils.ts`)\n* so both the control adapter (used at emit time) and the runtime adapter\n* (used at execute time) can depend on them through a single one-way edge:\n* `adapter-sqlite → target-sqlite`. Hosting them target-side avoids the\n* cyclic workspace dependency that would arise if `target-sqlite` reached\n* back into `adapter-sqlite` for these primitives.\n*/\nfunction quoteIdentifier(identifier) {\n\tif (identifier.length === 0) throw sqliteError(\"CONTRACT.IDENTIFIER_INVALID\", \"Identifier cannot be empty\", { meta: {\n\t\tvalue: identifier,\n\t\tcontext: \"identifier\"\n\t} });\n\tif (identifier.includes(\"\\0\")) throw sqliteError(\"CONTRACT.IDENTIFIER_INVALID\", \"Identifier cannot contain null bytes\", { meta: {\n\t\tvalue: identifier.replace(/\\0/g, \"\\\\0\"),\n\t\tcontext: \"identifier\"\n\t} });\n\treturn `\"${identifier.replace(/\"/g, \"\\\"\\\"\")}\"`;\n}\nfunction escapeLiteral(value) {\n\tif (value.includes(\"\\0\")) throw sqliteError(\"CONTRACT.IDENTIFIER_INVALID\", \"Literal value cannot contain null bytes\", { meta: {\n\t\tvalue: value.replace(/\\0/g, \"\\\\0\"),\n\t\tcontext: \"literal\"\n\t} });\n\treturn value.replace(/'/g, \"''\");\n}\n/** The quotes this target's SQL knows, for the check of SQL a migration writes into a statement. */\nconst SQLITE_QUOTING = [\n\t{\n\t\topen: \"'\",\n\t\tclose: \"'\",\n\t\tdoubledCloseEscapes: true,\n\t\tbackslashEscapes: false\n\t},\n\t{\n\t\topen: \"\\\"\",\n\t\tclose: \"\\\"\",\n\t\tdoubledCloseEscapes: true,\n\t\tbackslashEscapes: false\n\t},\n\t{\n\t\topen: \"`\",\n\t\tclose: \"`\",\n\t\tdoubledCloseEscapes: true,\n\t\tbackslashEscapes: false\n\t},\n\t{\n\t\topen: \"[\",\n\t\tclose: \"]\",\n\t\tdoubledCloseEscapes: false,\n\t\tbackslashEscapes: false\n\t}\n];\n//#endregion\nexport { escapeLiteral as n, quoteIdentifier as r, SQLITE_QUOTING as t };\n\n//# sourceMappingURL=sql-utils-XGT5Esi2.mjs.map"],"mappings":";;;;;;;;;;;;;AAaA,SAAS,gBAAgB,YAAY;CACpC,IAAI,WAAW,WAAW,GAAG,MAAM,YAAY,+BAA+B,8BAA8B,EAAE,MAAM;EACnH,OAAO;EACP,SAAS;CACV,EAAE,CAAC;CACH,IAAI,WAAW,SAAS,IAAI,GAAG,MAAM,YAAY,+BAA+B,wCAAwC,EAAE,MAAM;EAC/H,OAAO,WAAW,QAAQ,OAAO,KAAK;EACtC,SAAS;CACV,EAAE,CAAC;CACH,OAAO,IAAI,WAAW,QAAQ,MAAM,MAAM,EAAE;AAC7C;AACA,SAAS,cAAc,OAAO;CAC7B,IAAI,MAAM,SAAS,IAAI,GAAG,MAAM,YAAY,+BAA+B,2CAA2C,EAAE,MAAM;EAC7H,OAAO,MAAM,QAAQ,OAAO,KAAK;EACjC,SAAS;CACV,EAAE,CAAC;CACH,OAAO,MAAM,QAAQ,MAAM,IAAI;AAChC;;AAEA,MAAM,iBAAiB;CACtB;EACC,MAAM;EACN,OAAO;EACP,qBAAqB;EACrB,kBAAkB;CACnB;CACA;EACC,MAAM;EACN,OAAO;EACP,qBAAqB;EACrB,kBAAkB;CACnB;CACA;EACC,MAAM;EACN,OAAO;EACP,qBAAqB;EACrB,kBAAkB;CACnB;CACA;EACC,MAAM;EACN,OAAO;EACP,qBAAqB;EACrB,kBAAkB;CACnB;AACD"}
@@ -1,12 +1,12 @@
1
1
  import { n as sqliteError } from "./errors-DnR-sMHS-KkMLIP2U.mjs";
2
- import { n as quoteIdentifier } from "./sql-utils-C2O4zVkP-Dz3Hb85I.mjs";
2
+ import { r as quoteIdentifier } from "./sql-utils-XGT5Esi2-5k9pvJeF.mjs";
3
3
  import { blindCast } from "@prisma/orm-framework/utils/casts";
4
4
  import { UNBOUND_NAMESPACE_ID, freezeNode, hydrateNamespaceEntities } from "@prisma/orm-framework/components/ir";
5
5
  import { SqlNamespaceBase } from "@prisma/orm-family-sql/contract/types";
6
6
  import { buildSqlSingleNamespaceView } from "@prisma/orm-family-sql/contract/contract-view";
7
7
  import { SqlContractSerializerBase } from "@prisma/orm-family-sql/family/ir";
8
8
  import { tableEntityKind } from "@prisma/orm-family-sql/contract/entity-kinds";
9
- //#region ../../../3-targets/3-targets/sqlite/dist/sqlite-contract-view-BrXalcTm.mjs
9
+ //#region ../../../3-targets/3-targets/sqlite/dist/sqlite-contract-view-TELBWEt4.mjs
10
10
  const SQLITE_NAMESPACE_KIND = "sqlite-namespace";
11
11
  /**
12
12
  * SQLite namespace concretion carrying table metadata under
@@ -149,4 +149,4 @@ const SqliteContractView = {
149
149
  //#endregion
150
150
  export { sqliteCreateNamespace as i, SqliteContractView as n, SqliteUnboundDatabase as r, SqliteContractSerializer as t };
151
151
 
152
- //# sourceMappingURL=sqlite-contract-view-BrXalcTm-DYDH4LQC.mjs.map
152
+ //# sourceMappingURL=sqlite-contract-view-TELBWEt4-CVsdZnpX.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"sqlite-contract-view-BrXalcTm-DYDH4LQC.mjs","names":[],"sources":["../../../../3-targets/3-targets/sqlite/dist/sqlite-contract-view-BrXalcTm.mjs"],"sourcesContent":["import { n as sqliteError } from \"./errors-DnR-sMHS.mjs\";\nimport { n as quoteIdentifier } from \"./sql-utils-C2O4zVkP.mjs\";\nimport { blindCast } from \"@internal/utils/casts\";\nimport { SqlNamespaceBase } from \"@internal/sql-contract/types\";\nimport { UNBOUND_NAMESPACE_ID, freezeNode, hydrateNamespaceEntities } from \"@internal/framework-components/ir\";\nimport { buildSqlSingleNamespaceView } from \"@internal/sql-contract/contract-view\";\nimport { SqlContractSerializerBase } from \"@internal/family-sql/ir\";\nimport { tableEntityKind } from \"@internal/sql-contract/entity-kinds\";\n//#region src/core/sqlite-unbound-database.ts\nconst SQLITE_NAMESPACE_KIND = \"sqlite-namespace\";\n/**\n* SQLite namespace concretion carrying table metadata under\n* `entries.table` and unqualified `qualifyTable()` emission for runtime\n* SQL rendering.\n*/\nvar SqliteDatabase = class extends SqlNamespaceBase {\n\tid;\n\tentries;\n\tconstructor(input) {\n\t\tsuper();\n\t\tthis.id = input.id;\n\t\tconst dispatched = hydrateNamespaceEntities(input.entries, /* @__PURE__ */ new Map([[\"table\", tableEntityKind]]), \"carry\");\n\t\tthis.entries = Object.freeze(blindCast(dispatched));\n\t\tObject.defineProperty(this, \"kind\", {\n\t\t\tvalue: SQLITE_NAMESPACE_KIND,\n\t\t\twritable: false,\n\t\t\tenumerable: false,\n\t\t\tconfigurable: true\n\t\t});\n\t\tfreezeNode(this);\n\t}\n\tget table() {\n\t\treturn this.entries.table ?? Object.freeze({});\n\t}\n\tqualifier() {\n\t\treturn \"\";\n\t}\n\tqualifyTable(tableName) {\n\t\treturn quoteIdentifier(tableName);\n\t}\n};\n/**\n* SQLite target `Namespace` concretion. SQLite has no schema or\n* database-namespacing concept at the SQL level — there is exactly one\n* effective namespace per connection, so the target ships a single\n* singleton bound to the framework's `UNBOUND_NAMESPACE_ID` slot.\n*\n* Qualifier emission elides the prefix entirely: rendered DDL and\n* queries look unqualified (`CREATE TABLE \"users\" (...)`), matching\n* SQLite's native dialect. Call sites stay polymorphic — they ask the\n* namespace for its qualifier and consume the empty/unqualified result\n* the same way Postgres consumes a `\"schema\"` prefix.\n*\n* The SQLite PSL interpreter rejects every explicit `namespace { … }`\n* block with a diagnostic naming SQLite; only the implicit\n* `__unspecified__` AST bucket reaches the SQLite interpreter, which\n* lowers it to this singleton.\n*/\nvar SqliteUnboundDatabase = class SqliteUnboundDatabase extends SqliteDatabase {\n\tstatic instance = new SqliteUnboundDatabase();\n\tconstructor() {\n\t\tsuper({\n\t\t\tid: UNBOUND_NAMESPACE_ID,\n\t\t\tentries: { table: {} }\n\t\t});\n\t}\n};\n/**\n* The SQLite target's rejection of expression and partial indexes: the\n* family-shared authoring surfaces parse `expression:`/`where:` for every\n* SQL target, but SQLite neither renders nor introspects them (project\n* non-goal) — a contract carrying one must fail loudly at lowering instead\n* of silently producing an unverifiable index. Target-owned so no family\n* code branches on the target.\n*/\nfunction rejectSqlBodyIndexes(input) {\n\tconst tables = input.entries[\"table\"];\n\tif (tables === void 0) return;\n\tfor (const [tableName, table] of Object.entries(tables)) {\n\t\tconst indexes = blindCast(table).indexes;\n\t\tfor (const index of indexes ?? []) if (index.expression !== void 0 || index.where !== void 0) throw sqliteError(\"CONTRACT.ARGUMENT_INVALID\", `SQLite does not support expression or partial indexes: index \"${index.name ?? \"<unnamed>\"}\" on table \"${tableName}\" declares ${index.expression !== void 0 ? \"an expression\" : \"a where predicate\"}. Use a fields-only index, or author this index against a Postgres target.`);\n\t}\n}\nfunction buildSqliteNamespace(input) {\n\trejectSqlBodyIndexes(input);\n\tif (input.id !== UNBOUND_NAMESPACE_ID) throw sqliteError(\"CONTRACT.NAMESPACE_INVALID\", `buildSqliteNamespace: SQLite has no schema concept; the only valid namespace id is \"${UNBOUND_NAMESPACE_ID}\" (received \"${input.id}\").`, { meta: { received: input.id } });\n\tconst tableKind = input.entries[\"table\"];\n\tconst tableCount = tableKind !== void 0 ? Object.keys(tableKind).length : 0;\n\tconst hasUnknownKinds = Object.keys(input.entries).some((kind) => kind !== \"table\");\n\tif (tableCount === 0 && !hasUnknownKinds) return SqliteUnboundDatabase.instance;\n\treturn new SqliteDatabase({\n\t\tid: input.id,\n\t\tentries: input.entries\n\t});\n}\n/**\n* Target-supplied `Namespace` factory the SQLite target plumbs through\n* `defineContract({ createNamespace })`. SQLite has only one\n* effective namespace slot — the framework `UNBOUND_NAMESPACE_ID`\n* sentinel — so the factory always returns the singleton or a fresh\n* `SqliteDatabase` for the unbound slot with tables. The SQL family's\n* defensive validation in `defineContract` already rejects\n* user-declared SQLite namespaces, so this throw is a structural\n* safety net rather than a user-facing surface.\n*/\nfunction sqliteCreateNamespace(input) {\n\treturn buildSqliteNamespace(input);\n}\n//#endregion\n//#region src/core/sqlite-contract-serializer.ts\n/**\n* SQLite target `ContractSerializer` concretion. Mirrors the Postgres\n* shape: inherits the full SQL-family deserialization pipeline and\n* materialises namespace entries as SQLite database concretions that\n* expose `qualifyTable()` for runtime SQL rendering.\n*/\nvar SqliteContractSerializer = class extends SqlContractSerializerBase {\n\tconstructor() {\n\t\tsuper(/* @__PURE__ */ new Map());\n\t}\n\thydrateSqlNamespaceEntry(nsId, raw) {\n\t\treturn buildSqliteNamespace(blindCast(super.hydrateSqlNamespaceEntry(nsId, raw)));\n\t}\n\tserializeContract(contract) {\n\t\tconst { storage, ...rest } = contract;\n\t\tconst namespacesJson = {};\n\t\tfor (const [nsId, ns] of Object.entries(storage.namespaces)) namespacesJson[nsId] = {\n\t\t\tid: ns.id,\n\t\t\tentries: this.serializeNamespaceEntries(ns.entries)\n\t\t};\n\t\treturn blindCast({\n\t\t\t...rest,\n\t\t\tstorage: {\n\t\t\t\tstorageHash: String(storage.storageHash),\n\t\t\t\tnamespaces: namespacesJson,\n\t\t\t\t...storage.types !== void 0 ? { types: this.serializeJsonObject(storage.types) } : {}\n\t\t\t}\n\t\t});\n\t}\n};\n//#endregion\n//#region src/core/sqlite-contract-view.ts\nconst SqliteContractView = {\n\t/** Wrap an already-deserialized SQLite contract in a view. */\n\tfrom(contract) {\n\t\treturn buildSqlSingleNamespaceView(contract);\n\t},\n\t/** Deserialize a SQLite contract JSON envelope and wrap it in a view. */\n\tfromJson(json) {\n\t\treturn buildSqlSingleNamespaceView(new SqliteContractSerializer().deserializeContract(json));\n\t}\n};\n//#endregion\nexport { sqliteCreateNamespace as i, SqliteContractSerializer as n, SqliteUnboundDatabase as r, SqliteContractView as t };\n\n//# sourceMappingURL=sqlite-contract-view-BrXalcTm.mjs.map"],"mappings":"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"}
1
+ {"version":3,"file":"sqlite-contract-view-TELBWEt4-CVsdZnpX.mjs","names":[],"sources":["../../../../3-targets/3-targets/sqlite/dist/sqlite-contract-view-TELBWEt4.mjs"],"sourcesContent":["import { n as sqliteError } from \"./errors-DnR-sMHS.mjs\";\nimport { r as quoteIdentifier } from \"./sql-utils-XGT5Esi2.mjs\";\nimport { blindCast } from \"@internal/utils/casts\";\nimport { SqlNamespaceBase } from \"@internal/sql-contract/types\";\nimport { UNBOUND_NAMESPACE_ID, freezeNode, hydrateNamespaceEntities } from \"@internal/framework-components/ir\";\nimport { buildSqlSingleNamespaceView } from \"@internal/sql-contract/contract-view\";\nimport { SqlContractSerializerBase } from \"@internal/family-sql/ir\";\nimport { tableEntityKind } from \"@internal/sql-contract/entity-kinds\";\n//#region src/core/sqlite-unbound-database.ts\nconst SQLITE_NAMESPACE_KIND = \"sqlite-namespace\";\n/**\n* SQLite namespace concretion carrying table metadata under\n* `entries.table` and unqualified `qualifyTable()` emission for runtime\n* SQL rendering.\n*/\nvar SqliteDatabase = class extends SqlNamespaceBase {\n\tid;\n\tentries;\n\tconstructor(input) {\n\t\tsuper();\n\t\tthis.id = input.id;\n\t\tconst dispatched = hydrateNamespaceEntities(input.entries, /* @__PURE__ */ new Map([[\"table\", tableEntityKind]]), \"carry\");\n\t\tthis.entries = Object.freeze(blindCast(dispatched));\n\t\tObject.defineProperty(this, \"kind\", {\n\t\t\tvalue: SQLITE_NAMESPACE_KIND,\n\t\t\twritable: false,\n\t\t\tenumerable: false,\n\t\t\tconfigurable: true\n\t\t});\n\t\tfreezeNode(this);\n\t}\n\tget table() {\n\t\treturn this.entries.table ?? Object.freeze({});\n\t}\n\tqualifier() {\n\t\treturn \"\";\n\t}\n\tqualifyTable(tableName) {\n\t\treturn quoteIdentifier(tableName);\n\t}\n};\n/**\n* SQLite target `Namespace` concretion. SQLite has no schema or\n* database-namespacing concept at the SQL level — there is exactly one\n* effective namespace per connection, so the target ships a single\n* singleton bound to the framework's `UNBOUND_NAMESPACE_ID` slot.\n*\n* Qualifier emission elides the prefix entirely: rendered DDL and\n* queries look unqualified (`CREATE TABLE \"users\" (...)`), matching\n* SQLite's native dialect. Call sites stay polymorphic — they ask the\n* namespace for its qualifier and consume the empty/unqualified result\n* the same way Postgres consumes a `\"schema\"` prefix.\n*\n* The SQLite PSL interpreter rejects every explicit `namespace { … }`\n* block with a diagnostic naming SQLite; only the implicit\n* `__unspecified__` AST bucket reaches the SQLite interpreter, which\n* lowers it to this singleton.\n*/\nvar SqliteUnboundDatabase = class SqliteUnboundDatabase extends SqliteDatabase {\n\tstatic instance = new SqliteUnboundDatabase();\n\tconstructor() {\n\t\tsuper({\n\t\t\tid: UNBOUND_NAMESPACE_ID,\n\t\t\tentries: { table: {} }\n\t\t});\n\t}\n};\n/**\n* The SQLite target's rejection of expression and partial indexes: the\n* family-shared authoring surfaces parse `expression:`/`where:` for every\n* SQL target, but SQLite neither renders nor introspects them (project\n* non-goal) — a contract carrying one must fail loudly at lowering instead\n* of silently producing an unverifiable index. Target-owned so no family\n* code branches on the target.\n*/\nfunction rejectSqlBodyIndexes(input) {\n\tconst tables = input.entries[\"table\"];\n\tif (tables === void 0) return;\n\tfor (const [tableName, table] of Object.entries(tables)) {\n\t\tconst indexes = blindCast(table).indexes;\n\t\tfor (const index of indexes ?? []) if (index.expression !== void 0 || index.where !== void 0) throw sqliteError(\"CONTRACT.ARGUMENT_INVALID\", `SQLite does not support expression or partial indexes: index \"${index.name ?? \"<unnamed>\"}\" on table \"${tableName}\" declares ${index.expression !== void 0 ? \"an expression\" : \"a where predicate\"}. Use a fields-only index, or author this index against a Postgres target.`);\n\t}\n}\nfunction buildSqliteNamespace(input) {\n\trejectSqlBodyIndexes(input);\n\tif (input.id !== UNBOUND_NAMESPACE_ID) throw sqliteError(\"CONTRACT.NAMESPACE_INVALID\", `buildSqliteNamespace: SQLite has no schema concept; the only valid namespace id is \"${UNBOUND_NAMESPACE_ID}\" (received \"${input.id}\").`, { meta: { received: input.id } });\n\tconst tableKind = input.entries[\"table\"];\n\tconst tableCount = tableKind !== void 0 ? Object.keys(tableKind).length : 0;\n\tconst hasUnknownKinds = Object.keys(input.entries).some((kind) => kind !== \"table\");\n\tif (tableCount === 0 && !hasUnknownKinds) return SqliteUnboundDatabase.instance;\n\treturn new SqliteDatabase({\n\t\tid: input.id,\n\t\tentries: input.entries\n\t});\n}\n/**\n* Target-supplied `Namespace` factory the SQLite target plumbs through\n* `defineContract({ createNamespace })`. SQLite has only one\n* effective namespace slot — the framework `UNBOUND_NAMESPACE_ID`\n* sentinel — so the factory always returns the singleton or a fresh\n* `SqliteDatabase` for the unbound slot with tables. The SQL family's\n* defensive validation in `defineContract` already rejects\n* user-declared SQLite namespaces, so this throw is a structural\n* safety net rather than a user-facing surface.\n*/\nfunction sqliteCreateNamespace(input) {\n\treturn buildSqliteNamespace(input);\n}\n//#endregion\n//#region src/core/sqlite-contract-serializer.ts\n/**\n* SQLite target `ContractSerializer` concretion. Mirrors the Postgres\n* shape: inherits the full SQL-family deserialization pipeline and\n* materialises namespace entries as SQLite database concretions that\n* expose `qualifyTable()` for runtime SQL rendering.\n*/\nvar SqliteContractSerializer = class extends SqlContractSerializerBase {\n\tconstructor() {\n\t\tsuper(/* @__PURE__ */ new Map());\n\t}\n\thydrateSqlNamespaceEntry(nsId, raw) {\n\t\treturn buildSqliteNamespace(blindCast(super.hydrateSqlNamespaceEntry(nsId, raw)));\n\t}\n\tserializeContract(contract) {\n\t\tconst { storage, ...rest } = contract;\n\t\tconst namespacesJson = {};\n\t\tfor (const [nsId, ns] of Object.entries(storage.namespaces)) namespacesJson[nsId] = {\n\t\t\tid: ns.id,\n\t\t\tentries: this.serializeNamespaceEntries(ns.entries)\n\t\t};\n\t\treturn blindCast({\n\t\t\t...rest,\n\t\t\tstorage: {\n\t\t\t\tstorageHash: String(storage.storageHash),\n\t\t\t\tnamespaces: namespacesJson,\n\t\t\t\t...storage.types !== void 0 ? { types: this.serializeJsonObject(storage.types) } : {}\n\t\t\t}\n\t\t});\n\t}\n};\n//#endregion\n//#region src/core/sqlite-contract-view.ts\nconst SqliteContractView = {\n\t/** Wrap an already-deserialized SQLite contract in a view. */\n\tfrom(contract) {\n\t\treturn buildSqlSingleNamespaceView(contract);\n\t},\n\t/** Deserialize a SQLite contract JSON envelope and wrap it in a view. */\n\tfromJson(json) {\n\t\treturn buildSqlSingleNamespaceView(new SqliteContractSerializer().deserializeContract(json));\n\t}\n};\n//#endregion\nexport { sqliteCreateNamespace as i, SqliteContractSerializer as n, SqliteUnboundDatabase as r, SqliteContractView as t };\n\n//# sourceMappingURL=sqlite-contract-view-TELBWEt4.mjs.map"],"mappings":"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"}
@@ -1,5 +1,5 @@
1
1
  import { t as SqlitePlanTargetDetails } from "./planner-target-details-xR6UfIcz-CMahymzq.mjs";
2
- import { a as SqliteTableSpec, i as SqliteIndexSpec, n as RecreatePostcheck, r as SqliteColumnSpec } from "./tables-CvLOKCiJ-DYQkJ90L.mjs";
2
+ import { a as SqliteTableSpec, i as SqliteIndexSpec, n as RecreatePostcheck, r as SqliteColumnSpec } from "./tables-DD_EmImp-B8ZaVBMr.mjs";
3
3
  import { t as SqliteContractView } from "./sqlite-contract-view-BDw8T5Cp-CbLVOPJq.mjs";
4
4
  import { DdlColumn, DdlTableConstraint } from "@prisma/orm-family-sql/relational-core/ast";
5
5
  import { ControlStack } from "@prisma/orm-framework/components/control";
@@ -9,7 +9,7 @@ import { SqlStorage } from "@prisma/orm-family-sql/contract/types";
9
9
  import { Migration } from "@prisma/orm-family-sql/family/migration";
10
10
  import { ColumnDefault, Contract } from "@prisma/orm-framework/contract/types";
11
11
  import { SqlControlAdapter } from "@prisma/orm-family-sql/family/control-adapter";
12
- //#region ../../../3-targets/3-targets/sqlite/dist/sqlite-migration-omhBdJEh.d.mts
12
+ //#region ../../../3-targets/3-targets/sqlite/dist/sqlite-migration-BqbQmUY1.d.mts
13
13
  //#region src/core/migrations/sqlite-migration.d.ts
14
14
  type Op = SqlMigrationPlanOperation<SqlitePlanTargetDetails>;
15
15
  /**
@@ -128,6 +128,12 @@ declare abstract class SqliteMigration<Start extends Contract<SqlStorage> = Cont
128
128
  readonly summary: string;
129
129
  readonly postchecks: readonly RecreatePostcheck[];
130
130
  readonly operationClass: MigrationOperationClass;
131
+ /** SQL each named column is copied from, such as `CAST("age" AS INTEGER)`. */
132
+ readonly copyExpressions?: Readonly<Record<string, SqlTextInput>>;
133
+ /** The value each named new column takes in the existing rows, such as `''`. */
134
+ readonly temporaryValues?: Readonly<Record<string, SqlTextInput>>;
135
+ /** The columns whose type changes; the rebuild checks each after its copy, as a conversion when it has a copy expression and as SQLite's cast otherwise. */
136
+ readonly retypedColumns?: readonly string[];
131
137
  }): Promise<Op>;
132
138
  }
133
139
  type ColumnDefaultInput = Exclude<ColumnDefault, {
@@ -144,4 +150,4 @@ type SqliteTableSpecInput = Omit<SqliteTableSpec, 'columns'> & {
144
150
  };
145
151
  //#endregion
146
152
  export { SqliteMigration as t };
147
- //# sourceMappingURL=sqlite-migration-omhBdJEh-CizoFjMg.d.mts.map
153
+ //# sourceMappingURL=sqlite-migration-BqbQmUY1-CTmurARU.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"sqlite-migration-omhBdJEh-CizoFjMg.d.mts","names":[],"sources":["../../../../3-targets/3-targets/sqlite/dist/sqlite-migration-omhBdJEh.d.mts"],"mappings":";;;;;;;;;;;;;KAYK,KAAK,0BAA0B;;;;;;;;;;;;;;;;;;;;;;;uBAuBb,gBAAgB,cAAc,SAAS,cAAc,SAAS,aAAa,YAAY,SAAS,cAAc,SAAS,qBAAqB,UAAU,mCAAmC,OAAO;;WAE5M;;;;;;;qBAOU,gBAAgB;EACnC,YAAY,QAAQ;UACZ;;;;;;UAMA;;;;;;MAMJ,eAAe,mBAAmB;;;;;MAKlC,iBAAiB,mBAAmB;YAC9B,YAAY;aACX;aACA;aACA,kBAAkB;aAClB,uBAAuB;MAC9B,QAAQ;YACF,UAAU;aACT;MACP,QAAQ;;;;;;;;;;YAUF,YAAY;aACX;aACA;eACE,QAAQ;;;;;;;;;;;YAWX,aAAa;aACZ;aACA;aACA;eACE,QAAQ;;UAEb;YACE;YACA,UAAU;aACT;aACA,QAAQ;MACf,QAAQ;YACF,WAAW;aACV;aACA;MACP,QAAQ;YACF,YAAY;aACX;aACA;aACA;MACP,QAAQ;YACF,UAAU;aACT;aACA;MACP,QAAQ;YACF,cAAc;aACb;aACA,eAAe;aACf;aACA,kBAAkB;aAClB;aACA,qBAAqB;aACrB,gBAAgB;MACvB,QAAQ;;KAET,qBAAqB,QAAQ;WACvB;;WAEA;WACA,YAAY;;KAElB,wBAAwB,KAAK;WACvB,UAAU;;KAEhB,uBAAuB,KAAK;WACtB,kBAAkB"}
1
+ {"version":3,"file":"sqlite-migration-BqbQmUY1-CTmurARU.d.mts","names":[],"sources":["../../../../3-targets/3-targets/sqlite/dist/sqlite-migration-BqbQmUY1.d.mts"],"mappings":";;;;;;;;;;;;;KAYK,KAAK,0BAA0B;;;;;;;;;;;;;;;;;;;;;;;uBAuBb,gBAAgB,cAAc,SAAS,cAAc,SAAS,aAAa,YAAY,SAAS,cAAc,SAAS,qBAAqB,UAAU,mCAAmC,OAAO;;WAE5M;;;;;;;qBAOU,gBAAgB;EACnC,YAAY,QAAQ;UACZ;;;;;;UAMA;;;;;;MAMJ,eAAe,mBAAmB;;;;;MAKlC,iBAAiB,mBAAmB;YAC9B,YAAY;aACX;aACA;aACA,kBAAkB;aAClB,uBAAuB;MAC9B,QAAQ;YACF,UAAU;aACT;MACP,QAAQ;;;;;;;;;;YAUF,YAAY;aACX;aACA;eACE,QAAQ;;;;;;;;;;;YAWX,aAAa;aACZ;aACA;aACA;eACE,QAAQ;;UAEb;YACE;YACA,UAAU;aACT;aACA,QAAQ;MACf,QAAQ;YACF,WAAW;aACV;aACA;MACP,QAAQ;YACF,YAAY;aACX;aACA;aACA;MACP,QAAQ;YACF,UAAU;aACT;aACA;MACP,QAAQ;YACF,cAAc;aACb;aACA,eAAe;aACf;aACA,kBAAkB;aAClB;aACA,qBAAqB;aACrB,gBAAgB;;aAEhB,kBAAkB,SAAS,eAAe;;aAE1C,kBAAkB,SAAS,eAAe;;aAE1C;MACP,QAAQ;;KAET,qBAAqB,QAAQ;WACvB;;WAEA;WACA,YAAY;;KAElB,wBAAwB,KAAK;WACvB,UAAU;;KAEhB,uBAAuB,KAAK;WACtB,kBAAkB"}
@@ -1,16 +1,21 @@
1
+ import { a as SQLITE_INTEGER_CODEC_ID, c as SQLITE_TEXT_CODEC_ID, i as SQLITE_DATETIME_CODEC_ID, o as SQLITE_JSON_CODEC_ID, t as SQLITE_BIGINT_CODEC_ID } from "./codec-ids-KMliSCRp-BhTbmbGr.mjs";
2
+ import { c as sqliteText, i as sqliteCharacterVarying, n as sqliteCharacter, o as sqliteInteger, s as sqliteReal, t as sqliteBlob } from "./data-types-pFQMl37_-B-3aK_wd.mjs";
1
3
  import { n as sqliteError, t as errorSqliteMigrationStackMissing } from "./errors-DnR-sMHS-KkMLIP2U.mjs";
4
+ import { r as encodeSqliteDatetime } from "./codecs-BctEWIFt-DgMd3dUl.mjs";
2
5
  import { n as SQLITE_NOW_EXPRESSION } from "./datetime-text-Bniwehv--Ddt3VS4z.mjs";
6
+ import { n as escapeLiteral } from "./sql-utils-XGT5Esi2-5k9pvJeF.mjs";
3
7
  import { n as sqliteResolveDefault } from "./default-normalizer-Ch3VFnEH-C-h1XtlJ.mjs";
4
- import { _ as renameTableSteps, a as DropColumnCall, b as sqliteIdentifiersCollide, d as RenameTableCall, f as buildColumnTypeSql, h as indexReplacementCalls, i as DataTransformCall, l as RecreateTableCall, m as buildRecreateSummary, n as CreateIndexCall, o as DropIndexCall, p as buildRecreatePostchecks, r as CreateTableCall, s as DropTableCall, t as AddColumnCall, u as RenameColumnCall, v as renderDefaultLiteral, y as sqliteDefaultToDdlColumnDefault } from "./op-factory-call-gwVgzGbc-caCULmpj.mjs";
8
+ import { C as sqliteIdentifiersCollide, S as sqliteDefaultToDdlColumnDefault, _ as indexReplacementCalls, a as DropColumnCall, b as renameTableSteps, d as RenameTableCall, h as buildRecreateSummary, i as DataTransformCall, l as RecreateTableCall, m as buildRecreatePostchecks, n as CreateIndexCall, o as DropIndexCall, p as buildColumnTypeSql, r as CreateTableCall, s as DropTableCall, t as AddColumnCall, u as RenameColumnCall, x as renderDefaultLiteral } from "./op-factory-call-hxIbAMSY-CinxsQHg.mjs";
5
9
  import { t as CONTROL_TABLE_NAMES } from "./control-tables-D_o8dKRB-BXi43noL.mjs";
6
- import { n as SqliteContractView } from "./sqlite-contract-view-BrXalcTm-DYDH4LQC.mjs";
10
+ import { n as SqliteContractView } from "./sqlite-contract-view-TELBWEt4-CVsdZnpX.mjs";
7
11
  import { DdlColumn, ForeignKeyConstraint, PrimaryKeyConstraint, UniqueConstraint } from "@prisma/orm-family-sql/relational-core/ast";
8
12
  import { ifDefined } from "@prisma/orm-framework/utils/defined";
9
13
  import { blindCast } from "@prisma/orm-framework/utils/casts";
14
+ import { sqlDataTypeOfCodec } from "@prisma/orm-family-sql/contract/data-type";
10
15
  import { diffSchemas, issueOutcome, orderIssuesByDependencies } from "@prisma/orm-framework/components/control";
11
16
  import { sqlTextOf } from "@prisma/orm-family-sql/relational-core/contract-free";
12
17
  import { UNBOUND_NAMESPACE_ID, entityAt } from "@prisma/orm-framework/components/ir";
13
- import { contractToSchemaIR, resolveColumnRenameAgainst, resolveTableRenameAgainst, sqlTypeLookupsOf, unmatchedColumnRename, unmatchedTableRename } from "@prisma/orm-family-sql/family/control";
18
+ import { contractToSchemaIR, extractCodecControlHooks, resolveColumnRenameAgainst, resolveTableRenameAgainst, sqlTypeLookupsOf, unmatchedColumnRename, unmatchedTableRename } from "@prisma/orm-family-sql/family/control";
14
19
  import { PrimaryKey, RelationalSchemaNodeKind, SqlCheckConstraintIR, SqlColumnIR, SqlForeignKeyIR, SqlIndexIR, SqlSchemaIR, SqlTableIR, SqlUniqueIR, contractDefaultRefusal, relationalNodeGranularity } from "@prisma/orm-family-sql/schema-ir/types";
15
20
  import { InternalError } from "@prisma/orm-framework/utils/internal-error";
16
21
  import { verifySqlSchemaByDiff } from "@prisma/orm-family-sql/family/diff";
@@ -19,7 +24,7 @@ import { namingOf, namingOfLiveName, parseWireName } from "@prisma/orm-family-sq
19
24
  import { isArrayEqual } from "@prisma/orm-framework/utils/array-equal";
20
25
  import { Migration } from "@prisma/orm-family-sql/family/migration";
21
26
  import { MigrationContractViews } from "@prisma/orm-toolchain/migration-tools/migration";
22
- //#region ../../../3-targets/3-targets/sqlite/dist/sqlite-migration-D7DWt0JL.mjs
27
+ //#region ../../../3-targets/3-targets/sqlite/dist/sqlite-migration-CTNkjYJ1.mjs
23
28
  /** Renders a column default for the SQLite dialect. */
24
29
  function sqliteRenderDefault(def, column) {
25
30
  if (def.kind === "function") {
@@ -270,6 +275,49 @@ function tableConstraintsFromNode(table, hasInlinePk) {
270
275
  }));
271
276
  return constraints;
272
277
  }
278
+ /** Values for the codecs that store text their reader parses, so `''` would not read back. */
279
+ const CODEC_FILL_VALUES = /* @__PURE__ */ new Map([[SQLITE_DATETIME_CODEC_ID, `'${escapeLiteral(encodeSqliteDatetime(/* @__PURE__ */ new Date(0)))}'`], [SQLITE_JSON_CODEC_ID, `'{}'`]]);
280
+ const DATA_TYPE_FILL_VALUES = /* @__PURE__ */ new Map([
281
+ [sqliteInteger.id, "0"],
282
+ [sqliteReal.id, "0"],
283
+ [sqliteText.id, "''"],
284
+ [sqliteCharacter.id, "''"],
285
+ [sqliteCharacterVarying.id, "''"],
286
+ [sqliteBlob.id, "X''"]
287
+ ]);
288
+ function isParamRecord(value) {
289
+ return value !== null && typeof value === "object" && !Array.isArray(value);
290
+ }
291
+ /**
292
+ * The SQL value a new required column takes in the rows a table already has, or `undefined` when
293
+ * its type has none: the column's codec hook first, as on Postgres, then a value the codec reads
294
+ * back, then a value of the data type it stores.
295
+ */
296
+ function sqliteFillValue(column, codecHooks, types) {
297
+ const codecRef = column.codecRef;
298
+ if (codecRef === void 0 || column.many === true) return void 0;
299
+ const dataType = sqlDataTypeOfCodec(codecRef.codecId, types).id;
300
+ const fromHook = codecHooks.get(codecRef.codecId)?.resolveIdentityValue?.({
301
+ dataType,
302
+ codecId: codecRef.codecId,
303
+ ...isParamRecord(codecRef.typeParams) ? { typeParams: codecRef.typeParams } : {}
304
+ });
305
+ if (fromHook !== void 0) return fromHook ?? void 0;
306
+ return CODEC_FILL_VALUES.get(codecRef.codecId) ?? DATA_TYPE_FILL_VALUES.get(dataType);
307
+ }
308
+ /**
309
+ * SQLite migration strategies.
310
+ *
311
+ * Each strategy examines the node-typed issue list, consumes issues it
312
+ * handles, and returns the `SqliteOpFactoryCall[]` to address them. The issue
313
+ * planner runs each strategy in order and routes whatever's left through
314
+ * `mapNodeIssueToCall`.
315
+ *
316
+ * SQLite has no enums and no component-declared database dependencies. The
317
+ * recipe that needs strategy-level multi-issue consumption is `recreateTable`,
318
+ * which absorbs type/nullability/default/constraint mismatches, and required
319
+ * columns added to existing tables, for a given table into one rebuild.
320
+ */
273
321
  /**
274
322
  * Classifies a node issue into the operation class a recreate absorbing it
275
323
  * would need, or `null` when the strategy doesn't handle this node/reason at
@@ -285,13 +333,32 @@ function tableConstraintsFromNode(table, hasInlinePk) {
285
333
  function columnNameOf(issue) {
286
334
  return blindCast(issue.expected).name;
287
335
  }
288
- function classifyNodeIssue(issue) {
336
+ /**
337
+ * The changes of codec a table rebuild's copy makes without losing a value: the column's type
338
+ * affinity stores each old value as the same value of the new type. An integer becomes its decimal
339
+ * text; a real is not listed, since SQLite writes it as text with fifteen significant digits. Keyed
340
+ * by codec, not data type, because `Int` and `BigInt` differ only in their codec.
341
+ */
342
+ const LOSSLESS_COPIES = /* @__PURE__ */ new Set([
343
+ `${SQLITE_INTEGER_CODEC_ID}→${SQLITE_TEXT_CODEC_ID}`,
344
+ `${SQLITE_BIGINT_CODEC_ID}→${SQLITE_TEXT_CODEC_ID}`,
345
+ `${SQLITE_INTEGER_CODEC_ID}→${SQLITE_BIGINT_CODEC_ID}`
346
+ ]);
347
+ function copyKeepsEveryValue(fromCodec, to) {
348
+ const toCodec = to.codecRef?.codecId;
349
+ return fromCodec !== void 0 && toCodec !== void 0 && LOSSLESS_COPIES.has(`${fromCodec}→${toCodec}`);
350
+ }
351
+ function classifyNodeIssue(issue, ctx) {
289
352
  const node = issue.expected ?? issue.actual;
290
353
  if (node === void 0) return null;
291
354
  switch (blindCast(node).nodeKind) {
292
- case RelationalSchemaNodeKind.column:
355
+ case RelationalSchemaNodeKind.column: {
293
356
  if (issueOutcome(issue) !== "not-equal") return null;
294
- return columnTypeChanged(blindCast(issue.expected), blindCast(issue.actual)) ? "destructive" : "widening";
357
+ const expected = blindCast(issue.expected);
358
+ const actual = blindCast(issue.actual);
359
+ const fromCodec = ctx.originCodecId(String(issue.path[1]), actual.name);
360
+ return columnTypeChanged(expected, actual) && !copyKeepsEveryValue(fromCodec, expected) ? "destructive" : "widening";
361
+ }
295
362
  case RelationalSchemaNodeKind.columnDefault:
296
363
  case RelationalSchemaNodeKind.primaryKey:
297
364
  case RelationalSchemaNodeKind.foreignKey:
@@ -299,47 +366,130 @@ function classifyNodeIssue(issue) {
299
366
  default: return null;
300
367
  }
301
368
  }
369
+ function columnNode(node) {
370
+ return blindCast(node);
371
+ }
372
+ function isColumnIssue(issue) {
373
+ const node = issue.expected ?? issue.actual;
374
+ return node !== void 0 && blindCast(node).nodeKind === RelationalSchemaNodeKind.column;
375
+ }
376
+ /** The column a `--convert` or `--backfill` statement of `kind` names, if one names it. */
377
+ function statementColumn(ctx, kind, tableName, columnName) {
378
+ if (!ctx.policy.allowedOperationClasses.includes("data")) return void 0;
379
+ return ctx.statementColumns[kind].find((column) => column.table === tableName && column.column === columnName);
380
+ }
302
381
  /**
303
- * Groups recreate-eligible issues by table, decides per-table operation class
304
- * (destructive wins over widening, and a recreate that leaves a live column
305
- * out of the new table loses its values, so it is destructive), and emits one `RecreateTableCall` per
306
- * table. Returns unchanged-or-smaller issue list — issues the strategy
307
- * consumed are removed so `mapNodeIssueToCall` doesn't double-handle them.
382
+ * A required column with no default that the plan adds to a table the database already has, so
383
+ * existing rows need a value for it.
384
+ */
385
+ function addedRequiredColumn(issue, ctx) {
386
+ if (issueOutcome(issue) !== "not-found" || !isColumnIssue(issue)) return void 0;
387
+ const tableName = issue.path[1];
388
+ if (tableName === void 0 || ctx.actual.tables[tableName] === void 0) return void 0;
389
+ const column = columnNode(issue.expected);
390
+ return column.nullable || column.resolvedDefault !== void 0 ? void 0 : column;
391
+ }
392
+ const CLASS_ORDER = [
393
+ "additive",
394
+ "widening",
395
+ "data",
396
+ "destructive"
397
+ ];
398
+ function highestClass(classes) {
399
+ return classes.reduce((highest, next) => CLASS_ORDER.indexOf(next) > CLASS_ORDER.indexOf(highest) ? next : highest, "additive");
400
+ }
401
+ /**
402
+ * Groups recreate-eligible issues by table and emits one `RecreateTableCall` per table, removing
403
+ * the issues it consumed so `mapNodeIssueToCall` does not handle them again.
404
+ *
405
+ * - A type change is `destructive`, since the copy can change values, unless a `--convert`
406
+ * statement names the column: the copy then goes through a slot the user fills, and the rebuild
407
+ * is `data`. Either way the rebuild checks after its copy that every value took the new type.
408
+ * - A nullability or constraint change alone is `widening`: a tightening copy fails on a NULL
409
+ * rather than losing it.
410
+ * - A required column with no default added to an existing table is copied from a temporary value
411
+ * (`additive`). A column in a key or foreign key, whose values come from a value set, or whose
412
+ * type has no such value is carried with nothing to copy from: the rebuild succeeds on an empty
413
+ * table and fails on `NOT NULL` when the table has rows. A column a `--backfill` statement names
414
+ * was added nullable and filled by earlier calls, so the rebuild copies it like a live column.
415
+ * - A rebuild that leaves a live column out loses its values, so it is `destructive`.
308
416
  *
309
- * The full desired/live table shapes come from `ctx.expected`/`ctx.actual`
310
- * directly (keyed by table name — SQLite is a flat, single-namespace target)
311
- * rather than from any individual issue, since a single drifted attribute's
312
- * issue only carries that attribute's own node, never the whole table.
417
+ * The table shapes come from `ctx.expected` and `ctx.actual`, keyed by table name: SQLite is a
418
+ * flat, single-namespace target, and one issue only carries its own node.
313
419
  */
314
420
  const recreateTableStrategy = (issues, ctx) => {
315
421
  const byTable = /* @__PURE__ */ new Map();
316
422
  const consumed = /* @__PURE__ */ new Set();
423
+ const codecHooks = extractCodecControlHooks(ctx.frameworkComponents);
424
+ const rebuildOf = (tableName) => {
425
+ const existing = byTable.get(tableName);
426
+ if (existing !== void 0) return existing;
427
+ const created = {
428
+ issues: [],
429
+ classes: [],
430
+ retypedColumns: [],
431
+ copyExpressions: {},
432
+ temporaryValues: {},
433
+ addedColumns: []
434
+ };
435
+ byTable.set(tableName, created);
436
+ return created;
437
+ };
317
438
  for (const issue of issues) {
318
- const cls = classifyNodeIssue(issue);
319
- if (!cls) continue;
320
439
  const tableName = issue.path[1];
321
440
  if (tableName === void 0) continue;
322
- const entry = byTable.get(tableName) ?? {
323
- issues: [],
324
- hasDestructive: false,
325
- lossyColumns: []
326
- };
327
- entry.issues.push(issue);
328
- if (cls === "destructive") {
329
- entry.hasDestructive = true;
330
- entry.lossyColumns.push(columnNameOf(issue));
441
+ const added = addedRequiredColumn(issue, ctx);
442
+ if (added !== void 0) {
443
+ const expectedTable = ctx.expected.tables[tableName];
444
+ if (statementColumn(ctx, "backfill", tableName, added.name) !== void 0) {
445
+ const rebuild = rebuildOf(tableName);
446
+ rebuild.issues.push(issue);
447
+ rebuild.addedColumns.push(added.name);
448
+ rebuild.classes.push("widening");
449
+ consumed.add(issue);
450
+ continue;
451
+ }
452
+ const fill = expectedTable === void 0 || !ctx.takesTemporaryValue(tableName, added.name) ? void 0 : sqliteFillValue(added, codecHooks, ctx.types);
453
+ const rebuild = rebuildOf(tableName);
454
+ rebuild.issues.push(issue);
455
+ if (fill !== void 0) rebuild.temporaryValues[added.name] = {
456
+ kind: "sql",
457
+ sql: fill
458
+ };
459
+ rebuild.classes.push("additive");
460
+ consumed.add(issue);
461
+ continue;
331
462
  }
332
- byTable.set(tableName, entry);
463
+ const cls = classifyNodeIssue(issue, ctx);
464
+ if (!cls) continue;
465
+ const rebuild = rebuildOf(tableName);
466
+ rebuild.issues.push(issue);
333
467
  consumed.add(issue);
468
+ if (cls === "widening") {
469
+ rebuild.classes.push("widening");
470
+ continue;
471
+ }
472
+ const column = columnNameOf(issue);
473
+ const converted = statementColumn(ctx, "convert", tableName, column);
474
+ rebuild.retypedColumns.push(column);
475
+ if (converted === void 0) {
476
+ rebuild.classes.push("destructive");
477
+ continue;
478
+ }
479
+ rebuild.copyExpressions[column] = {
480
+ kind: "placeholder",
481
+ slot: `${converted.text}:convert`
482
+ };
483
+ rebuild.classes.push("data");
334
484
  }
335
485
  if (byTable.size === 0) return { kind: "no_match" };
336
486
  const calls = [];
337
- for (const [tableName, entry] of byTable) {
487
+ for (const [tableName, rebuild] of byTable) {
338
488
  const expectedTable = ctx.expected.tables[tableName];
339
489
  const actualTable = ctx.actual.tables[tableName];
340
490
  if (!expectedTable || !actualTable) continue;
341
491
  const leavesColumnsOut = Object.keys(actualTable.columns).some((column) => !Object.hasOwn(expectedTable.columns, column));
342
- const operationClass = entry.hasDestructive || leavesColumnsOut ? "destructive" : "widening";
492
+ const operationClass = highestClass([...rebuild.classes, ...leavesColumnsOut ? ["destructive"] : []]);
343
493
  const tableSpec = tableSpecFromNode(expectedTable, ctx.types);
344
494
  const indexes = expectedTable.indexes.map((idx) => ({
345
495
  name: idx.name,
@@ -348,12 +498,15 @@ const recreateTableStrategy = (issues, ctx) => {
348
498
  calls.push(new RecreateTableCall({
349
499
  tableName,
350
500
  contractTable: tableSpec,
351
- schemaColumnNames: Object.keys(actualTable.columns),
501
+ schemaColumnNames: [...Object.keys(actualTable.columns), ...rebuild.addedColumns],
352
502
  indexes,
353
- summary: buildRecreateSummary(tableName, entry.issues),
354
- postchecks: buildRecreatePostchecks(tableName, entry.issues, tableSpec),
355
- operationClass
356
- }, entry.lossyColumns));
503
+ summary: buildRecreateSummary(tableName, rebuild.issues),
504
+ postchecks: [...buildRecreatePostchecks(tableName, rebuild.issues, tableSpec, /* @__PURE__ */ new Set([...Object.keys(rebuild.copyExpressions), ...Object.keys(rebuild.temporaryValues)]), new Set(tableSpec.columns.filter(({ name }) => statementColumn(ctx, "backfill", tableName, name) !== void 0).map(({ name }) => name)))],
505
+ operationClass,
506
+ copyExpressions: rebuild.copyExpressions,
507
+ temporaryValues: rebuild.temporaryValues,
508
+ retypedColumns: rebuild.retypedColumns
509
+ }));
357
510
  }
358
511
  return {
359
512
  kind: "match",
@@ -363,37 +516,28 @@ const recreateTableStrategy = (issues, ctx) => {
363
516
  };
364
517
  };
365
518
  /**
366
- * When the policy allows `'data'` and the expected tree tightens one or more
367
- * columns from nullable to NOT NULL, emit a `DataTransformCall` stub per
368
- * tightened column. The user fills the backfill `UPDATE` in the rendered
369
- * `migration.ts` before the subsequent `RecreateTableCall` copies data into
370
- * the tightened schema (whose `INSERT INTO temp SELECT … FROM old` would
371
- * otherwise fail at runtime if any `NULL`s remain).
372
- *
373
- * Does NOT consume the tightening issue — `recreateTableStrategy` still
374
- * needs it to produce the actual recreate that enforces the NOT NULL at
375
- * the schema level. The backfill op and the recreate op end up in the
376
- * recipe slot in strategy order (backfill first, recreate second), which
377
- * matches the required execution order.
378
- *
379
- * Mirrors Postgres's `nullableTighteningCallStrategy`. When `'data'` is not
380
- * in the policy (the default `db update` / `db init` path), the strategy
381
- * short-circuits and the recreate alone runs, failing at runtime if NULLs
382
- * are present.
519
+ * Writes the calls that come before the rebuild of a column a `--backfill` statement names: for a
520
+ * required column added to an existing table, the nullable add and a data transform whose slot the
521
+ * user fills; for a column made required, the data transform. The rebuild that makes the column
522
+ * NOT NULL comes from `recreateTableStrategy`, so this strategy consumes no issue. Without the
523
+ * statement, a tightening rebuild fails on a NULL rather than guessing a value for it.
383
524
  */
384
525
  const nullabilityTighteningBackfillStrategy = (issues, ctx) => {
385
- if (!ctx.policy.allowedOperationClasses.includes("data")) return { kind: "no_match" };
386
526
  const calls = [];
387
527
  for (const issue of issues) {
388
- if (issueOutcome(issue) !== "not-equal" || issue.expected === void 0 || issue.actual === void 0) continue;
389
- if (blindCast(issue.expected).nodeKind !== RelationalSchemaNodeKind.column) continue;
390
- const expectedColumn = blindCast(issue.expected);
391
- const actualColumn = blindCast(issue.actual);
392
- if (expectedColumn.nullable === actualColumn.nullable) continue;
393
- if (expectedColumn.nullable) continue;
394
528
  const tableName = issue.path[1];
395
- if (tableName === void 0) continue;
396
- calls.push(new DataTransformCall(`data_migration.backfill-${tableName}-${expectedColumn.name}`, `Backfill NULLs in "${tableName}"."${expectedColumn.name}" before NOT NULL tightening`, tableName, expectedColumn.name));
529
+ if (tableName === void 0 || !isColumnIssue(issue)) continue;
530
+ const added = addedRequiredColumn(issue, ctx);
531
+ const tightened = issueOutcome(issue) === "not-equal" && !columnNode(issue.expected).nullable && columnNode(issue.actual).nullable ? columnNode(issue.expected) : void 0;
532
+ const column = added ?? tightened;
533
+ if (column === void 0) continue;
534
+ const named = statementColumn(ctx, "backfill", tableName, column.name);
535
+ if (named === void 0) continue;
536
+ if (added !== void 0) calls.push(new AddColumnCall(tableName, {
537
+ ...columnSpecFromNode(added, false, ctx.types),
538
+ nullable: true
539
+ }));
540
+ calls.push(new DataTransformCall(`data_migration.backfill-${tableName}-${column.name}`, `Backfill NULLs in "${tableName}"."${column.name}" before NOT NULL tightening`, tableName, column.name, `${named.text}:run`));
397
541
  }
398
542
  if (calls.length === 0) return { kind: "no_match" };
399
543
  return {
@@ -588,7 +732,13 @@ function planIssues(options) {
588
732
  actual: options.actual ?? emptySchemaIR(),
589
733
  policy,
590
734
  frameworkComponents,
591
- types: sqlTypeLookupsOf(frameworkComponents)
735
+ types: sqlTypeLookupsOf(frameworkComponents),
736
+ statementColumns: options.statementColumns ?? {
737
+ convert: [],
738
+ backfill: []
739
+ },
740
+ takesTemporaryValue: options.takesTemporaryValue ?? (() => true),
741
+ originCodecId: options.originCodecId ?? (() => void 0)
592
742
  };
593
743
  const strategies = options.strategies ?? sqlitePlannerStrategies;
594
744
  let remaining = options.issues;
@@ -633,7 +783,14 @@ function planIssues(options) {
633
783
  gatedDefault = gatedDefaultBucket;
634
784
  }
635
785
  if (conflicts.length > 0) return notOk(conflicts);
636
- const combined = [...gatedDefault, ...gatedBucketable];
786
+ const rebuiltIndexes = new Set(gatedRecipe.flatMap((call) => call instanceof RecreateTableCall ? call.indexes.map((index) => indexKey(call.tableName, index.name)) : []));
787
+ const bucketed = [...gatedDefault, ...gatedBucketable];
788
+ const addedBeforeIndexes = new Set(bucketed.flatMap((call) => call instanceof AddColumnCall ? [indexKey(call.tableName, call.columnName)] : []));
789
+ const indexesANewColumn = (call) => {
790
+ const live = context.actual.tables[call.tableName];
791
+ return live !== void 0 && call.columns.some((column) => live.columns[column] === void 0 && !addedBeforeIndexes.has(indexKey(call.tableName, column)));
792
+ };
793
+ const combined = bucketed.filter((call) => !(call instanceof CreateIndexCall) || !indexesANewColumn(call) || !rebuiltIndexes.has(indexKey(call.tableName, call.indexName)));
637
794
  const byCategory = (cat) => combined.filter((c) => classifyCall(c) === cat);
638
795
  return ok({ calls: [
639
796
  ...byCategory("create-table"),
@@ -645,6 +802,9 @@ function planIssues(options) {
645
802
  ...byCategory("drop-table")
646
803
  ] });
647
804
  }
805
+ function indexKey(tableName, indexName) {
806
+ return JSON.stringify([tableName, indexName]);
807
+ }
648
808
  function emptySchemaIR() {
649
809
  return new SqlSchemaIR({ tables: {} });
650
810
  }
@@ -1137,12 +1297,15 @@ var SqliteMigration = class extends Migration {
1137
1297
  return new DropIndexCall(options.table, options.index).toOp(this.controlAdapterFor("dropIndex"));
1138
1298
  }
1139
1299
  recreateTable(options) {
1300
+ const { copyExpressions, temporaryValues, ...args } = options;
1140
1301
  return new RecreateTableCall({
1141
- ...options,
1302
+ ...args,
1142
1303
  contractTable: {
1143
1304
  ...options.contractTable,
1144
1305
  columns: options.contractTable.columns.map((column) => columnSpecOf(column, "recreateTable", options.tableName))
1145
- }
1306
+ },
1307
+ ...ifDefined("copyExpressions", copyExpressions === void 0 ? void 0 : copyExpressionSlotsOf(copyExpressions, options.tableName)),
1308
+ ...ifDefined("temporaryValues", temporaryValues === void 0 ? void 0 : copyExpressionSlotsOf(temporaryValues, options.tableName, "temporaryValues"))
1146
1309
  }).toOp(this.controlAdapterFor("recreateTable"));
1147
1310
  }
1148
1311
  };
@@ -1160,7 +1323,13 @@ function columnSpecOf(column, operation, table) {
1160
1323
  ...ifDefined("default", columnDefault === void 0 ? void 0 : columnDefaultOf(columnDefault, what))
1161
1324
  };
1162
1325
  }
1326
+ function copyExpressionSlotsOf(copyExpressions, table, option = "copyExpressions") {
1327
+ return Object.fromEntries(Object.entries(copyExpressions).map(([column, expression]) => [column, {
1328
+ kind: "sql",
1329
+ sql: sqlTextOf(expression, `recreateTable ${JSON.stringify(table)} ${option}.${column}`)
1330
+ }]));
1331
+ }
1163
1332
  //#endregion
1164
1333
  export { sqliteSchemaTables as _, createWorkingSchema as a, verifySqliteDatabaseSchema as b, issueNode as c, renameTableByHandStatements as d, renderRenameTableCall as f, sqlitePlannerStrategies as g, sqliteContractToSchema as h, conflictForDisallowedCall as i, pairIndexReplacements as l, sqliteColumnRenameCall as m, buildSqlitePlanDiff as n, diffSqliteSchema as o, sqliteActualSchema as p, coalesceSubtreeIssues as r, indexNameCaseChange as s, SqliteMigration as t, planIssues as u, sqliteTableRenameByHand as v, sqliteTableRenameCall as y };
1165
1334
 
1166
- //# sourceMappingURL=sqlite-migration-D7DWt0JL-D_5jFkOx.mjs.map
1335
+ //# sourceMappingURL=sqlite-migration-CTNkjYJ1-eRdmsbpK.mjs.map