@prisma-next/target-sqlite 0.13.0-dev.3 → 0.13.0-dev.30

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 (67) hide show
  1. package/dist/contract-free.mjs +1 -20
  2. package/dist/contract-free.mjs.map +1 -1
  3. package/dist/control.d.mts +5 -8
  4. package/dist/control.d.mts.map +1 -1
  5. package/dist/control.mjs +17 -19
  6. package/dist/control.mjs.map +1 -1
  7. package/dist/ddl-CH8V_qcd.mjs +23 -0
  8. package/dist/ddl-CH8V_qcd.mjs.map +1 -0
  9. package/dist/migration.d.mts +3 -3
  10. package/dist/migration.d.mts.map +1 -1
  11. package/dist/migration.mjs +4 -3
  12. package/dist/migration.mjs.map +1 -1
  13. package/dist/{tables-CjB7vXCr.mjs → op-factory-call-z4TT72k3.mjs} +375 -32
  14. package/dist/op-factory-call-z4TT72k3.mjs.map +1 -0
  15. package/dist/op-factory-call.d.mts +16 -12
  16. package/dist/op-factory-call.d.mts.map +1 -1
  17. package/dist/op-factory-call.mjs +1 -1
  18. package/dist/{planner-DSNDwQy9.mjs → planner-jMHqfl1A.mjs} +80 -12
  19. package/dist/planner-jMHqfl1A.mjs.map +1 -0
  20. package/dist/{planner-produced-sqlite-migration-C1yqJAiM.d.mts → planner-produced-sqlite-migration-BWpnDmhM.d.mts} +5 -4
  21. package/dist/planner-produced-sqlite-migration-BWpnDmhM.d.mts.map +1 -0
  22. package/dist/{planner-produced-sqlite-migration-DowV_vHw.mjs → planner-produced-sqlite-migration-CyyvoPmm.mjs} +9 -5
  23. package/dist/planner-produced-sqlite-migration-CyyvoPmm.mjs.map +1 -0
  24. package/dist/planner-produced-sqlite-migration.d.mts +1 -1
  25. package/dist/planner-produced-sqlite-migration.mjs +1 -1
  26. package/dist/planner.d.mts +5 -2
  27. package/dist/planner.d.mts.map +1 -1
  28. package/dist/planner.mjs +1 -1
  29. package/dist/render-ops-BDW2tUeR.mjs +22 -0
  30. package/dist/render-ops-BDW2tUeR.mjs.map +1 -0
  31. package/dist/render-ops.d.mts +2 -1
  32. package/dist/render-ops.d.mts.map +1 -1
  33. package/dist/render-ops.mjs +1 -1
  34. package/dist/runtime.mjs +1 -1
  35. package/dist/{sqlite-contract-serializer-jcRu8aHh.mjs → sqlite-contract-serializer-B_Cu0o3G.mjs} +20 -4
  36. package/dist/sqlite-contract-serializer-B_Cu0o3G.mjs.map +1 -0
  37. package/dist/sqlite-migration-CJrASAxf.d.mts +46 -0
  38. package/dist/sqlite-migration-CJrASAxf.d.mts.map +1 -0
  39. package/dist/sqlite-migration-DhW4ycZV.mjs +73 -0
  40. package/dist/sqlite-migration-DhW4ycZV.mjs.map +1 -0
  41. package/package.json +18 -18
  42. package/src/core/control-target.ts +4 -4
  43. package/src/core/errors.ts +28 -0
  44. package/src/core/migrations/issue-planner.ts +151 -8
  45. package/src/core/migrations/op-factory-call.ts +162 -23
  46. package/src/core/migrations/planner-ddl-builders.ts +7 -16
  47. package/src/core/migrations/planner-produced-sqlite-migration.ts +8 -2
  48. package/src/core/migrations/planner-strategies.ts +3 -3
  49. package/src/core/migrations/planner.ts +14 -2
  50. package/src/core/migrations/render-ops.ts +37 -9
  51. package/src/core/migrations/runner.ts +16 -12
  52. package/src/core/migrations/sqlite-migration.ts +51 -1
  53. package/src/core/sqlite-unbound-database.ts +34 -51
  54. package/src/exports/migration.ts +9 -1
  55. package/dist/op-factory-call-DymqdXQW.mjs +0 -279
  56. package/dist/op-factory-call-DymqdXQW.mjs.map +0 -1
  57. package/dist/planner-DSNDwQy9.mjs.map +0 -1
  58. package/dist/planner-produced-sqlite-migration-C1yqJAiM.d.mts.map +0 -1
  59. package/dist/planner-produced-sqlite-migration-DowV_vHw.mjs.map +0 -1
  60. package/dist/render-ops-CFRbJ3Yb.mjs +0 -8
  61. package/dist/render-ops-CFRbJ3Yb.mjs.map +0 -1
  62. package/dist/sqlite-contract-serializer-jcRu8aHh.mjs.map +0 -1
  63. package/dist/sqlite-migration-CUqgmzQH.mjs +0 -16
  64. package/dist/sqlite-migration-CUqgmzQH.mjs.map +0 -1
  65. package/dist/sqlite-migration-D4XGYzgQ.d.mts +0 -17
  66. package/dist/sqlite-migration-D4XGYzgQ.d.mts.map +0 -1
  67. package/dist/tables-CjB7vXCr.mjs.map +0 -1
@@ -1,5 +1,5 @@
1
1
  import { a as SQLITE_JSON_CODEC_ID, i as SQLITE_INTEGER_CODEC_ID, r as SQLITE_DATETIME_CODEC_ID, s as SQLITE_TEXT_CODEC_ID } from "./codec-ids-DSU7S2Li.mjs";
2
- import { t as SqliteCreateTable } from "./nodes-D0k4z7NL.mjs";
2
+ import { t as createTable } from "./ddl-CH8V_qcd.mjs";
3
3
  import { TableSource } from "@prisma-next/sql-relational-core/ast";
4
4
  import { APP_SPACE_ID } from "@prisma-next/framework-components/control";
5
5
  import { col, fn, lit, table } from "@prisma-next/sql-relational-core/contract-free";
@@ -28,25 +28,6 @@ function sqliteTable(name, columns) {
28
28
  return table(TableSource.named(name), columns);
29
29
  }
30
30
  //#endregion
31
- //#region src/contract-free/ddl.ts
32
- /**
33
- * Build a SQLite `CREATE TABLE` query node.
34
- *
35
- * Pass `constraints` for table-level composite primary keys, foreign keys, and
36
- * unique constraints — use the {@link PrimaryKeyConstraint}, {@link ForeignKeyConstraint},
37
- * and {@link UniqueConstraint} classes from `@prisma-next/sql-relational-core/ast`.
38
- *
39
- * Precondition: identifiers (`table`, column names/types) are emitted to SQL
40
- * verbatim — they are not quoted or escaped, so callers must pass pre-trusted
41
- * values (e.g. fixed control-plane identifiers). String-literal default values,
42
- * by contrast, are single-quote-escaped (embedded `'` doubled) by the renderer.
43
- * Identifier quoting for untrusted identifiers is added when the migration
44
- * planner adopts this lowering path.
45
- */
46
- function createTable(options) {
47
- return new SqliteCreateTable(options);
48
- }
49
- //#endregion
50
31
  //#region src/contract-free/control-bootstrap.ts
51
32
  const markerColumns = [
52
33
  col("space", "TEXT", {
@@ -1 +1 @@
1
- {"version":3,"file":"contract-free.mjs","names":[],"sources":["../src/contract-free/columns.ts","../src/contract-free/ddl.ts","../src/contract-free/control-bootstrap.ts"],"sourcesContent":["import { TableSource } from '@prisma-next/sql-relational-core/ast';\nimport {\n type ColumnDescriptor,\n type ColumnSchema,\n type TableHandle,\n table,\n} from '@prisma-next/sql-relational-core/contract-free';\nimport {\n SQLITE_DATETIME_CODEC_ID,\n SQLITE_INTEGER_CODEC_ID,\n SQLITE_JSON_CODEC_ID,\n SQLITE_TEXT_CODEC_ID,\n} from '../core/codec-ids';\n\ntype ColOpts = { readonly nullable?: boolean };\n\nconst desc = (codecId: string, opts?: ColOpts): ColumnDescriptor => ({\n codecId,\n nullable: opts?.nullable ?? false,\n});\n\nexport const text = (opts?: ColOpts): ColumnDescriptor => desc(SQLITE_TEXT_CODEC_ID, opts);\nexport const integer = (opts?: ColOpts): ColumnDescriptor => desc(SQLITE_INTEGER_CODEC_ID, opts);\nexport const jsonText = (opts?: ColOpts): ColumnDescriptor => desc(SQLITE_JSON_CODEC_ID, opts);\nexport const datetime = (opts?: ColOpts): ColumnDescriptor => desc(SQLITE_DATETIME_CODEC_ID, opts);\n\n/**\n * Declare a SQLite control-plane table with a typed column schema. SQLite tables\n * are addressed by a flat name (no schema prefix).\n *\n * ```ts\n * const marker = sqliteTable('_prisma_marker', {\n * space: text(),\n * core_hash: text(),\n * updated_at: datetime(),\n * });\n * ```\n */\nexport function sqliteTable<Schema extends ColumnSchema>(\n name: string,\n columns: Schema,\n): TableHandle<Schema> {\n return table(TableSource.named(name), columns);\n}\n","import type { DdlColumn, DdlTableConstraint } from '@prisma-next/sql-relational-core/ast';\nimport { SqliteCreateTable } from '../core/ddl/nodes';\n\n/**\n * Build a SQLite `CREATE TABLE` query node.\n *\n * Pass `constraints` for table-level composite primary keys, foreign keys, and\n * unique constraints — use the {@link PrimaryKeyConstraint}, {@link ForeignKeyConstraint},\n * and {@link UniqueConstraint} classes from `@prisma-next/sql-relational-core/ast`.\n *\n * Precondition: identifiers (`table`, column names/types) are emitted to SQL\n * verbatim — they are not quoted or escaped, so callers must pass pre-trusted\n * values (e.g. fixed control-plane identifiers). String-literal default values,\n * by contrast, are single-quote-escaped (embedded `'` doubled) by the renderer.\n * Identifier quoting for untrusted identifiers is added when the migration\n * planner adopts this lowering path.\n */\nexport function createTable(options: {\n readonly table: string;\n readonly schema?: string;\n readonly ifNotExists?: boolean;\n readonly columns: readonly DdlColumn[];\n readonly constraints?: readonly DdlTableConstraint[];\n}): SqliteCreateTable {\n return new SqliteCreateTable(options);\n}\n","import { APP_SPACE_ID } from '@prisma-next/framework-components/control';\nimport type { DdlNode } from '@prisma-next/sql-relational-core/ast';\nimport { col, fn, lit } from '@prisma-next/sql-relational-core/contract-free';\nimport { createTable } from './ddl';\n\nconst markerColumns = [\n col('space', 'TEXT', { notNull: true, primaryKey: true, default: lit(APP_SPACE_ID) }),\n col('core_hash', 'TEXT', { notNull: true }),\n col('profile_hash', 'TEXT', { notNull: true }),\n col('contract_json', 'TEXT'),\n col('canonical_version', 'INTEGER'),\n col('updated_at', 'TEXT', { notNull: true, default: fn(\"datetime('now')\") }),\n col('app_tag', 'TEXT'),\n col('meta', 'TEXT', { notNull: true, default: lit('{}') }),\n col('invariants', 'TEXT', { notNull: true, default: lit('[]') }),\n] as const;\n\nconst ledgerColumns = [\n col('id', 'INTEGER PRIMARY KEY AUTOINCREMENT'),\n col('created_at', 'TEXT', {\n notNull: true,\n default: fn(\"strftime('%Y-%m-%dT%H:%M:%fZ','now')\"),\n }),\n col('space', 'TEXT', { notNull: true }),\n col('migration_name', 'TEXT', { notNull: true }),\n col('migration_hash', 'TEXT', { notNull: true }),\n col('origin_core_hash', 'TEXT'),\n col('origin_profile_hash', 'TEXT'),\n col('destination_core_hash', 'TEXT', { notNull: true }),\n col('destination_profile_hash', 'TEXT'),\n col('contract_json_before', 'TEXT'),\n col('contract_json_after', 'TEXT'),\n col('operations', 'TEXT', { notNull: true }),\n] as const;\n\nconst markerTable = createTable({\n table: '_prisma_marker',\n ifNotExists: true,\n columns: markerColumns,\n});\n\nconst ledgerTable = createTable({\n table: '_prisma_ledger',\n ifNotExists: true,\n columns: ledgerColumns,\n});\n\nexport function buildSignMarkerBootstrapQueries(): readonly DdlNode[] {\n return [markerTable];\n}\n\nexport function buildControlTableBootstrapQueries(): readonly DdlNode[] {\n return [markerTable, ledgerTable];\n}\n"],"mappings":";;;;;;AAgBA,MAAM,QAAQ,SAAiB,UAAsC;CACnE;CACA,UAAU,MAAM,YAAY;AAC9B;AAEA,MAAa,QAAQ,SAAqC,KAAK,sBAAsB,IAAI;AACzF,MAAa,WAAW,SAAqC,KAAK,yBAAyB,IAAI;AAC/F,MAAa,YAAY,SAAqC,KAAK,sBAAsB,IAAI;AAC7F,MAAa,YAAY,SAAqC,KAAK,0BAA0B,IAAI;;;;;;;;;;;;;AAcjG,SAAgB,YACd,MACA,SACqB;CACrB,OAAO,MAAM,YAAY,MAAM,IAAI,GAAG,OAAO;AAC/C;;;;;;;;;;;;;;;;;AC1BA,SAAgB,YAAY,SAMN;CACpB,OAAO,IAAI,kBAAkB,OAAO;AACtC;;;ACpBA,MAAM,gBAAgB;CACpB,IAAI,SAAS,QAAQ;EAAE,SAAS;EAAM,YAAY;EAAM,SAAS,IAAI,YAAY;CAAE,CAAC;CACpF,IAAI,aAAa,QAAQ,EAAE,SAAS,KAAK,CAAC;CAC1C,IAAI,gBAAgB,QAAQ,EAAE,SAAS,KAAK,CAAC;CAC7C,IAAI,iBAAiB,MAAM;CAC3B,IAAI,qBAAqB,SAAS;CAClC,IAAI,cAAc,QAAQ;EAAE,SAAS;EAAM,SAAS,GAAG,iBAAiB;CAAE,CAAC;CAC3E,IAAI,WAAW,MAAM;CACrB,IAAI,QAAQ,QAAQ;EAAE,SAAS;EAAM,SAAS,IAAI,IAAI;CAAE,CAAC;CACzD,IAAI,cAAc,QAAQ;EAAE,SAAS;EAAM,SAAS,IAAI,IAAI;CAAE,CAAC;AACjE;AAEA,MAAM,gBAAgB;CACpB,IAAI,MAAM,mCAAmC;CAC7C,IAAI,cAAc,QAAQ;EACxB,SAAS;EACT,SAAS,GAAG,sCAAsC;CACpD,CAAC;CACD,IAAI,SAAS,QAAQ,EAAE,SAAS,KAAK,CAAC;CACtC,IAAI,kBAAkB,QAAQ,EAAE,SAAS,KAAK,CAAC;CAC/C,IAAI,kBAAkB,QAAQ,EAAE,SAAS,KAAK,CAAC;CAC/C,IAAI,oBAAoB,MAAM;CAC9B,IAAI,uBAAuB,MAAM;CACjC,IAAI,yBAAyB,QAAQ,EAAE,SAAS,KAAK,CAAC;CACtD,IAAI,4BAA4B,MAAM;CACtC,IAAI,wBAAwB,MAAM;CAClC,IAAI,uBAAuB,MAAM;CACjC,IAAI,cAAc,QAAQ,EAAE,SAAS,KAAK,CAAC;AAC7C;AAEA,MAAM,cAAc,YAAY;CAC9B,OAAO;CACP,aAAa;CACb,SAAS;AACX,CAAC;AAED,MAAM,cAAc,YAAY;CAC9B,OAAO;CACP,aAAa;CACb,SAAS;AACX,CAAC;AAED,SAAgB,kCAAsD;CACpE,OAAO,CAAC,WAAW;AACrB;AAEA,SAAgB,oCAAwD;CACtE,OAAO,CAAC,aAAa,WAAW;AAClC"}
1
+ {"version":3,"file":"contract-free.mjs","names":[],"sources":["../src/contract-free/columns.ts","../src/contract-free/control-bootstrap.ts"],"sourcesContent":["import { TableSource } from '@prisma-next/sql-relational-core/ast';\nimport {\n type ColumnDescriptor,\n type ColumnSchema,\n type TableHandle,\n table,\n} from '@prisma-next/sql-relational-core/contract-free';\nimport {\n SQLITE_DATETIME_CODEC_ID,\n SQLITE_INTEGER_CODEC_ID,\n SQLITE_JSON_CODEC_ID,\n SQLITE_TEXT_CODEC_ID,\n} from '../core/codec-ids';\n\ntype ColOpts = { readonly nullable?: boolean };\n\nconst desc = (codecId: string, opts?: ColOpts): ColumnDescriptor => ({\n codecId,\n nullable: opts?.nullable ?? false,\n});\n\nexport const text = (opts?: ColOpts): ColumnDescriptor => desc(SQLITE_TEXT_CODEC_ID, opts);\nexport const integer = (opts?: ColOpts): ColumnDescriptor => desc(SQLITE_INTEGER_CODEC_ID, opts);\nexport const jsonText = (opts?: ColOpts): ColumnDescriptor => desc(SQLITE_JSON_CODEC_ID, opts);\nexport const datetime = (opts?: ColOpts): ColumnDescriptor => desc(SQLITE_DATETIME_CODEC_ID, opts);\n\n/**\n * Declare a SQLite control-plane table with a typed column schema. SQLite tables\n * are addressed by a flat name (no schema prefix).\n *\n * ```ts\n * const marker = sqliteTable('_prisma_marker', {\n * space: text(),\n * core_hash: text(),\n * updated_at: datetime(),\n * });\n * ```\n */\nexport function sqliteTable<Schema extends ColumnSchema>(\n name: string,\n columns: Schema,\n): TableHandle<Schema> {\n return table(TableSource.named(name), columns);\n}\n","import { APP_SPACE_ID } from '@prisma-next/framework-components/control';\nimport type { DdlNode } from '@prisma-next/sql-relational-core/ast';\nimport { col, fn, lit } from '@prisma-next/sql-relational-core/contract-free';\nimport { createTable } from './ddl';\n\nconst markerColumns = [\n col('space', 'TEXT', { notNull: true, primaryKey: true, default: lit(APP_SPACE_ID) }),\n col('core_hash', 'TEXT', { notNull: true }),\n col('profile_hash', 'TEXT', { notNull: true }),\n col('contract_json', 'TEXT'),\n col('canonical_version', 'INTEGER'),\n col('updated_at', 'TEXT', { notNull: true, default: fn(\"datetime('now')\") }),\n col('app_tag', 'TEXT'),\n col('meta', 'TEXT', { notNull: true, default: lit('{}') }),\n col('invariants', 'TEXT', { notNull: true, default: lit('[]') }),\n] as const;\n\nconst ledgerColumns = [\n col('id', 'INTEGER PRIMARY KEY AUTOINCREMENT'),\n col('created_at', 'TEXT', {\n notNull: true,\n default: fn(\"strftime('%Y-%m-%dT%H:%M:%fZ','now')\"),\n }),\n col('space', 'TEXT', { notNull: true }),\n col('migration_name', 'TEXT', { notNull: true }),\n col('migration_hash', 'TEXT', { notNull: true }),\n col('origin_core_hash', 'TEXT'),\n col('origin_profile_hash', 'TEXT'),\n col('destination_core_hash', 'TEXT', { notNull: true }),\n col('destination_profile_hash', 'TEXT'),\n col('contract_json_before', 'TEXT'),\n col('contract_json_after', 'TEXT'),\n col('operations', 'TEXT', { notNull: true }),\n] as const;\n\nconst markerTable = createTable({\n table: '_prisma_marker',\n ifNotExists: true,\n columns: markerColumns,\n});\n\nconst ledgerTable = createTable({\n table: '_prisma_ledger',\n ifNotExists: true,\n columns: ledgerColumns,\n});\n\nexport function buildSignMarkerBootstrapQueries(): readonly DdlNode[] {\n return [markerTable];\n}\n\nexport function buildControlTableBootstrapQueries(): readonly DdlNode[] {\n return [markerTable, ledgerTable];\n}\n"],"mappings":";;;;;;AAgBA,MAAM,QAAQ,SAAiB,UAAsC;CACnE;CACA,UAAU,MAAM,YAAY;AAC9B;AAEA,MAAa,QAAQ,SAAqC,KAAK,sBAAsB,IAAI;AACzF,MAAa,WAAW,SAAqC,KAAK,yBAAyB,IAAI;AAC/F,MAAa,YAAY,SAAqC,KAAK,sBAAsB,IAAI;AAC7F,MAAa,YAAY,SAAqC,KAAK,0BAA0B,IAAI;;;;;;;;;;;;;AAcjG,SAAgB,YACd,MACA,SACqB;CACrB,OAAO,MAAM,YAAY,MAAM,IAAI,GAAG,OAAO;AAC/C;;;ACtCA,MAAM,gBAAgB;CACpB,IAAI,SAAS,QAAQ;EAAE,SAAS;EAAM,YAAY;EAAM,SAAS,IAAI,YAAY;CAAE,CAAC;CACpF,IAAI,aAAa,QAAQ,EAAE,SAAS,KAAK,CAAC;CAC1C,IAAI,gBAAgB,QAAQ,EAAE,SAAS,KAAK,CAAC;CAC7C,IAAI,iBAAiB,MAAM;CAC3B,IAAI,qBAAqB,SAAS;CAClC,IAAI,cAAc,QAAQ;EAAE,SAAS;EAAM,SAAS,GAAG,iBAAiB;CAAE,CAAC;CAC3E,IAAI,WAAW,MAAM;CACrB,IAAI,QAAQ,QAAQ;EAAE,SAAS;EAAM,SAAS,IAAI,IAAI;CAAE,CAAC;CACzD,IAAI,cAAc,QAAQ;EAAE,SAAS;EAAM,SAAS,IAAI,IAAI;CAAE,CAAC;AACjE;AAEA,MAAM,gBAAgB;CACpB,IAAI,MAAM,mCAAmC;CAC7C,IAAI,cAAc,QAAQ;EACxB,SAAS;EACT,SAAS,GAAG,sCAAsC;CACpD,CAAC;CACD,IAAI,SAAS,QAAQ,EAAE,SAAS,KAAK,CAAC;CACtC,IAAI,kBAAkB,QAAQ,EAAE,SAAS,KAAK,CAAC;CAC/C,IAAI,kBAAkB,QAAQ,EAAE,SAAS,KAAK,CAAC;CAC/C,IAAI,oBAAoB,MAAM;CAC9B,IAAI,uBAAuB,MAAM;CACjC,IAAI,yBAAyB,QAAQ,EAAE,SAAS,KAAK,CAAC;CACtD,IAAI,4BAA4B,MAAM;CACtC,IAAI,wBAAwB,MAAM;CAClC,IAAI,uBAAuB,MAAM;CACjC,IAAI,cAAc,QAAQ,EAAE,SAAS,KAAK,CAAC;AAC7C;AAEA,MAAM,cAAc,YAAY;CAC9B,OAAO;CACP,aAAa;CACb,SAAS;AACX,CAAC;AAED,MAAM,cAAc,YAAY;CAC9B,OAAO;CACP,aAAa;CACb,SAAS;AACX,CAAC;AAED,SAAgB,kCAAsD;CACpE,OAAO,CAAC,WAAW;AACrB;AAEA,SAAgB,oCAAwD;CACtE,OAAO,CAAC,aAAa,WAAW;AAClC"}
@@ -1,7 +1,7 @@
1
1
  import { t as SqlitePlanTargetDetails } from "./planner-target-details-xR6UfIcz.mjs";
2
2
  import { SqlControlTargetDescriptor } from "@prisma-next/family-sql/control";
3
- import { SqlNamespaceTablesInput, StorageTable, StorageTableInput } from "@prisma-next/sql-contract/types";
4
- import { Namespace, NamespaceBase } from "@prisma-next/framework-components/ir";
3
+ import { SqlNamespaceEntries, SqlNamespaceTablesInput, StorageTable } from "@prisma-next/sql-contract/types";
4
+ import { NamespaceBase } from "@prisma-next/framework-components/ir";
5
5
 
6
6
  //#region src/core/control-target.d.ts
7
7
  declare const sqliteControlTargetDescriptor: SqlControlTargetDescriptor<'sqlite', SqlitePlanTargetDetails>;
@@ -9,9 +9,7 @@ declare const sqliteControlTargetDescriptor: SqlControlTargetDescriptor<'sqlite'
9
9
  //#region src/core/sqlite-unbound-database.d.ts
10
10
  type SqliteDatabaseInput = {
11
11
  readonly id: string;
12
- readonly entries: {
13
- readonly table: Readonly<Record<string, StorageTable | StorageTableInput>>;
14
- };
12
+ readonly entries: SqlNamespaceEntries;
15
13
  };
16
14
  /**
17
15
  * SQLite namespace concretion carrying table metadata under
@@ -21,10 +19,9 @@ type SqliteDatabaseInput = {
21
19
  declare class SqliteDatabase extends NamespaceBase {
22
20
  readonly kind: string;
23
21
  readonly id: string;
24
- readonly entries: Readonly<{
25
- readonly table: Readonly<Record<string, StorageTable>>;
26
- }>;
22
+ readonly entries: SqlNamespaceEntries;
27
23
  constructor(input: SqliteDatabaseInput);
24
+ get table(): Readonly<Record<string, StorageTable>>;
28
25
  qualifier(): string;
29
26
  qualifyTable(tableName: string): string;
30
27
  }
@@ -1 +1 @@
1
- {"version":3,"file":"control.d.mts","names":[],"sources":["../src/core/control-target.ts","../src/core/sqlite-unbound-database.ts"],"mappings":";;;;;;cAgCM,6BAAA,EAA+B,0BAA0B,WAAW,uBAAA;;;KCnB9D,mBAAA;EAAA,SACD,EAAA;EAAA,SACA,OAAA;IAAA,SACE,KAAA,EAAO,QAAA,CAAS,MAAA,SAAe,YAAA,GAAe,iBAAA;EAAA;AAAA;;;ADgBsC;;;cCQpF,cAAA,SAAuB,aAAA;EAAA,SACjB,IAAA;EAAA,SAER,EAAA;EAAA,SACA,OAAA,EAAS,QAAA;IAAA,SACP,KAAA,EAAO,QAAA,CAAS,MAAA,SAAe,YAAA;EAAA;cAG9B,KAAA,EAAO,mBAAA;EAsBnB,SAAA;EAIA,YAAA,CAAa,SAAA;AAAA;;;;;;;;;AA1D6D;AAwB5E;;;;;;;;cAwDa,qBAAA,SAA8B,cAAc;EAAA,gBACvC,QAAA,EAAU,qBAAA;EAAA,QAEnB,WAAA;AAAA;;;;;;;;;;;iBA+CO,qBAAA,CACd,KAAA,EAAO,uBAAA,GACN,cAAA,GAAiB,qBAAA"}
1
+ {"version":3,"file":"control.d.mts","names":[],"sources":["../src/core/control-target.ts","../src/core/sqlite-unbound-database.ts"],"mappings":";;;;;;cAgCM,6BAAA,EAA+B,0BAA0B,WAAW,uBAAA;;;KCnB9D,mBAAA;EAAA,SACD,EAAA;EAAA,SACA,OAAA,EAAS,mBAAmB;AAAA;ADF4C;;;;AAmBc;AAnBd,cCYtE,cAAA,SAAuB,aAAA;EAAA,SACjB,IAAA;EAAA,SAER,EAAA;EAAA,SACA,OAAA,EAAS,mBAAA;cAEN,KAAA,EAAO,mBAAA;EAAA,IAiCf,KAAA,IAAS,QAAA,CAAS,MAAA,SAAe,YAAA;EAIrC,SAAA;EAIA,YAAA,CAAa,SAAA;AAAA;;;AAzDwB;AAUvC;;;;;;;;;;;;;;cAqEa,qBAAA,SAA8B,cAAc;EAAA,gBACvC,QAAA,EAAU,qBAAA;EAAA,QAEnB,WAAA;AAAA;;;;;;;;;AAzBuB;AAsBhC;iBAmCgB,qBAAA,CACd,KAAA,EAAO,uBAAA,GACN,cAAA,GAAiB,qBAAA"}
package/dist/control.mjs CHANGED
@@ -2,14 +2,15 @@ import { t as sqliteTargetDescriptorMeta } from "./descriptor-meta-Dxx2A6PT.mjs"
2
2
  import { t as parseSqliteDefault } from "./default-normalizer-DuoHj9-O.mjs";
3
3
  import { t as normalizeSqliteNativeType } from "./native-type-normalizer-CiSyVmMP.mjs";
4
4
  import { r as MARKER_TABLE_NAME } from "./control-tables-7KwMyJ6i.mjs";
5
- import { d as renderDefaultLiteral } from "./tables-CjB7vXCr.mjs";
6
- import { n as createSqliteMigrationPlanner } from "./planner-DSNDwQy9.mjs";
7
- import { n as SqliteUnboundDatabase, r as sqliteCreateNamespace, t as SqliteContractSerializer } from "./sqlite-contract-serializer-jcRu8aHh.mjs";
5
+ import { y as renderDefaultLiteral } from "./op-factory-call-z4TT72k3.mjs";
6
+ import { n as createSqliteMigrationPlanner } from "./planner-jMHqfl1A.mjs";
7
+ import { n as SqliteUnboundDatabase, r as sqliteCreateNamespace, t as SqliteContractSerializer } from "./sqlite-contract-serializer-B_Cu0o3G.mjs";
8
8
  import { contractToSchemaIR, runnerFailure, runnerSuccess } from "@prisma-next/family-sql/control";
9
9
  import { SqlStorage } from "@prisma-next/sql-contract/types";
10
10
  import { verifySqlSchema } from "@prisma-next/family-sql/schema-verify";
11
- import { notOk, ok, okVoid } from "@prisma-next/utils/result";
11
+ import { blindCast } from "@prisma-next/utils/casts";
12
12
  import { ifDefined } from "@prisma-next/utils/defined";
13
+ import { notOk, ok, okVoid } from "@prisma-next/utils/result";
13
14
  import { APP_SPACE_ID } from "@prisma-next/framework-components/control";
14
15
  import { SqlSchemaVerifierBase } from "@prisma-next/family-sql/ir";
15
16
  //#region src/core/migrations/runner.ts
@@ -31,9 +32,10 @@ var SqliteMigrationRunner = class {
31
32
  const driver = options.driver;
32
33
  if (options.space !== void 0 && options.space !== options.plan.spaceId) throw new Error(`SqlMigrationRunner: options.space (${options.space}) does not match plan.spaceId (${options.plan.spaceId})`);
33
34
  const space = options.plan.spaceId;
35
+ const planOps = blindCast(await Promise.all(options.plan.operations));
34
36
  const destinationCheck = this.ensurePlanMatchesDestinationContract(options.plan.destination, options.destinationContract);
35
37
  if (!destinationCheck.ok) return destinationCheck;
36
- const policyCheck = this.enforcePolicyCompatibility(options.policy, options.plan.operations);
38
+ const policyCheck = this.enforcePolicyCompatibility(options.policy, planOps);
37
39
  if (!policyCheck.ok) return policyCheck;
38
40
  const ensureResult = await this.ensureControlTables(driver, options.destinationContract);
39
41
  if (!ensureResult.ok) return ensureResult;
@@ -52,7 +54,7 @@ var SqliteMigrationRunner = class {
52
54
  operationsExecuted = 0;
53
55
  executedOperations = [];
54
56
  } else {
55
- const applyResult = await this.applyPlan(driver, options);
57
+ const applyResult = await this.applyPlan(driver, options, planOps);
56
58
  if (!applyResult.ok) return applyResult;
57
59
  operationsExecuted = applyResult.value.operationsExecuted;
58
60
  executedOperations = applyResult.value.executedOperations;
@@ -86,7 +88,7 @@ var SqliteMigrationRunner = class {
86
88
  await this.recordLedgerEntries(driver, options, executedOperations);
87
89
  }
88
90
  return runnerSuccess({
89
- operationsPlanned: options.plan.operations.length,
91
+ operationsPlanned: planOps.length,
90
92
  operationsExecuted
91
93
  });
92
94
  }
@@ -147,14 +149,14 @@ var SqliteMigrationRunner = class {
147
149
  meta: { violations: result.rows }
148
150
  });
149
151
  }
150
- async applyPlan(driver, options) {
152
+ async applyPlan(driver, options, ops) {
151
153
  const checks = options.executionChecks;
152
154
  const runPrechecks = checks?.prechecks !== false;
153
155
  const runPostchecks = checks?.postchecks !== false;
154
156
  const runIdempotency = checks?.idempotencyChecks !== false;
155
157
  let operationsExecuted = 0;
156
158
  const executedOperations = [];
157
- for (const operation of options.plan.operations) {
159
+ for (const operation of ops) {
158
160
  options.callbacks?.onOperationStart?.(operation);
159
161
  try {
160
162
  if (runPostchecks && runIdempotency) {
@@ -188,7 +190,7 @@ var SqliteMigrationRunner = class {
188
190
  const legacyDetection = await this.detectLegacyMarkerShape(driver);
189
191
  if (!legacyDetection.ok) return legacyDetection;
190
192
  const lowererContext = { contract };
191
- for (const query of this.family.bootstrapControlTableQueries()) await this.executeStatement(driver, this.family.lowerAst(query, lowererContext));
193
+ for (const query of this.family.bootstrapControlTableQueries()) await this.executeStatement(driver, await this.family.lowerAst(query, lowererContext));
192
194
  return okVoid();
193
195
  }
194
196
  async detectLegacyMarkerShape(driver) {
@@ -372,11 +374,7 @@ var SqliteMigrationRunner = class {
372
374
  await driver.query("ROLLBACK");
373
375
  }
374
376
  async executeStatement(driver, statement) {
375
- if (statement.params.length > 0) {
376
- await driver.query(statement.sql, statement.params);
377
- return;
378
- }
379
- await driver.query(statement.sql);
377
+ await driver.query(statement.sql, statement.params);
380
378
  }
381
379
  };
382
380
  //#endregion
@@ -411,8 +409,8 @@ const sqliteControlTargetDescriptor = {
411
409
  contractSerializer: new SqliteContractSerializer(),
412
410
  schemaVerifier: new SqliteSchemaVerifier(),
413
411
  migrations: {
414
- createPlanner(_adapter) {
415
- return createSqliteMigrationPlanner();
412
+ createPlanner(adapter) {
413
+ return createSqliteMigrationPlanner(adapter);
416
414
  },
417
415
  createRunner(family) {
418
416
  return createSqliteMigrationRunner(family);
@@ -431,8 +429,8 @@ const sqliteControlTargetDescriptor = {
431
429
  targetId: "sqlite"
432
430
  };
433
431
  },
434
- createPlanner(_adapter) {
435
- return createSqliteMigrationPlanner();
432
+ createPlanner(adapter) {
433
+ return createSqliteMigrationPlanner(adapter);
436
434
  },
437
435
  createRunner(family) {
438
436
  return createSqliteMigrationRunner(family);
@@ -1 +1 @@
1
- {"version":3,"file":"control.mjs","names":[],"sources":["../src/core/migrations/runner.ts","../src/core/sqlite-schema-verifier.ts","../src/core/control-target.ts"],"sourcesContent":["import type { Contract, ContractMarkerRecord } from '@prisma-next/contract/types';\nimport type {\n MigrationOperationPolicy,\n SqlControlFamilyInstance,\n SqlMigrationPlanContractInfo,\n SqlMigrationPlanOperation,\n SqlMigrationPlanOperationStep,\n SqlMigrationRunner,\n SqlMigrationRunnerExecuteOptions,\n SqlMigrationRunnerFailure,\n SqlMigrationRunnerResult,\n SqlMigrationRunnerSuccessValue,\n} from '@prisma-next/family-sql/control';\nimport { runnerFailure, runnerSuccess } from '@prisma-next/family-sql/control';\nimport { verifySqlSchema } from '@prisma-next/family-sql/schema-verify';\nimport type { MigrationRunnerResult } from '@prisma-next/framework-components/control';\nimport { APP_SPACE_ID } from '@prisma-next/framework-components/control';\nimport type { SqlControlDriverInstance, SqlStorage } from '@prisma-next/sql-contract/types';\nimport type { LoweredStatement } from '@prisma-next/sql-relational-core/ast';\nimport { ifDefined } from '@prisma-next/utils/defined';\nimport type { Result } from '@prisma-next/utils/result';\nimport { notOk, ok, okVoid } from '@prisma-next/utils/result';\nimport { MARKER_TABLE_NAME } from '../control-tables';\nimport { parseSqliteDefault } from '../default-normalizer';\nimport { normalizeSqliteNativeType } from '../native-type-normalizer';\nimport type { SqlitePlanTargetDetails } from './planner-target-details';\n\nexport function createSqliteMigrationRunner(\n family: SqlControlFamilyInstance,\n): SqlMigrationRunner<SqlitePlanTargetDetails> {\n return new SqliteMigrationRunner(family);\n}\n\nclass SqliteMigrationRunner implements SqlMigrationRunner<SqlitePlanTargetDetails> {\n constructor(private readonly family: SqlControlFamilyInstance) {}\n\n /**\n * Apply the plan against an already-open connection without managing\n * the transaction lifecycle. The caller ({@link SqliteMigrationRunner.execute})\n * owns BEGIN/COMMIT/ROLLBACK and any connection-level setup (FK pragma\n * toggle, FK integrity check).\n */\n async executeOnConnection(\n options: SqlMigrationRunnerExecuteOptions<SqlitePlanTargetDetails>,\n ): Promise<SqlMigrationRunnerResult> {\n const driver = options.driver;\n if (options.space !== undefined && options.space !== options.plan.spaceId) {\n throw new Error(\n `SqlMigrationRunner: options.space (${options.space}) does not match plan.spaceId (${options.plan.spaceId})`,\n );\n }\n const space = options.plan.spaceId;\n\n const destinationCheck = this.ensurePlanMatchesDestinationContract(\n options.plan.destination,\n options.destinationContract,\n );\n if (!destinationCheck.ok) return destinationCheck;\n\n const policyCheck = this.enforcePolicyCompatibility(options.policy, options.plan.operations);\n if (!policyCheck.ok) return policyCheck;\n\n const ensureResult = await this.ensureControlTables(driver, options.destinationContract);\n if (!ensureResult.ok) return ensureResult;\n const existingMarker = await this.family.readMarker({ driver, space });\n\n const markerCheck = this.ensureMarkerCompatibility(existingMarker, options.plan);\n if (!markerCheck.ok) return markerCheck;\n\n const markerAtDestination = this.markerMatchesDestination(existingMarker, options.plan);\n const isSelfEdge = options.plan.origin?.storageHash === options.plan.destination.storageHash;\n const skipOperations = markerAtDestination && options.plan.origin != null && !isSelfEdge;\n\n let operationsExecuted: number;\n let executedOperations: readonly SqlMigrationPlanOperation<SqlitePlanTargetDetails>[];\n\n if (skipOperations) {\n operationsExecuted = 0;\n executedOperations = [];\n } else {\n const applyResult = await this.applyPlan(driver, options);\n if (!applyResult.ok) return applyResult;\n operationsExecuted = applyResult.value.operationsExecuted;\n executedOperations = applyResult.value.executedOperations;\n }\n\n if (space === APP_SPACE_ID) {\n const schemaIR = await this.family.introspect({\n driver,\n contract: options.destinationContract,\n });\n\n const schemaVerifyResult = verifySqlSchema({\n contract: options.destinationContract,\n schema: schemaIR,\n strict: options.strictVerification ?? true,\n context: options.context ?? {},\n typeMetadataRegistry: this.family.typeMetadataRegistry,\n frameworkComponents: options.frameworkComponents,\n normalizeDefault: parseSqliteDefault,\n normalizeNativeType: normalizeSqliteNativeType,\n });\n if (!schemaVerifyResult.ok) {\n return runnerFailure('SCHEMA_VERIFY_FAILED', schemaVerifyResult.summary, {\n why: 'The resulting database schema does not satisfy the destination contract.',\n meta: { issues: schemaVerifyResult.schema.issues },\n });\n }\n }\n\n // Self-edge no-op detection: see Postgres runner for the rationale\n // (kept symmetric across both targets).\n const incomingInvariants = options.plan.providedInvariants;\n const existingInvariants = new Set(existingMarker?.invariants ?? []);\n const incomingIsSubsetOfExisting = incomingInvariants.every((id) => existingInvariants.has(id));\n const isSelfEdgeNoOp = isSelfEdge && operationsExecuted === 0 && incomingIsSubsetOfExisting;\n\n if (!isSelfEdgeNoOp) {\n const markerResult = await this.upsertMarker(driver, options, existingMarker, space);\n if (!markerResult.ok) return markerResult;\n await this.recordLedgerEntries(driver, options, executedOperations);\n }\n\n return runnerSuccess({\n operationsPlanned: options.plan.operations.length,\n operationsExecuted,\n });\n }\n\n async execute(options: {\n readonly driver: SqlControlDriverInstance<string>;\n readonly perSpaceOptions: ReadonlyArray<\n SqlMigrationRunnerExecuteOptions<SqlitePlanTargetDetails>\n >;\n }): Promise<MigrationRunnerResult> {\n const driver = options.driver;\n const perSpaceOptions = options.perSpaceOptions;\n\n if (perSpaceOptions.length === 0) {\n return ok({ perSpaceResults: [] });\n }\n\n // FK pragma toggle and the FK integrity check both span the outer\n // transaction: PRAGMA foreign_keys is a no-op inside a transaction, so the\n // toggle has to wrap BEGIN/COMMIT.\n const fkWasEnabled = await this.readForeignKeysEnabled(driver);\n if (fkWasEnabled) {\n await driver.query('PRAGMA foreign_keys = OFF');\n }\n\n try {\n await this.beginExclusiveTransaction(driver);\n let committed = false;\n try {\n const perSpaceResults: Array<{\n space: string;\n value: SqlMigrationRunnerSuccessValue;\n }> = [];\n let lastProcessedSpace: string | undefined;\n for (const spaceOptions of perSpaceOptions) {\n const space = spaceOptions.space ?? spaceOptions.plan.spaceId;\n const result = await this.executeOnConnection({ ...spaceOptions, driver, space });\n if (!result.ok) {\n return notOk({ ...result.failure, failingSpace: space });\n }\n perSpaceResults.push({ space, value: result.value });\n lastProcessedSpace = space;\n }\n\n if (fkWasEnabled) {\n const fkIntegrityCheck = await this.verifyForeignKeyIntegrity(driver);\n if (!fkIntegrityCheck.ok) {\n // Post-loop integrity violations cannot be attributed to a\n // single per-space step (the cumulative effect of all\n // applied plans was needed to reveal the broken\n // reference). Surface the last successfully-applied space\n // so operators can investigate from the most recent\n // migration first.\n return notOk({\n ...fkIntegrityCheck.failure,\n failingSpace: lastProcessedSpace ?? APP_SPACE_ID,\n });\n }\n }\n\n await this.commitTransaction(driver);\n committed = true;\n return ok({ perSpaceResults });\n } finally {\n if (!committed) {\n await this.rollbackTransaction(driver);\n }\n }\n } finally {\n if (fkWasEnabled) {\n await driver.query('PRAGMA foreign_keys = ON');\n }\n }\n }\n\n private async readForeignKeysEnabled(\n driver: SqlMigrationRunnerExecuteOptions<SqlitePlanTargetDetails>['driver'],\n ): Promise<boolean> {\n const result = await driver.query<{ foreign_keys: number }>('PRAGMA foreign_keys');\n const row = result.rows[0];\n return row?.foreign_keys === 1;\n }\n\n private async verifyForeignKeyIntegrity(\n driver: SqlMigrationRunnerExecuteOptions<SqlitePlanTargetDetails>['driver'],\n ): Promise<Result<void, SqlMigrationRunnerFailure>> {\n const result = await driver.query<Record<string, unknown>>('PRAGMA foreign_key_check');\n if (result.rows.length === 0) {\n return okVoid();\n }\n return runnerFailure(\n 'FOREIGN_KEY_VIOLATION',\n `Foreign key integrity check failed after migration: ${result.rows.length} violation(s).`,\n {\n why: 'PRAGMA foreign_key_check reported violations after applying recreate-table operations.',\n meta: { violations: result.rows },\n },\n );\n }\n\n private async applyPlan(\n driver: SqlMigrationRunnerExecuteOptions<SqlitePlanTargetDetails>['driver'],\n options: SqlMigrationRunnerExecuteOptions<SqlitePlanTargetDetails>,\n ): Promise<\n Result<\n {\n readonly operationsExecuted: number;\n readonly executedOperations: readonly SqlMigrationPlanOperation<SqlitePlanTargetDetails>[];\n },\n SqlMigrationRunnerFailure\n >\n > {\n const checks = options.executionChecks;\n const runPrechecks = checks?.prechecks !== false;\n const runPostchecks = checks?.postchecks !== false;\n const runIdempotency = checks?.idempotencyChecks !== false;\n\n let operationsExecuted = 0;\n const executedOperations: Array<SqlMigrationPlanOperation<SqlitePlanTargetDetails>> = [];\n\n for (const operation of options.plan.operations) {\n options.callbacks?.onOperationStart?.(operation);\n try {\n if (runPostchecks && runIdempotency) {\n const postcheckAlreadySatisfied = await this.expectationsAreSatisfied(\n driver,\n operation.postcheck,\n );\n if (postcheckAlreadySatisfied) {\n executedOperations.push(this.createSkipRecord(operation));\n continue;\n }\n }\n\n if (runPrechecks) {\n const precheckResult = await this.runExpectationSteps(\n driver,\n operation.precheck,\n operation,\n 'precheck',\n );\n if (!precheckResult.ok) {\n return precheckResult;\n }\n }\n\n const executeResult = await this.runExecuteSteps(driver, operation.execute, operation);\n if (!executeResult.ok) {\n return executeResult;\n }\n\n if (runPostchecks) {\n const postcheckResult = await this.runExpectationSteps(\n driver,\n operation.postcheck,\n operation,\n 'postcheck',\n );\n if (!postcheckResult.ok) {\n return postcheckResult;\n }\n }\n\n executedOperations.push(operation);\n operationsExecuted += 1;\n } finally {\n options.callbacks?.onOperationComplete?.(operation);\n }\n }\n return ok({ operationsExecuted, executedOperations });\n }\n\n private async ensureControlTables(\n driver: SqlMigrationRunnerExecuteOptions<SqlitePlanTargetDetails>['driver'],\n contract: Contract<SqlStorage>,\n ): Promise<Result<void, SqlMigrationRunnerFailure>> {\n const legacyDetection = await this.detectLegacyMarkerShape(driver);\n if (!legacyDetection.ok) {\n return legacyDetection;\n }\n const lowererContext = { contract };\n for (const query of this.family.bootstrapControlTableQueries()) {\n await this.executeStatement(driver, this.family.lowerAst(query, lowererContext));\n }\n return okVoid();\n }\n\n private async detectLegacyMarkerShape(\n driver: SqlMigrationRunnerExecuteOptions<SqlitePlanTargetDetails>['driver'],\n ): Promise<Result<void, SqlMigrationRunnerFailure>> {\n const tableInfo = await driver.query<{ name: string }>(\n `PRAGMA table_info(\"${MARKER_TABLE_NAME}\")`,\n );\n if (tableInfo.rows.length === 0) {\n return okVoid();\n }\n const columns = new Set(tableInfo.rows.map((row) => row.name));\n if (columns.has('space')) {\n return okVoid();\n }\n return runnerFailure(\n 'LEGACY_MARKER_SHAPE',\n `Legacy marker-table shape detected on ${MARKER_TABLE_NAME} (no \\`space\\` column). ` +\n 'Prisma Next is in pre-1.0; the previous transitional auto-migration to the per-space-row schema has been removed. ' +\n `Drop \\`${MARKER_TABLE_NAME}\\` and re-run \\`dbInit\\` to reinitialise from a clean baseline.`,\n {\n meta: {\n table: MARKER_TABLE_NAME,\n columns: [...columns].sort(),\n },\n },\n );\n }\n\n private async runExpectationSteps(\n driver: SqlMigrationRunnerExecuteOptions<SqlitePlanTargetDetails>['driver'],\n steps: readonly SqlMigrationPlanOperationStep[],\n operation: SqlMigrationPlanOperation<SqlitePlanTargetDetails>,\n phase: 'precheck' | 'postcheck',\n ): Promise<Result<void, SqlMigrationRunnerFailure>> {\n for (const step of steps) {\n const result = await driver.query(step.sql, step.params ?? []);\n if (!this.stepResultIsTrue(result.rows)) {\n const code = phase === 'precheck' ? 'PRECHECK_FAILED' : 'POSTCHECK_FAILED';\n return runnerFailure(\n code,\n `Operation ${operation.id} failed during ${phase}: ${step.description}`,\n {\n meta: {\n operationId: operation.id,\n phase,\n stepDescription: step.description,\n },\n },\n );\n }\n }\n return okVoid();\n }\n\n private async runExecuteSteps(\n driver: SqlMigrationRunnerExecuteOptions<SqlitePlanTargetDetails>['driver'],\n steps: readonly SqlMigrationPlanOperationStep[],\n operation: SqlMigrationPlanOperation<SqlitePlanTargetDetails>,\n ): Promise<Result<void, SqlMigrationRunnerFailure>> {\n for (const step of steps) {\n try {\n await driver.query(step.sql, step.params ?? []);\n } catch (error: unknown) {\n const message = error instanceof Error ? error.message : String(error);\n return runnerFailure(\n 'EXECUTION_FAILED',\n `Operation ${operation.id} failed during execution: ${step.description}`,\n {\n why: message,\n meta: {\n operationId: operation.id,\n stepDescription: step.description,\n sql: step.sql,\n },\n },\n );\n }\n }\n return okVoid();\n }\n\n private stepResultIsTrue(rows: readonly Record<string, unknown>[]): boolean {\n if (!rows || rows.length === 0) {\n return false;\n }\n const firstRow = rows[0];\n const firstValue = firstRow ? Object.values(firstRow)[0] : undefined;\n if (typeof firstValue === 'number') {\n return firstValue !== 0;\n }\n if (typeof firstValue === 'boolean') {\n return firstValue;\n }\n if (typeof firstValue === 'string') {\n const lower = firstValue.toLowerCase();\n if (lower === 'true' || lower === '1') return true;\n if (lower === 'false' || lower === '0') return false;\n return firstValue.length > 0;\n }\n return Boolean(firstValue);\n }\n\n private async expectationsAreSatisfied(\n driver: SqlMigrationRunnerExecuteOptions<SqlitePlanTargetDetails>['driver'],\n steps: readonly SqlMigrationPlanOperationStep[],\n ): Promise<boolean> {\n if (steps.length === 0) {\n return false;\n }\n for (const step of steps) {\n const result = await driver.query(step.sql, step.params ?? []);\n if (!this.stepResultIsTrue(result.rows)) {\n return false;\n }\n }\n return true;\n }\n\n private createSkipRecord(\n operation: SqlMigrationPlanOperation<SqlitePlanTargetDetails>,\n ): SqlMigrationPlanOperation<SqlitePlanTargetDetails> {\n return Object.freeze({\n id: operation.id,\n label: operation.label,\n ...ifDefined('summary', operation.summary),\n operationClass: operation.operationClass,\n target: operation.target,\n precheck: Object.freeze([]),\n execute: Object.freeze([]),\n postcheck: Object.freeze([...operation.postcheck]),\n meta: Object.freeze({\n ...(operation.meta ?? {}),\n runner: Object.freeze({ skipped: true, reason: 'postcheck_pre_satisfied' }),\n }),\n });\n }\n\n private markerMatchesDestination(\n marker: ContractMarkerRecord | null,\n plan: SqlMigrationRunnerExecuteOptions<SqlitePlanTargetDetails>['plan'],\n ): boolean {\n if (!marker) return false;\n if (marker.storageHash !== plan.destination.storageHash) return false;\n if (plan.destination.profileHash && marker.profileHash !== plan.destination.profileHash) {\n return false;\n }\n return true;\n }\n\n private enforcePolicyCompatibility(\n policy: MigrationOperationPolicy,\n operations: readonly SqlMigrationPlanOperation<SqlitePlanTargetDetails>[],\n ): Result<void, SqlMigrationRunnerFailure> {\n const allowedClasses = new Set(policy.allowedOperationClasses);\n for (const operation of operations) {\n if (!allowedClasses.has(operation.operationClass)) {\n return runnerFailure(\n 'POLICY_VIOLATION',\n `Operation ${operation.id} has class \"${operation.operationClass}\" which is not allowed by policy.`,\n {\n why: `Policy only allows: ${policy.allowedOperationClasses.join(', ')}.`,\n meta: {\n operationId: operation.id,\n operationClass: operation.operationClass,\n allowedClasses: policy.allowedOperationClasses,\n },\n },\n );\n }\n }\n return okVoid();\n }\n\n private ensureMarkerCompatibility(\n marker: ContractMarkerRecord | null,\n plan: SqlMigrationRunnerExecuteOptions<SqlitePlanTargetDetails>['plan'],\n ): Result<void, SqlMigrationRunnerFailure> {\n const origin = plan.origin ?? null;\n if (!origin) {\n return okVoid();\n }\n if (!marker) {\n return runnerFailure(\n 'MARKER_ORIGIN_MISMATCH',\n `Missing contract marker: expected origin storage hash ${origin.storageHash}.`,\n { meta: { expectedOriginStorageHash: origin.storageHash } },\n );\n }\n if (marker.storageHash !== origin.storageHash) {\n return runnerFailure(\n 'MARKER_ORIGIN_MISMATCH',\n `Existing contract marker (${marker.storageHash}) does not match plan origin (${origin.storageHash}).`,\n {\n meta: {\n markerStorageHash: marker.storageHash,\n expectedOriginStorageHash: origin.storageHash,\n },\n },\n );\n }\n if (origin.profileHash && marker.profileHash !== origin.profileHash) {\n return runnerFailure(\n 'MARKER_ORIGIN_MISMATCH',\n `Existing contract marker profile hash (${marker.profileHash}) does not match plan origin profile hash (${origin.profileHash}).`,\n {\n meta: {\n markerProfileHash: marker.profileHash,\n expectedOriginProfileHash: origin.profileHash,\n },\n },\n );\n }\n return okVoid();\n }\n\n private ensurePlanMatchesDestinationContract(\n destination: SqlMigrationPlanContractInfo,\n contract: SqlMigrationRunnerExecuteOptions<SqlitePlanTargetDetails>['destinationContract'],\n ): Result<void, SqlMigrationRunnerFailure> {\n if (destination.storageHash !== contract.storage.storageHash) {\n return runnerFailure(\n 'DESTINATION_CONTRACT_MISMATCH',\n `Plan destination storage hash (${destination.storageHash}) does not match provided contract storage hash (${contract.storage.storageHash}).`,\n {\n meta: {\n planStorageHash: destination.storageHash,\n contractStorageHash: contract.storage.storageHash,\n },\n },\n );\n }\n if (\n destination.profileHash &&\n contract.profileHash &&\n destination.profileHash !== contract.profileHash\n ) {\n return runnerFailure(\n 'DESTINATION_CONTRACT_MISMATCH',\n `Plan destination profile hash (${destination.profileHash}) does not match provided contract profile hash (${contract.profileHash}).`,\n {\n meta: {\n planProfileHash: destination.profileHash,\n contractProfileHash: contract.profileHash,\n },\n },\n );\n }\n return okVoid();\n }\n\n private async upsertMarker(\n driver: SqlMigrationRunnerExecuteOptions<SqlitePlanTargetDetails>['driver'],\n options: SqlMigrationRunnerExecuteOptions<SqlitePlanTargetDetails>,\n existingMarker: ContractMarkerRecord | null,\n space: string,\n ): Promise<Result<void, SqlMigrationRunnerFailure>> {\n // Pass the plan's incoming invariants verbatim; `updateMarker` unions them\n // with the stored set (TS-side, dialect-uniform) under the runner's\n // BEGIN EXCLUSIVE — no client-side pre-merge here, so there is no\n // double-merge with the SPI's internal accumulate-dedupe.\n const destination = {\n storageHash: options.plan.destination.storageHash,\n profileHash:\n options.plan.destination.profileHash ??\n options.destinationContract.profileHash ??\n options.plan.destination.storageHash,\n invariants: options.plan.providedInvariants ?? [],\n };\n if (!existingMarker) {\n await this.family.initMarker({ driver, space, destination });\n return okVoid();\n }\n const updated = await this.family.updateMarker({\n driver,\n space,\n expectedFrom: existingMarker.storageHash,\n destination,\n });\n if (!updated) {\n return runnerFailure(\n 'MARKER_CAS_FAILURE',\n 'Marker was modified by another process during migration execution.',\n {\n meta: {\n space,\n expectedStorageHash: existingMarker.storageHash,\n destinationStorageHash: options.plan.destination.storageHash,\n },\n },\n );\n }\n return okVoid();\n }\n\n private async recordLedgerEntries(\n driver: SqlMigrationRunnerExecuteOptions<SqlitePlanTargetDetails>['driver'],\n options: SqlMigrationRunnerExecuteOptions<SqlitePlanTargetDetails>,\n executedOperations: readonly SqlMigrationPlanOperation<SqlitePlanTargetDetails>[],\n ): Promise<void> {\n const plan = options.plan;\n const space = plan.spaceId;\n const edges = options.migrationEdges;\n const totalEdgeOps = edges.reduce((sum, edge) => sum + edge.operationCount, 0);\n if (totalEdgeOps !== plan.operations.length) {\n throw new Error(\n `Ledger write: plan.operations length (${plan.operations.length}) does not match sum of migrationEdges operationCount (${totalEdgeOps})`,\n );\n }\n // The ledger records the operations as executed — idempotency-skipped ops\n // are substituted with skip records (empty `execute`) by `applyPlan`, so the\n // journal reflects what actually ran rather than the raw plan.\n let offset = 0;\n for (const edge of edges) {\n const edgeOps = executedOperations.slice(offset, offset + edge.operationCount);\n offset += edge.operationCount;\n await this.family.writeLedgerEntry({\n driver,\n space,\n entry: {\n edgeId: `${edge.from}->${edge.to}`,\n from: edge.from,\n to: edge.to,\n migrationName: edge.dirName,\n migrationHash: edge.migrationHash,\n operations: edgeOps,\n },\n });\n }\n }\n\n private async beginExclusiveTransaction(\n driver: SqlMigrationRunnerExecuteOptions<SqlitePlanTargetDetails>['driver'],\n ): Promise<void> {\n await driver.query('BEGIN EXCLUSIVE');\n }\n\n private async commitTransaction(\n driver: SqlMigrationRunnerExecuteOptions<SqlitePlanTargetDetails>['driver'],\n ): Promise<void> {\n await driver.query('COMMIT');\n }\n\n private async rollbackTransaction(\n driver: SqlMigrationRunnerExecuteOptions<SqlitePlanTargetDetails>['driver'],\n ): Promise<void> {\n await driver.query('ROLLBACK');\n }\n\n private async executeStatement(\n driver: SqlMigrationRunnerExecuteOptions<SqlitePlanTargetDetails>['driver'],\n statement: LoweredStatement,\n ): Promise<void> {\n if (statement.params.length > 0) {\n await driver.query(statement.sql, statement.params);\n return;\n }\n await driver.query(statement.sql);\n }\n}\n","import type { Contract } from '@prisma-next/contract/types';\nimport { SqlSchemaVerifierBase } from '@prisma-next/family-sql/ir';\nimport type { SchemaIssue, SchemaVerifyOptions } from '@prisma-next/framework-components/control';\nimport type { SqlStorage } from '@prisma-next/sql-contract/types';\nimport type { SqlSchemaIR } from '@prisma-next/sql-schema-ir/types';\n\n/**\n * SQLite target `SchemaVerifier` concretion. Mirrors the Postgres\n * shape: hooks return the empty list pending the call-site migration\n * that routes the existing verifier behaviour through the SPI.\n */\nexport class SqliteSchemaVerifier extends SqlSchemaVerifierBase<Contract<SqlStorage>, SqlSchemaIR> {\n protected verifyCommonSqlSchema(\n _options: SchemaVerifyOptions<Contract<SqlStorage>, SqlSchemaIR>,\n ): readonly SchemaIssue[] {\n return [];\n }\n\n protected verifyTargetExtensions(\n _options: SchemaVerifyOptions<Contract<SqlStorage>, SqlSchemaIR>,\n ): readonly SchemaIssue[] {\n return [];\n }\n}\n","import type { ColumnDefault, Contract } from '@prisma-next/contract/types';\nimport type { SqlControlTargetDescriptor } from '@prisma-next/family-sql/control';\nimport { contractToSchemaIR } from '@prisma-next/family-sql/control';\nimport type { SqlControlAdapter } from '@prisma-next/family-sql/control-adapter';\nimport type {\n ControlTargetInstance,\n MigrationPlanner,\n MigrationRunner,\n} from '@prisma-next/framework-components/control';\nimport { SqlStorage, type StorageColumn } from '@prisma-next/sql-contract/types';\nimport { sqliteTargetDescriptorMeta } from './descriptor-meta';\nimport { createSqliteMigrationPlanner } from './migrations/planner';\nimport { renderDefaultLiteral } from './migrations/planner-ddl-builders';\nimport type { SqlitePlanTargetDetails } from './migrations/planner-target-details';\nimport { createSqliteMigrationRunner } from './migrations/runner';\nimport { SqliteContractSerializer } from './sqlite-contract-serializer';\nimport { SqliteSchemaVerifier } from './sqlite-schema-verifier';\n\nfunction isSqlContract(contract: Contract | null): contract is Contract<SqlStorage> | null {\n return contract === null || contract.storage instanceof SqlStorage;\n}\n\nfunction sqliteRenderDefault(def: ColumnDefault, _column: StorageColumn): string {\n if (def.kind === 'function') {\n if (def.expression === 'now()') {\n return \"datetime('now')\";\n }\n return def.expression;\n }\n return renderDefaultLiteral(def.value);\n}\n\nconst sqliteControlTargetDescriptor: SqlControlTargetDescriptor<'sqlite', SqlitePlanTargetDetails> =\n {\n ...sqliteTargetDescriptorMeta,\n contractSerializer: new SqliteContractSerializer(),\n schemaVerifier: new SqliteSchemaVerifier(),\n migrations: {\n createPlanner(_adapter: SqlControlAdapter<'sqlite'>): MigrationPlanner<'sql', 'sqlite'> {\n return createSqliteMigrationPlanner();\n },\n createRunner(family) {\n return createSqliteMigrationRunner(family) as MigrationRunner<'sql', 'sqlite'>;\n },\n contractToSchema(contract, _frameworkComponents) {\n // The framework SPI types `contract` as the generic\n // `Contract | null`. Any contract reaching the sqlite\n // target descriptor is SQL-family by construction (the\n // family contract resolver would have refused to bind a\n // sqlite target otherwise); the `isSqlContract` predicate\n // encodes that invariant at runtime + narrows the generic\n // to `Contract<SqlStorage>` without a blind cast.\n if (!isSqlContract(contract)) {\n throw new Error(\n 'sqliteControlTargetDescriptor.contractToSchema received a non-SQL contract; expected Contract<SqlStorage>',\n );\n }\n return contractToSchemaIR(contract, {\n annotationNamespace: 'sqlite',\n renderDefault: sqliteRenderDefault,\n });\n },\n },\n create(): ControlTargetInstance<'sql', 'sqlite'> {\n return {\n familyId: 'sql',\n targetId: 'sqlite',\n };\n },\n createPlanner(_adapter: SqlControlAdapter<'sqlite'>) {\n return createSqliteMigrationPlanner();\n },\n createRunner(family) {\n return createSqliteMigrationRunner(family);\n },\n };\n\nexport default sqliteControlTargetDescriptor;\n"],"mappings":";;;;;;;;;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4BAA4B,MAAM;CAC3C;AACF"}
1
+ {"version":3,"file":"control.mjs","names":[],"sources":["../src/core/migrations/runner.ts","../src/core/sqlite-schema-verifier.ts","../src/core/control-target.ts"],"sourcesContent":["import type { Contract, ContractMarkerRecord } from '@prisma-next/contract/types';\nimport type {\n MigrationOperationPolicy,\n SqlControlFamilyInstance,\n SqlMigrationPlanContractInfo,\n SqlMigrationPlanOperation,\n SqlMigrationPlanOperationStep,\n SqlMigrationRunner,\n SqlMigrationRunnerExecuteOptions,\n SqlMigrationRunnerFailure,\n SqlMigrationRunnerResult,\n SqlMigrationRunnerSuccessValue,\n} from '@prisma-next/family-sql/control';\nimport { runnerFailure, runnerSuccess } from '@prisma-next/family-sql/control';\nimport { verifySqlSchema } from '@prisma-next/family-sql/schema-verify';\nimport type { MigrationRunnerResult } from '@prisma-next/framework-components/control';\nimport { APP_SPACE_ID } from '@prisma-next/framework-components/control';\nimport type { SqlControlDriverInstance, SqlStorage } from '@prisma-next/sql-contract/types';\nimport type { SqlExecuteRequest } from '@prisma-next/sql-relational-core/ast';\nimport { blindCast } from '@prisma-next/utils/casts';\nimport { ifDefined } from '@prisma-next/utils/defined';\nimport type { Result } from '@prisma-next/utils/result';\nimport { notOk, ok, okVoid } from '@prisma-next/utils/result';\nimport { MARKER_TABLE_NAME } from '../control-tables';\nimport { parseSqliteDefault } from '../default-normalizer';\nimport { normalizeSqliteNativeType } from '../native-type-normalizer';\nimport type { SqlitePlanTargetDetails } from './planner-target-details';\n\nexport function createSqliteMigrationRunner(\n family: SqlControlFamilyInstance,\n): SqlMigrationRunner<SqlitePlanTargetDetails> {\n return new SqliteMigrationRunner(family);\n}\n\nclass SqliteMigrationRunner implements SqlMigrationRunner<SqlitePlanTargetDetails> {\n constructor(private readonly family: SqlControlFamilyInstance) {}\n\n /**\n * Apply the plan against an already-open connection without managing\n * the transaction lifecycle. The caller ({@link SqliteMigrationRunner.execute})\n * owns BEGIN/COMMIT/ROLLBACK and any connection-level setup (FK pragma\n * toggle, FK integrity check).\n */\n async executeOnConnection(\n options: SqlMigrationRunnerExecuteOptions<SqlitePlanTargetDetails>,\n ): Promise<SqlMigrationRunnerResult> {\n const driver = options.driver;\n if (options.space !== undefined && options.space !== options.plan.spaceId) {\n throw new Error(\n `SqlMigrationRunner: options.space (${options.space}) does not match plan.spaceId (${options.plan.spaceId})`,\n );\n }\n const space = options.plan.spaceId;\n\n // Materialize any async ops before running checks or executing.\n const planOps = blindCast<\n readonly SqlMigrationPlanOperation<SqlitePlanTargetDetails>[],\n 'ops were produced by the SQLite planner and are SqlMigrationPlanOperation<SqlitePlanTargetDetails>; MigrationPlan.operations uses the wider framework type to accommodate Promise covariance'\n >(await Promise.all(options.plan.operations));\n\n const destinationCheck = this.ensurePlanMatchesDestinationContract(\n options.plan.destination,\n options.destinationContract,\n );\n if (!destinationCheck.ok) return destinationCheck;\n\n const policyCheck = this.enforcePolicyCompatibility(options.policy, planOps);\n if (!policyCheck.ok) return policyCheck;\n\n const ensureResult = await this.ensureControlTables(driver, options.destinationContract);\n if (!ensureResult.ok) return ensureResult;\n const existingMarker = await this.family.readMarker({ driver, space });\n\n const markerCheck = this.ensureMarkerCompatibility(existingMarker, options.plan);\n if (!markerCheck.ok) return markerCheck;\n\n const markerAtDestination = this.markerMatchesDestination(existingMarker, options.plan);\n const isSelfEdge = options.plan.origin?.storageHash === options.plan.destination.storageHash;\n const skipOperations = markerAtDestination && options.plan.origin != null && !isSelfEdge;\n\n let operationsExecuted: number;\n let executedOperations: readonly SqlMigrationPlanOperation<SqlitePlanTargetDetails>[];\n\n if (skipOperations) {\n operationsExecuted = 0;\n executedOperations = [];\n } else {\n const applyResult = await this.applyPlan(driver, options, planOps);\n if (!applyResult.ok) return applyResult;\n operationsExecuted = applyResult.value.operationsExecuted;\n executedOperations = applyResult.value.executedOperations;\n }\n\n if (space === APP_SPACE_ID) {\n const schemaIR = await this.family.introspect({\n driver,\n contract: options.destinationContract,\n });\n\n const schemaVerifyResult = verifySqlSchema({\n contract: options.destinationContract,\n schema: schemaIR,\n strict: options.strictVerification ?? true,\n context: options.context ?? {},\n typeMetadataRegistry: this.family.typeMetadataRegistry,\n frameworkComponents: options.frameworkComponents,\n normalizeDefault: parseSqliteDefault,\n normalizeNativeType: normalizeSqliteNativeType,\n });\n if (!schemaVerifyResult.ok) {\n return runnerFailure('SCHEMA_VERIFY_FAILED', schemaVerifyResult.summary, {\n why: 'The resulting database schema does not satisfy the destination contract.',\n meta: { issues: schemaVerifyResult.schema.issues },\n });\n }\n }\n\n // Self-edge no-op detection: see Postgres runner for the rationale\n // (kept symmetric across both targets).\n const incomingInvariants = options.plan.providedInvariants;\n const existingInvariants = new Set(existingMarker?.invariants ?? []);\n const incomingIsSubsetOfExisting = incomingInvariants.every((id) => existingInvariants.has(id));\n const isSelfEdgeNoOp = isSelfEdge && operationsExecuted === 0 && incomingIsSubsetOfExisting;\n\n if (!isSelfEdgeNoOp) {\n const markerResult = await this.upsertMarker(driver, options, existingMarker, space);\n if (!markerResult.ok) return markerResult;\n await this.recordLedgerEntries(driver, options, executedOperations);\n }\n\n return runnerSuccess({\n operationsPlanned: planOps.length,\n operationsExecuted,\n });\n }\n\n async execute(options: {\n readonly driver: SqlControlDriverInstance<string>;\n readonly perSpaceOptions: ReadonlyArray<\n SqlMigrationRunnerExecuteOptions<SqlitePlanTargetDetails>\n >;\n }): Promise<MigrationRunnerResult> {\n const driver = options.driver;\n const perSpaceOptions = options.perSpaceOptions;\n\n if (perSpaceOptions.length === 0) {\n return ok({ perSpaceResults: [] });\n }\n\n // FK pragma toggle and the FK integrity check both span the outer\n // transaction: PRAGMA foreign_keys is a no-op inside a transaction, so the\n // toggle has to wrap BEGIN/COMMIT.\n const fkWasEnabled = await this.readForeignKeysEnabled(driver);\n if (fkWasEnabled) {\n await driver.query('PRAGMA foreign_keys = OFF');\n }\n\n try {\n await this.beginExclusiveTransaction(driver);\n let committed = false;\n try {\n const perSpaceResults: Array<{\n space: string;\n value: SqlMigrationRunnerSuccessValue;\n }> = [];\n let lastProcessedSpace: string | undefined;\n for (const spaceOptions of perSpaceOptions) {\n const space = spaceOptions.space ?? spaceOptions.plan.spaceId;\n const result = await this.executeOnConnection({ ...spaceOptions, driver, space });\n if (!result.ok) {\n return notOk({ ...result.failure, failingSpace: space });\n }\n perSpaceResults.push({ space, value: result.value });\n lastProcessedSpace = space;\n }\n\n if (fkWasEnabled) {\n const fkIntegrityCheck = await this.verifyForeignKeyIntegrity(driver);\n if (!fkIntegrityCheck.ok) {\n // Post-loop integrity violations cannot be attributed to a\n // single per-space step (the cumulative effect of all\n // applied plans was needed to reveal the broken\n // reference). Surface the last successfully-applied space\n // so operators can investigate from the most recent\n // migration first.\n return notOk({\n ...fkIntegrityCheck.failure,\n failingSpace: lastProcessedSpace ?? APP_SPACE_ID,\n });\n }\n }\n\n await this.commitTransaction(driver);\n committed = true;\n return ok({ perSpaceResults });\n } finally {\n if (!committed) {\n await this.rollbackTransaction(driver);\n }\n }\n } finally {\n if (fkWasEnabled) {\n await driver.query('PRAGMA foreign_keys = ON');\n }\n }\n }\n\n private async readForeignKeysEnabled(\n driver: SqlMigrationRunnerExecuteOptions<SqlitePlanTargetDetails>['driver'],\n ): Promise<boolean> {\n const result = await driver.query<{ foreign_keys: number }>('PRAGMA foreign_keys');\n const row = result.rows[0];\n return row?.foreign_keys === 1;\n }\n\n private async verifyForeignKeyIntegrity(\n driver: SqlMigrationRunnerExecuteOptions<SqlitePlanTargetDetails>['driver'],\n ): Promise<Result<void, SqlMigrationRunnerFailure>> {\n const result = await driver.query<Record<string, unknown>>('PRAGMA foreign_key_check');\n if (result.rows.length === 0) {\n return okVoid();\n }\n return runnerFailure(\n 'FOREIGN_KEY_VIOLATION',\n `Foreign key integrity check failed after migration: ${result.rows.length} violation(s).`,\n {\n why: 'PRAGMA foreign_key_check reported violations after applying recreate-table operations.',\n meta: { violations: result.rows },\n },\n );\n }\n\n private async applyPlan(\n driver: SqlMigrationRunnerExecuteOptions<SqlitePlanTargetDetails>['driver'],\n options: SqlMigrationRunnerExecuteOptions<SqlitePlanTargetDetails>,\n ops: readonly SqlMigrationPlanOperation<SqlitePlanTargetDetails>[],\n ): Promise<\n Result<\n {\n readonly operationsExecuted: number;\n readonly executedOperations: readonly SqlMigrationPlanOperation<SqlitePlanTargetDetails>[];\n },\n SqlMigrationRunnerFailure\n >\n > {\n const checks = options.executionChecks;\n const runPrechecks = checks?.prechecks !== false;\n const runPostchecks = checks?.postchecks !== false;\n const runIdempotency = checks?.idempotencyChecks !== false;\n\n let operationsExecuted = 0;\n const executedOperations: Array<SqlMigrationPlanOperation<SqlitePlanTargetDetails>> = [];\n\n for (const operation of ops) {\n options.callbacks?.onOperationStart?.(operation);\n try {\n if (runPostchecks && runIdempotency) {\n const postcheckAlreadySatisfied = await this.expectationsAreSatisfied(\n driver,\n operation.postcheck,\n );\n if (postcheckAlreadySatisfied) {\n executedOperations.push(this.createSkipRecord(operation));\n continue;\n }\n }\n\n if (runPrechecks) {\n const precheckResult = await this.runExpectationSteps(\n driver,\n operation.precheck,\n operation,\n 'precheck',\n );\n if (!precheckResult.ok) {\n return precheckResult;\n }\n }\n\n const executeResult = await this.runExecuteSteps(driver, operation.execute, operation);\n if (!executeResult.ok) {\n return executeResult;\n }\n\n if (runPostchecks) {\n const postcheckResult = await this.runExpectationSteps(\n driver,\n operation.postcheck,\n operation,\n 'postcheck',\n );\n if (!postcheckResult.ok) {\n return postcheckResult;\n }\n }\n\n executedOperations.push(operation);\n operationsExecuted += 1;\n } finally {\n options.callbacks?.onOperationComplete?.(operation);\n }\n }\n return ok({ operationsExecuted, executedOperations });\n }\n\n private async ensureControlTables(\n driver: SqlMigrationRunnerExecuteOptions<SqlitePlanTargetDetails>['driver'],\n contract: Contract<SqlStorage>,\n ): Promise<Result<void, SqlMigrationRunnerFailure>> {\n const legacyDetection = await this.detectLegacyMarkerShape(driver);\n if (!legacyDetection.ok) {\n return legacyDetection;\n }\n const lowererContext = { contract };\n for (const query of this.family.bootstrapControlTableQueries()) {\n await this.executeStatement(driver, await this.family.lowerAst(query, lowererContext));\n }\n return okVoid();\n }\n\n private async detectLegacyMarkerShape(\n driver: SqlMigrationRunnerExecuteOptions<SqlitePlanTargetDetails>['driver'],\n ): Promise<Result<void, SqlMigrationRunnerFailure>> {\n const tableInfo = await driver.query<{ name: string }>(\n `PRAGMA table_info(\"${MARKER_TABLE_NAME}\")`,\n );\n if (tableInfo.rows.length === 0) {\n return okVoid();\n }\n const columns = new Set(tableInfo.rows.map((row) => row.name));\n if (columns.has('space')) {\n return okVoid();\n }\n return runnerFailure(\n 'LEGACY_MARKER_SHAPE',\n `Legacy marker-table shape detected on ${MARKER_TABLE_NAME} (no \\`space\\` column). ` +\n 'Prisma Next is in pre-1.0; the previous transitional auto-migration to the per-space-row schema has been removed. ' +\n `Drop \\`${MARKER_TABLE_NAME}\\` and re-run \\`dbInit\\` to reinitialise from a clean baseline.`,\n {\n meta: {\n table: MARKER_TABLE_NAME,\n columns: [...columns].sort(),\n },\n },\n );\n }\n\n private async runExpectationSteps(\n driver: SqlMigrationRunnerExecuteOptions<SqlitePlanTargetDetails>['driver'],\n steps: readonly SqlMigrationPlanOperationStep[],\n operation: SqlMigrationPlanOperation<SqlitePlanTargetDetails>,\n phase: 'precheck' | 'postcheck',\n ): Promise<Result<void, SqlMigrationRunnerFailure>> {\n for (const step of steps) {\n const result = await driver.query(step.sql, step.params ?? []);\n if (!this.stepResultIsTrue(result.rows)) {\n const code = phase === 'precheck' ? 'PRECHECK_FAILED' : 'POSTCHECK_FAILED';\n return runnerFailure(\n code,\n `Operation ${operation.id} failed during ${phase}: ${step.description}`,\n {\n meta: {\n operationId: operation.id,\n phase,\n stepDescription: step.description,\n },\n },\n );\n }\n }\n return okVoid();\n }\n\n private async runExecuteSteps(\n driver: SqlMigrationRunnerExecuteOptions<SqlitePlanTargetDetails>['driver'],\n steps: readonly SqlMigrationPlanOperationStep[],\n operation: SqlMigrationPlanOperation<SqlitePlanTargetDetails>,\n ): Promise<Result<void, SqlMigrationRunnerFailure>> {\n for (const step of steps) {\n try {\n await driver.query(step.sql, step.params ?? []);\n } catch (error: unknown) {\n const message = error instanceof Error ? error.message : String(error);\n return runnerFailure(\n 'EXECUTION_FAILED',\n `Operation ${operation.id} failed during execution: ${step.description}`,\n {\n why: message,\n meta: {\n operationId: operation.id,\n stepDescription: step.description,\n sql: step.sql,\n },\n },\n );\n }\n }\n return okVoid();\n }\n\n private stepResultIsTrue(rows: readonly Record<string, unknown>[]): boolean {\n if (!rows || rows.length === 0) {\n return false;\n }\n const firstRow = rows[0];\n const firstValue = firstRow ? Object.values(firstRow)[0] : undefined;\n if (typeof firstValue === 'number') {\n return firstValue !== 0;\n }\n if (typeof firstValue === 'boolean') {\n return firstValue;\n }\n if (typeof firstValue === 'string') {\n const lower = firstValue.toLowerCase();\n if (lower === 'true' || lower === '1') return true;\n if (lower === 'false' || lower === '0') return false;\n return firstValue.length > 0;\n }\n return Boolean(firstValue);\n }\n\n private async expectationsAreSatisfied(\n driver: SqlMigrationRunnerExecuteOptions<SqlitePlanTargetDetails>['driver'],\n steps: readonly SqlMigrationPlanOperationStep[],\n ): Promise<boolean> {\n if (steps.length === 0) {\n return false;\n }\n for (const step of steps) {\n const result = await driver.query(step.sql, step.params ?? []);\n if (!this.stepResultIsTrue(result.rows)) {\n return false;\n }\n }\n return true;\n }\n\n private createSkipRecord(\n operation: SqlMigrationPlanOperation<SqlitePlanTargetDetails>,\n ): SqlMigrationPlanOperation<SqlitePlanTargetDetails> {\n return Object.freeze({\n id: operation.id,\n label: operation.label,\n ...ifDefined('summary', operation.summary),\n operationClass: operation.operationClass,\n target: operation.target,\n precheck: Object.freeze([]),\n execute: Object.freeze([]),\n postcheck: Object.freeze([...operation.postcheck]),\n meta: Object.freeze({\n ...(operation.meta ?? {}),\n runner: Object.freeze({ skipped: true, reason: 'postcheck_pre_satisfied' }),\n }),\n });\n }\n\n private markerMatchesDestination(\n marker: ContractMarkerRecord | null,\n plan: SqlMigrationRunnerExecuteOptions<SqlitePlanTargetDetails>['plan'],\n ): boolean {\n if (!marker) return false;\n if (marker.storageHash !== plan.destination.storageHash) return false;\n if (plan.destination.profileHash && marker.profileHash !== plan.destination.profileHash) {\n return false;\n }\n return true;\n }\n\n private enforcePolicyCompatibility(\n policy: MigrationOperationPolicy,\n operations: readonly SqlMigrationPlanOperation<SqlitePlanTargetDetails>[],\n ): Result<void, SqlMigrationRunnerFailure> {\n const allowedClasses = new Set(policy.allowedOperationClasses);\n for (const operation of operations) {\n if (!allowedClasses.has(operation.operationClass)) {\n return runnerFailure(\n 'POLICY_VIOLATION',\n `Operation ${operation.id} has class \"${operation.operationClass}\" which is not allowed by policy.`,\n {\n why: `Policy only allows: ${policy.allowedOperationClasses.join(', ')}.`,\n meta: {\n operationId: operation.id,\n operationClass: operation.operationClass,\n allowedClasses: policy.allowedOperationClasses,\n },\n },\n );\n }\n }\n return okVoid();\n }\n\n private ensureMarkerCompatibility(\n marker: ContractMarkerRecord | null,\n plan: SqlMigrationRunnerExecuteOptions<SqlitePlanTargetDetails>['plan'],\n ): Result<void, SqlMigrationRunnerFailure> {\n const origin = plan.origin ?? null;\n if (!origin) {\n return okVoid();\n }\n if (!marker) {\n return runnerFailure(\n 'MARKER_ORIGIN_MISMATCH',\n `Missing contract marker: expected origin storage hash ${origin.storageHash}.`,\n { meta: { expectedOriginStorageHash: origin.storageHash } },\n );\n }\n if (marker.storageHash !== origin.storageHash) {\n return runnerFailure(\n 'MARKER_ORIGIN_MISMATCH',\n `Existing contract marker (${marker.storageHash}) does not match plan origin (${origin.storageHash}).`,\n {\n meta: {\n markerStorageHash: marker.storageHash,\n expectedOriginStorageHash: origin.storageHash,\n },\n },\n );\n }\n if (origin.profileHash && marker.profileHash !== origin.profileHash) {\n return runnerFailure(\n 'MARKER_ORIGIN_MISMATCH',\n `Existing contract marker profile hash (${marker.profileHash}) does not match plan origin profile hash (${origin.profileHash}).`,\n {\n meta: {\n markerProfileHash: marker.profileHash,\n expectedOriginProfileHash: origin.profileHash,\n },\n },\n );\n }\n return okVoid();\n }\n\n private ensurePlanMatchesDestinationContract(\n destination: SqlMigrationPlanContractInfo,\n contract: SqlMigrationRunnerExecuteOptions<SqlitePlanTargetDetails>['destinationContract'],\n ): Result<void, SqlMigrationRunnerFailure> {\n if (destination.storageHash !== contract.storage.storageHash) {\n return runnerFailure(\n 'DESTINATION_CONTRACT_MISMATCH',\n `Plan destination storage hash (${destination.storageHash}) does not match provided contract storage hash (${contract.storage.storageHash}).`,\n {\n meta: {\n planStorageHash: destination.storageHash,\n contractStorageHash: contract.storage.storageHash,\n },\n },\n );\n }\n if (\n destination.profileHash &&\n contract.profileHash &&\n destination.profileHash !== contract.profileHash\n ) {\n return runnerFailure(\n 'DESTINATION_CONTRACT_MISMATCH',\n `Plan destination profile hash (${destination.profileHash}) does not match provided contract profile hash (${contract.profileHash}).`,\n {\n meta: {\n planProfileHash: destination.profileHash,\n contractProfileHash: contract.profileHash,\n },\n },\n );\n }\n return okVoid();\n }\n\n private async upsertMarker(\n driver: SqlMigrationRunnerExecuteOptions<SqlitePlanTargetDetails>['driver'],\n options: SqlMigrationRunnerExecuteOptions<SqlitePlanTargetDetails>,\n existingMarker: ContractMarkerRecord | null,\n space: string,\n ): Promise<Result<void, SqlMigrationRunnerFailure>> {\n // Pass the plan's incoming invariants verbatim; `updateMarker` unions them\n // with the stored set (TS-side, dialect-uniform) under the runner's\n // BEGIN EXCLUSIVE — no client-side pre-merge here, so there is no\n // double-merge with the SPI's internal accumulate-dedupe.\n const destination = {\n storageHash: options.plan.destination.storageHash,\n profileHash:\n options.plan.destination.profileHash ??\n options.destinationContract.profileHash ??\n options.plan.destination.storageHash,\n invariants: options.plan.providedInvariants ?? [],\n };\n if (!existingMarker) {\n await this.family.initMarker({ driver, space, destination });\n return okVoid();\n }\n const updated = await this.family.updateMarker({\n driver,\n space,\n expectedFrom: existingMarker.storageHash,\n destination,\n });\n if (!updated) {\n return runnerFailure(\n 'MARKER_CAS_FAILURE',\n 'Marker was modified by another process during migration execution.',\n {\n meta: {\n space,\n expectedStorageHash: existingMarker.storageHash,\n destinationStorageHash: options.plan.destination.storageHash,\n },\n },\n );\n }\n return okVoid();\n }\n\n private async recordLedgerEntries(\n driver: SqlMigrationRunnerExecuteOptions<SqlitePlanTargetDetails>['driver'],\n options: SqlMigrationRunnerExecuteOptions<SqlitePlanTargetDetails>,\n executedOperations: readonly SqlMigrationPlanOperation<SqlitePlanTargetDetails>[],\n ): Promise<void> {\n const plan = options.plan;\n const space = plan.spaceId;\n const edges = options.migrationEdges;\n const totalEdgeOps = edges.reduce((sum, edge) => sum + edge.operationCount, 0);\n if (totalEdgeOps !== plan.operations.length) {\n throw new Error(\n `Ledger write: plan.operations length (${plan.operations.length}) does not match sum of migrationEdges operationCount (${totalEdgeOps})`,\n );\n }\n // The ledger records the operations as executed — idempotency-skipped ops\n // are substituted with skip records (empty `execute`) by `applyPlan`, so the\n // journal reflects what actually ran rather than the raw plan.\n let offset = 0;\n for (const edge of edges) {\n const edgeOps = executedOperations.slice(offset, offset + edge.operationCount);\n offset += edge.operationCount;\n await this.family.writeLedgerEntry({\n driver,\n space,\n entry: {\n edgeId: `${edge.from}->${edge.to}`,\n from: edge.from,\n to: edge.to,\n migrationName: edge.dirName,\n migrationHash: edge.migrationHash,\n operations: edgeOps,\n },\n });\n }\n }\n\n private async beginExclusiveTransaction(\n driver: SqlMigrationRunnerExecuteOptions<SqlitePlanTargetDetails>['driver'],\n ): Promise<void> {\n await driver.query('BEGIN EXCLUSIVE');\n }\n\n private async commitTransaction(\n driver: SqlMigrationRunnerExecuteOptions<SqlitePlanTargetDetails>['driver'],\n ): Promise<void> {\n await driver.query('COMMIT');\n }\n\n private async rollbackTransaction(\n driver: SqlMigrationRunnerExecuteOptions<SqlitePlanTargetDetails>['driver'],\n ): Promise<void> {\n await driver.query('ROLLBACK');\n }\n\n private async executeStatement(\n driver: SqlMigrationRunnerExecuteOptions<SqlitePlanTargetDetails>['driver'],\n statement: SqlExecuteRequest,\n ): Promise<void> {\n await driver.query(statement.sql, statement.params);\n }\n}\n","import type { Contract } from '@prisma-next/contract/types';\nimport { SqlSchemaVerifierBase } from '@prisma-next/family-sql/ir';\nimport type { SchemaIssue, SchemaVerifyOptions } from '@prisma-next/framework-components/control';\nimport type { SqlStorage } from '@prisma-next/sql-contract/types';\nimport type { SqlSchemaIR } from '@prisma-next/sql-schema-ir/types';\n\n/**\n * SQLite target `SchemaVerifier` concretion. Mirrors the Postgres\n * shape: hooks return the empty list pending the call-site migration\n * that routes the existing verifier behaviour through the SPI.\n */\nexport class SqliteSchemaVerifier extends SqlSchemaVerifierBase<Contract<SqlStorage>, SqlSchemaIR> {\n protected verifyCommonSqlSchema(\n _options: SchemaVerifyOptions<Contract<SqlStorage>, SqlSchemaIR>,\n ): readonly SchemaIssue[] {\n return [];\n }\n\n protected verifyTargetExtensions(\n _options: SchemaVerifyOptions<Contract<SqlStorage>, SqlSchemaIR>,\n ): readonly SchemaIssue[] {\n return [];\n }\n}\n","import type { ColumnDefault, Contract } from '@prisma-next/contract/types';\nimport type { SqlControlTargetDescriptor } from '@prisma-next/family-sql/control';\nimport { contractToSchemaIR } from '@prisma-next/family-sql/control';\nimport type { SqlControlAdapter } from '@prisma-next/family-sql/control-adapter';\nimport type {\n ControlTargetInstance,\n MigrationPlanner,\n MigrationRunner,\n} from '@prisma-next/framework-components/control';\nimport { SqlStorage, type StorageColumn } from '@prisma-next/sql-contract/types';\nimport { sqliteTargetDescriptorMeta } from './descriptor-meta';\nimport { createSqliteMigrationPlanner } from './migrations/planner';\nimport { renderDefaultLiteral } from './migrations/planner-ddl-builders';\nimport type { SqlitePlanTargetDetails } from './migrations/planner-target-details';\nimport { createSqliteMigrationRunner } from './migrations/runner';\nimport { SqliteContractSerializer } from './sqlite-contract-serializer';\nimport { SqliteSchemaVerifier } from './sqlite-schema-verifier';\n\nfunction isSqlContract(contract: Contract | null): contract is Contract<SqlStorage> | null {\n return contract === null || contract.storage instanceof SqlStorage;\n}\n\nfunction sqliteRenderDefault(def: ColumnDefault, _column: StorageColumn): string {\n if (def.kind === 'function') {\n if (def.expression === 'now()') {\n return \"datetime('now')\";\n }\n return def.expression;\n }\n return renderDefaultLiteral(def.value);\n}\n\nconst sqliteControlTargetDescriptor: SqlControlTargetDescriptor<'sqlite', SqlitePlanTargetDetails> =\n {\n ...sqliteTargetDescriptorMeta,\n contractSerializer: new SqliteContractSerializer(),\n schemaVerifier: new SqliteSchemaVerifier(),\n migrations: {\n createPlanner(adapter: SqlControlAdapter<'sqlite'>): MigrationPlanner<'sql', 'sqlite'> {\n return createSqliteMigrationPlanner(adapter);\n },\n createRunner(family) {\n return createSqliteMigrationRunner(family) as MigrationRunner<'sql', 'sqlite'>;\n },\n contractToSchema(contract, _frameworkComponents) {\n // The framework SPI types `contract` as the generic\n // `Contract | null`. Any contract reaching the sqlite\n // target descriptor is SQL-family by construction (the\n // family contract resolver would have refused to bind a\n // sqlite target otherwise); the `isSqlContract` predicate\n // encodes that invariant at runtime + narrows the generic\n // to `Contract<SqlStorage>` without a blind cast.\n if (!isSqlContract(contract)) {\n throw new Error(\n 'sqliteControlTargetDescriptor.contractToSchema received a non-SQL contract; expected Contract<SqlStorage>',\n );\n }\n return contractToSchemaIR(contract, {\n annotationNamespace: 'sqlite',\n renderDefault: sqliteRenderDefault,\n });\n },\n },\n create(): ControlTargetInstance<'sql', 'sqlite'> {\n return {\n familyId: 'sql',\n targetId: 'sqlite',\n };\n },\n createPlanner(adapter: SqlControlAdapter<'sqlite'>) {\n return createSqliteMigrationPlanner(adapter);\n },\n createRunner(family) {\n return createSqliteMigrationRunner(family);\n },\n };\n\nexport default sqliteControlTargetDescriptor;\n"],"mappings":";;;;;;;;;;;;;;;;AA4BA,SAAgB,4BACd,QAC6C;CAC7C,OAAO,IAAI,sBAAsB,MAAM;AACzC;AAEA,IAAM,wBAAN,MAAmF;CACpD;CAA7B,YAAY,QAAmD;EAAlC,KAAA,SAAA;CAAmC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EACf,MAAM,OAAO,MAAM,QAAQ;CAC7B;CAEA,MAAc,oBACZ,QACe;EACf,MAAM,OAAO,MAAM,UAAU;CAC/B;CAEA,MAAc,iBACZ,QACA,WACe;EACf,MAAM,OAAO,MAAM,UAAU,KAAK,UAAU,MAAM;CACpD;AACF;;;;;;;;ACtpBA,IAAa,uBAAb,cAA0C,sBAAyD;CACjG,sBACE,UACwB;EACxB,OAAO,CAAC;CACV;CAEA,uBACE,UACwB;EACxB,OAAO,CAAC;CACV;AACF;;;ACLA,SAAS,cAAc,UAAoE;CACzF,OAAO,aAAa,QAAQ,SAAS,mBAAmB;AAC1D;AAEA,SAAS,oBAAoB,KAAoB,SAAgC;CAC/E,IAAI,IAAI,SAAS,YAAY;EAC3B,IAAI,IAAI,eAAe,SACrB,OAAO;EAET,OAAO,IAAI;CACb;CACA,OAAO,qBAAqB,IAAI,KAAK;AACvC;AAEA,MAAM,gCACJ;CACE,GAAG;CACH,oBAAoB,IAAI,yBAAyB;CACjD,gBAAgB,IAAI,qBAAqB;CACzC,YAAY;EACV,cAAc,SAAyE;GACrF,OAAO,6BAA6B,OAAO;EAC7C;EACA,aAAa,QAAQ;GACnB,OAAO,4BAA4B,MAAM;EAC3C;EACA,iBAAiB,UAAU,sBAAsB;GAQ/C,IAAI,CAAC,cAAc,QAAQ,GACzB,MAAM,IAAI,MACR,2GACF;GAEF,OAAO,mBAAmB,UAAU;IAClC,qBAAqB;IACrB,eAAe;GACjB,CAAC;EACH;CACF;CACA,SAAiD;EAC/C,OAAO;GACL,UAAU;GACV,UAAU;EACZ;CACF;CACA,cAAc,SAAsC;EAClD,OAAO,6BAA6B,OAAO;CAC7C;CACA,aAAa,QAAQ;EACnB,OAAO,4BAA4B,MAAM;CAC3C;AACF"}
@@ -0,0 +1,23 @@
1
+ import { t as SqliteCreateTable } from "./nodes-D0k4z7NL.mjs";
2
+ //#region src/contract-free/ddl.ts
3
+ /**
4
+ * Build a SQLite `CREATE TABLE` query node.
5
+ *
6
+ * Pass `constraints` for table-level composite primary keys, foreign keys, and
7
+ * unique constraints — use the {@link PrimaryKeyConstraint}, {@link ForeignKeyConstraint},
8
+ * and {@link UniqueConstraint} classes from `@prisma-next/sql-relational-core/ast`.
9
+ *
10
+ * Precondition: identifiers (`table`, column names/types) are emitted to SQL
11
+ * verbatim — they are not quoted or escaped, so callers must pass pre-trusted
12
+ * values (e.g. fixed control-plane identifiers). String-literal default values,
13
+ * by contrast, are single-quote-escaped (embedded `'` doubled) by the renderer.
14
+ * Identifier quoting for untrusted identifiers is added when the migration
15
+ * planner adopts this lowering path.
16
+ */
17
+ function createTable(options) {
18
+ return new SqliteCreateTable(options);
19
+ }
20
+ //#endregion
21
+ export { createTable as t };
22
+
23
+ //# sourceMappingURL=ddl-CH8V_qcd.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ddl-CH8V_qcd.mjs","names":[],"sources":["../src/contract-free/ddl.ts"],"sourcesContent":["import type { DdlColumn, DdlTableConstraint } from '@prisma-next/sql-relational-core/ast';\nimport { SqliteCreateTable } from '../core/ddl/nodes';\n\n/**\n * Build a SQLite `CREATE TABLE` query node.\n *\n * Pass `constraints` for table-level composite primary keys, foreign keys, and\n * unique constraints — use the {@link PrimaryKeyConstraint}, {@link ForeignKeyConstraint},\n * and {@link UniqueConstraint} classes from `@prisma-next/sql-relational-core/ast`.\n *\n * Precondition: identifiers (`table`, column names/types) are emitted to SQL\n * verbatim — they are not quoted or escaped, so callers must pass pre-trusted\n * values (e.g. fixed control-plane identifiers). String-literal default values,\n * by contrast, are single-quote-escaped (embedded `'` doubled) by the renderer.\n * Identifier quoting for untrusted identifiers is added when the migration\n * planner adopts this lowering path.\n */\nexport function createTable(options: {\n readonly table: string;\n readonly schema?: string;\n readonly ifNotExists?: boolean;\n readonly columns: readonly DdlColumn[];\n readonly constraints?: readonly DdlTableConstraint[];\n}): SqliteCreateTable {\n return new SqliteCreateTable(options);\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAiBA,SAAgB,YAAY,SAMN;CACpB,OAAO,IAAI,kBAAkB,OAAO;AACtC"}
@@ -1,7 +1,8 @@
1
1
  import { i as SqliteTableSpec, n as SqliteColumnSpec, r as SqliteIndexSpec, t as Op } from "./shared-Dhc8mLK1.mjs";
2
- import { t as SqliteMigration } from "./sqlite-migration-D4XGYzgQ.mjs";
2
+ import { t as SqliteMigration } from "./sqlite-migration-CJrASAxf.mjs";
3
3
  import { MigrationOperationClass } from "@prisma-next/family-sql/control";
4
4
  import { placeholder } from "@prisma-next/errors/migration";
5
+ import { col, fn, foreignKey, lit, primaryKey, unique } from "@prisma-next/sql-relational-core/contract-free";
5
6
  import { MigrationCLI } from "@prisma-next/cli/migration-cli";
6
7
 
7
8
  //#region src/core/migrations/operations/columns.d.ts
@@ -48,7 +49,6 @@ declare function dropIndex(tableName: string, indexName: string): Op;
48
49
  declare function rawSql(op: Op): Op;
49
50
  //#endregion
50
51
  //#region src/core/migrations/operations/tables.d.ts
51
- declare function createTable(tableName: string, spec: SqliteTableSpec): Op;
52
52
  declare function dropTable(tableName: string): Op;
53
53
  interface RecreateTableArgs {
54
54
  readonly tableName: string;
@@ -81,5 +81,5 @@ interface RecreateTableArgs {
81
81
  }
82
82
  declare function recreateTable(args: RecreateTableArgs): Op;
83
83
  //#endregion
84
- export { type DataTransformOptions, SqliteMigration as Migration, MigrationCLI, addColumn, createIndex, createTable, dataTransform, dropColumn, dropIndex, dropTable, placeholder, rawSql, recreateTable };
84
+ export { type DataTransformOptions, SqliteMigration as Migration, MigrationCLI, addColumn, col, createIndex, dataTransform, dropColumn, dropIndex, dropTable, fn, foreignKey, lit, placeholder, primaryKey, rawSql, recreateTable, unique };
85
85
  //# sourceMappingURL=migration.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"migration.d.mts","names":[],"sources":["../src/core/migrations/operations/columns.ts","../src/core/migrations/operations/data-transform.ts","../src/core/migrations/operations/indexes.ts","../src/core/migrations/operations/raw.ts","../src/core/migrations/operations/tables.ts"],"mappings":";;;;;;;iBAIgB,SAAA,CAAU,SAAA,UAAmB,MAAA,EAAQ,gBAAA,GAAmB,EAAE;AAAA,iBA+B1D,UAAA,CAAW,SAAA,UAAmB,UAAA,WAAqB,EAAE;;;UCnBpD,oBAAA;EDZ4B;EAAA,SCclC,EAAA;EDd+D;EAAA,SCgB/D,KAAA;EDeK;EAAA,SCbL,KAAA;;;;;WAKA,WAAA;EDQ0D;AAAA;;;;ACnBrE;;;EDmBqE,SCC1D,GAAA;AAAA;AAAA,iBAGK,aAAA,CAAc,IAAA,EAAM,oBAAA,GAAuB,EAAE;;;iBClC7C,WAAA,CAAY,SAAA,UAAmB,SAAA,UAAmB,OAAA,sBAA6B,EAAE;AAAA,iBAyBjF,SAAA,CAAU,SAAA,UAAmB,SAAA,WAAoB,EAAE;;;;;;;;;;iBCrBnD,MAAA,CAAO,EAAA,EAAI,EAAA,GAAK,EAAE;;;iBCmClB,WAAA,CAAY,SAAA,UAAmB,IAAA,EAAM,eAAA,GAAkB,EAAE;AAAA,iBAuBzD,SAAA,CAAU,SAAA,WAAoB,EAAE;AAAA,UAuB/B,iBAAA;EAAA,SACN,SAAA;;WAEA,aAAA,EAAe,eAAA;EJzFD;;;;;;EAAA,SIgGd,iBAAA;EJhG+D;AAAA;AA+B1E;;EA/B0E,SIqG/D,OAAA,WAAkB,eAAA;EJtEwC;EAAA,SIwE1D,OAAA;EJxEmC;;;AAAuB;;EAAvB,SI8EnC,UAAA;IAAA,SAAgC,WAAA;IAAA,SAA8B,GAAA;EAAA;EAAA,SAC9D,cAAA,EAAgB,uBAAA;AAAA;AAAA,iBAGX,aAAA,CAAc,IAAA,EAAM,iBAAA,GAAoB,EAAE"}
1
+ {"version":3,"file":"migration.d.mts","names":[],"sources":["../src/core/migrations/operations/columns.ts","../src/core/migrations/operations/data-transform.ts","../src/core/migrations/operations/indexes.ts","../src/core/migrations/operations/raw.ts","../src/core/migrations/operations/tables.ts"],"mappings":";;;;;;;;iBAIgB,SAAA,CAAU,SAAA,UAAmB,MAAA,EAAQ,gBAAA,GAAmB,EAAE;AAAA,iBA+B1D,UAAA,CAAW,SAAA,UAAmB,UAAA,WAAqB,EAAE;;;UCnBpD,oBAAA;EDZoC;EAAA,SCc1C,EAAA;EDd6D;EAAA,SCgB7D,KAAA;EDhB+D;EAAA,SCkB/D,KAAA;EDae;;;;EAAA,SCRf,WAAA;EDQwD;;AAAE;;;;ACnBrE;;EDmBmE,SCCxD,GAAA;AAAA;AAAA,iBAGK,aAAA,CAAc,IAAA,EAAM,oBAAA,GAAuB,EAAE;;;iBClC7C,WAAA,CAAY,SAAA,UAAmB,SAAA,UAAmB,OAAA,sBAA6B,EAAE;AAAA,iBAyBjF,SAAA,CAAU,SAAA,UAAmB,SAAA,WAAoB,EAAE;;;;;;;;;;iBCrBnD,MAAA,CAAO,EAAA,EAAI,EAAA,GAAK,EAAE;;;iBC0DlB,SAAA,CAAU,SAAA,WAAoB,EAAE;AAAA,UAuB/B,iBAAA;EAAA,SACN,SAAA;;WAEA,aAAA,EAAe,eAAA;EJzFV;;;;;;EAAA,SIgGL,iBAAA;EJhG6D;;AAAE;AA+B1E;EA/BwE,SIqG7D,OAAA,WAAkB,eAAA;;WAElB,OAAA;EJxEgB;;;;AAA0C;EAA1C,SI8EhB,UAAA;IAAA,SAAgC,WAAA;IAAA,SAA8B,GAAA;EAAA;EAAA,SAC9D,cAAA,EAAgB,uBAAA;AAAA;AAAA,iBAGX,aAAA,CAAc,IAAA,EAAM,iBAAA,GAAoB,EAAE"}
@@ -1,7 +1,8 @@
1
1
  import { t as buildTargetDetails } from "./planner-target-details-H8z9TFDg.mjs";
2
- import { a as recreateTable, f as addColumn, i as dropTable, m as step, o as createIndex, p as dropColumn, r as createTable, s as dropIndex } from "./tables-CjB7vXCr.mjs";
3
- import { t as SqliteMigration } from "./sqlite-migration-CUqgmzQH.mjs";
2
+ import { C as step, S as dropColumn, f as dropTable, h as dropIndex, m as createIndex, p as recreateTable, x as addColumn } from "./op-factory-call-z4TT72k3.mjs";
3
+ import { t as SqliteMigration } from "./sqlite-migration-DhW4ycZV.mjs";
4
4
  import { placeholder } from "@prisma-next/errors/migration";
5
+ import { col, fn, foreignKey, lit, primaryKey, unique } from "@prisma-next/sql-relational-core/contract-free";
5
6
  import { MigrationCLI } from "@prisma-next/cli/migration-cli";
6
7
  //#region src/core/migrations/operations/data-transform.ts
7
8
  /**
@@ -44,6 +45,6 @@ function rawSql(op) {
44
45
  return op;
45
46
  }
46
47
  //#endregion
47
- export { SqliteMigration as Migration, MigrationCLI, addColumn, createIndex, createTable, dataTransform, dropColumn, dropIndex, dropTable, placeholder, rawSql, recreateTable };
48
+ export { SqliteMigration as Migration, MigrationCLI, addColumn, col, createIndex, dataTransform, dropColumn, dropIndex, dropTable, fn, foreignKey, lit, placeholder, primaryKey, rawSql, recreateTable, unique };
48
49
 
49
50
  //# sourceMappingURL=migration.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"migration.mjs","names":[],"sources":["../src/core/migrations/operations/data-transform.ts","../src/core/migrations/operations/raw.ts"],"sourcesContent":["/**\n * User-facing `dataTransform` factory for the SQLite migration authoring\n * surface. Invoked directly inside a `migration.ts` file to supply a\n * user-authored SQL statement that runs with operation class `'data'`.\n *\n * Typical use: the planner emits a `DataTransformCall` stub when a NOT NULL\n * tightening requires a backfill. The rendered `migration.ts` exposes the\n * backfill as a `placeholder(\"…\")` slot the user fills in with an\n * `UPDATE … WHERE col IS NULL` statement. The filled-in `dataTransform(...)`\n * invocation returns a runnable operation the runner executes before the\n * subsequent recreate-table op copies data into the tightened schema.\n */\n\nimport { buildTargetDetails } from '../planner-target-details';\nimport { type Op, step } from './shared';\n\nexport interface DataTransformOptions {\n /** Stable id used in the ledger / for runner idempotency tracking. */\n readonly id: string;\n /** Human-readable label surfaced in CLI output. */\n readonly label: string;\n /** Table the backfill targets; informs `target.details`. */\n readonly table: string;\n /**\n * Short description of the step (shown by the runner on execute). The\n * planner leaves this as `placeholder(...)` for users to replace.\n */\n readonly description: string;\n /**\n * Producer of the SQL string to execute. Invoked eagerly by\n * `dataTransform(...)`, mirroring the Postgres factory — by the time the\n * user calls this factory in `migration.ts`, the SQL is expected to be\n * ready. Planner-emitted stubs that need to defer until the user fills\n * in the SQL go through `DataTransformCall.renderTypeScript()` instead;\n * this factory is only for the post-fill, runnable form.\n */\n readonly run: () => string;\n}\n\nexport function dataTransform(opts: DataTransformOptions): Op {\n return {\n id: opts.id,\n label: opts.label,\n summary: opts.description,\n operationClass: 'data',\n target: { id: 'sqlite', details: buildTargetDetails('table', opts.table) },\n precheck: [],\n execute: [step(opts.description, opts.run())],\n postcheck: [],\n };\n}\n","import type { Op } from './shared';\n\n/**\n * Identity factory for an already-materialized\n * `SqlMigrationPlanOperation<SqlitePlanTargetDetails>`. Mirrors the Postgres\n * `rawSql` factory: the planner uses this to carry ops produced by SQL-family\n * paths (codec lifecycle hooks, raw-SQL escape hatches) alongside structured\n * call IR without reverse-engineering their shape.\n */\nexport function rawSql(op: Op): Op {\n return op;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAuCA,SAAgB,cAAc,MAAgC;CAC5D,OAAO;EACL,IAAI,KAAK;EACT,OAAO,KAAK;EACZ,SAAS,KAAK;EACd,gBAAgB;EAChB,QAAQ;GAAE,IAAI;GAAU,SAAS,mBAAmB,SAAS,KAAK,KAAK;EAAE;EACzE,UAAU,CAAC;EACX,SAAS,CAAC,KAAK,KAAK,aAAa,KAAK,IAAI,CAAC,CAAC;EAC5C,WAAW,CAAC;CACd;AACF;;;;;;;;;;ACzCA,SAAgB,OAAO,IAAY;CACjC,OAAO;AACT"}
1
+ {"version":3,"file":"migration.mjs","names":[],"sources":["../src/core/migrations/operations/data-transform.ts","../src/core/migrations/operations/raw.ts"],"sourcesContent":["/**\n * User-facing `dataTransform` factory for the SQLite migration authoring\n * surface. Invoked directly inside a `migration.ts` file to supply a\n * user-authored SQL statement that runs with operation class `'data'`.\n *\n * Typical use: the planner emits a `DataTransformCall` stub when a NOT NULL\n * tightening requires a backfill. The rendered `migration.ts` exposes the\n * backfill as a `placeholder(\"…\")` slot the user fills in with an\n * `UPDATE … WHERE col IS NULL` statement. The filled-in `dataTransform(...)`\n * invocation returns a runnable operation the runner executes before the\n * subsequent recreate-table op copies data into the tightened schema.\n */\n\nimport { buildTargetDetails } from '../planner-target-details';\nimport { type Op, step } from './shared';\n\nexport interface DataTransformOptions {\n /** Stable id used in the ledger / for runner idempotency tracking. */\n readonly id: string;\n /** Human-readable label surfaced in CLI output. */\n readonly label: string;\n /** Table the backfill targets; informs `target.details`. */\n readonly table: string;\n /**\n * Short description of the step (shown by the runner on execute). The\n * planner leaves this as `placeholder(...)` for users to replace.\n */\n readonly description: string;\n /**\n * Producer of the SQL string to execute. Invoked eagerly by\n * `dataTransform(...)`, mirroring the Postgres factory — by the time the\n * user calls this factory in `migration.ts`, the SQL is expected to be\n * ready. Planner-emitted stubs that need to defer until the user fills\n * in the SQL go through `DataTransformCall.renderTypeScript()` instead;\n * this factory is only for the post-fill, runnable form.\n */\n readonly run: () => string;\n}\n\nexport function dataTransform(opts: DataTransformOptions): Op {\n return {\n id: opts.id,\n label: opts.label,\n summary: opts.description,\n operationClass: 'data',\n target: { id: 'sqlite', details: buildTargetDetails('table', opts.table) },\n precheck: [],\n execute: [step(opts.description, opts.run())],\n postcheck: [],\n };\n}\n","import type { Op } from './shared';\n\n/**\n * Identity factory for an already-materialized\n * `SqlMigrationPlanOperation<SqlitePlanTargetDetails>`. Mirrors the Postgres\n * `rawSql` factory: the planner uses this to carry ops produced by SQL-family\n * paths (codec lifecycle hooks, raw-SQL escape hatches) alongside structured\n * call IR without reverse-engineering their shape.\n */\nexport function rawSql(op: Op): Op {\n return op;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAuCA,SAAgB,cAAc,MAAgC;CAC5D,OAAO;EACL,IAAI,KAAK;EACT,OAAO,KAAK;EACZ,SAAS,KAAK;EACd,gBAAgB;EAChB,QAAQ;GAAE,IAAI;GAAU,SAAS,mBAAmB,SAAS,KAAK,KAAK;EAAE;EACzE,UAAU,CAAC;EACX,SAAS,CAAC,KAAK,KAAK,aAAa,KAAK,IAAI,CAAC,CAAC;EAC5C,WAAW,CAAC;CACd;AACF;;;;;;;;;;ACzCA,SAAgB,OAAO,IAAY;CACjC,OAAO;AACT"}