@prisma-next/target-postgres 0.5.0-dev.6 → 0.5.0-dev.60

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 (81) hide show
  1. package/dist/{codec-ids-CojIXVf9.mjs → codec-ids-ckQX9Kcg.mjs} +3 -2
  2. package/dist/{codec-ids-CojIXVf9.mjs.map → codec-ids-ckQX9Kcg.mjs.map} +1 -1
  3. package/dist/codec-ids.d.mts +2 -1
  4. package/dist/codec-ids.d.mts.map +1 -1
  5. package/dist/codec-ids.mjs +2 -2
  6. package/dist/codec-types.d.mts +1 -1
  7. package/dist/codec-types.mjs +2 -1
  8. package/dist/{codecs-D-F2KJqt.d.mts → codecs-B03dFv94.d.mts} +64 -30
  9. package/dist/codecs-B03dFv94.d.mts.map +1 -0
  10. package/dist/{codecs-BoahtY_Q.mjs → codecs-D0oXyJIH.mjs} +24 -104
  11. package/dist/codecs-D0oXyJIH.mjs.map +1 -0
  12. package/dist/codecs.d.mts +1 -1
  13. package/dist/codecs.mjs +2 -1
  14. package/dist/control.mjs +21 -63
  15. package/dist/control.mjs.map +1 -1
  16. package/dist/{data-transform-VfEGzXWt.mjs → data-transform-Be_i_DBc.mjs} +24 -5
  17. package/dist/data-transform-Be_i_DBc.mjs.map +1 -0
  18. package/dist/data-transform-CrpmG4uJ.d.mts +39 -0
  19. package/dist/data-transform-CrpmG4uJ.d.mts.map +1 -0
  20. package/dist/data-transform.d.mts +1 -1
  21. package/dist/data-transform.mjs +1 -1
  22. package/dist/{descriptor-meta-BVoVtyp-.mjs → descriptor-meta-Ieg1XLOs.mjs} +7 -12
  23. package/dist/descriptor-meta-Ieg1XLOs.mjs.map +1 -0
  24. package/dist/issue-planner.d.mts +1 -1
  25. package/dist/migration.d.mts +2 -2
  26. package/dist/migration.mjs +2 -2
  27. package/dist/op-factory-call-C3bWXKSP.d.mts.map +1 -1
  28. package/dist/pack.d.mts +28 -9
  29. package/dist/pack.d.mts.map +1 -1
  30. package/dist/pack.mjs +1 -1
  31. package/dist/{planner-CLUvVhUN.mjs → planner-Cm-ZLutk.mjs} +6 -6
  32. package/dist/planner-Cm-ZLutk.mjs.map +1 -0
  33. package/dist/{planner-produced-postgres-migration-DSSPq8QS.mjs → planner-produced-postgres-migration-Bi-RWO4-.mjs} +3 -4
  34. package/dist/{planner-produced-postgres-migration-DSSPq8QS.mjs.map → planner-produced-postgres-migration-Bi-RWO4-.mjs.map} +1 -1
  35. package/dist/{planner-produced-postgres-migration-CRRTno6Z.d.mts → planner-produced-postgres-migration-M3EfhWSS.d.mts} +2 -2
  36. package/dist/planner-produced-postgres-migration-M3EfhWSS.d.mts.map +1 -0
  37. package/dist/planner-produced-postgres-migration.d.mts +3 -2
  38. package/dist/planner-produced-postgres-migration.mjs +1 -1
  39. package/dist/planner.d.mts +17 -10
  40. package/dist/planner.d.mts.map +1 -1
  41. package/dist/planner.mjs +1 -1
  42. package/dist/{postgres-migration-BjA3Zmts.d.mts → postgres-migration-BFjbb25b.d.mts} +4 -3
  43. package/dist/postgres-migration-BFjbb25b.d.mts.map +1 -0
  44. package/dist/{postgres-migration-qtmtbONe.mjs → postgres-migration-BS9vQW97.mjs} +2 -2
  45. package/dist/postgres-migration-BS9vQW97.mjs.map +1 -0
  46. package/dist/{render-typescript-1rF_SB4g.mjs → render-typescript-Co3Emwgz.mjs} +1 -2
  47. package/dist/render-typescript-Co3Emwgz.mjs.map +1 -0
  48. package/dist/render-typescript.d.mts +1 -2
  49. package/dist/render-typescript.d.mts.map +1 -1
  50. package/dist/render-typescript.mjs +1 -1
  51. package/dist/runtime.mjs +1 -1
  52. package/dist/{statement-builders-BPnmt6wx.mjs → statement-builders-CHqCtSfe.mjs} +13 -8
  53. package/dist/statement-builders-CHqCtSfe.mjs.map +1 -0
  54. package/dist/statement-builders.d.mts +10 -3
  55. package/dist/statement-builders.d.mts.map +1 -1
  56. package/dist/statement-builders.mjs +2 -2
  57. package/package.json +15 -14
  58. package/src/core/authoring.ts +5 -11
  59. package/src/core/codec-ids.ts +1 -0
  60. package/src/core/codecs.ts +53 -40
  61. package/src/core/migrations/operations/data-transform.ts +86 -21
  62. package/src/core/migrations/planner-produced-postgres-migration.ts +0 -1
  63. package/src/core/migrations/planner.ts +17 -11
  64. package/src/core/migrations/postgres-migration.ts +3 -6
  65. package/src/core/migrations/render-typescript.ts +1 -5
  66. package/src/core/migrations/runner.ts +43 -112
  67. package/src/core/migrations/statement-builders.ts +22 -6
  68. package/src/exports/statement-builders.ts +1 -1
  69. package/dist/codecs-BoahtY_Q.mjs.map +0 -1
  70. package/dist/codecs-D-F2KJqt.d.mts.map +0 -1
  71. package/dist/data-transform-CxFRBIUp.d.mts +0 -32
  72. package/dist/data-transform-CxFRBIUp.d.mts.map +0 -1
  73. package/dist/data-transform-VfEGzXWt.mjs.map +0 -1
  74. package/dist/descriptor-meta-BVoVtyp-.mjs.map +0 -1
  75. package/dist/planner-CLUvVhUN.mjs.map +0 -1
  76. package/dist/planner-produced-postgres-migration-CRRTno6Z.d.mts.map +0 -1
  77. package/dist/postgres-migration-BjA3Zmts.d.mts.map +0 -1
  78. package/dist/postgres-migration-qtmtbONe.mjs.map +0 -1
  79. package/dist/render-typescript-1rF_SB4g.mjs.map +0 -1
  80. package/dist/statement-builders-BPnmt6wx.mjs.map +0 -1
  81. package/src/core/json-schema-type-expression.ts +0 -131
package/dist/pack.mjs CHANGED
@@ -1,3 +1,3 @@
1
- import { t as postgresTargetDescriptorMeta } from "./descriptor-meta-BVoVtyp-.mjs";
1
+ import { t as postgresTargetDescriptorMeta } from "./descriptor-meta-Ieg1XLOs.mjs";
2
2
 
3
3
  export { postgresTargetDescriptorMeta as default };
@@ -1,7 +1,7 @@
1
1
  import { t as parsePostgresDefault } from "./default-normalizer-DNOpRoOF.mjs";
2
2
  import { t as normalizeSchemaNativeType } from "./native-type-normalizer-CInai_oY.mjs";
3
3
  import { n as postgresPlannerStrategies, t as planIssues } from "./issue-planner-CFjB0_oO.mjs";
4
- import { t as TypeScriptRenderablePostgresMigration } from "./planner-produced-postgres-migration-DSSPq8QS.mjs";
4
+ import { t as TypeScriptRenderablePostgresMigration } from "./planner-produced-postgres-migration-Bi-RWO4-.mjs";
5
5
  import { extractCodecControlHooks, plannerFailure } from "@prisma-next/family-sql/control";
6
6
  import { verifySqlSchema } from "@prisma-next/family-sql/schema-verify";
7
7
 
@@ -34,7 +34,7 @@ var PostgresMigrationPlanner = class {
34
34
  this.config = config;
35
35
  }
36
36
  plan(options) {
37
- return this.planSql(options, options.fromHash ?? "");
37
+ return this.planSql(options);
38
38
  }
39
39
  emptyMigration(context) {
40
40
  return new TypeScriptRenderablePostgresMigration([], {
@@ -42,7 +42,7 @@ var PostgresMigrationPlanner = class {
42
42
  to: context.toHash
43
43
  });
44
44
  }
45
- planSql(options, fromHash) {
45
+ planSql(options) {
46
46
  const schemaName = options.schemaName ?? this.config.defaultSchema;
47
47
  const policyResult = this.ensureAdditivePolicy(options.policy);
48
48
  if (policyResult) return policyResult;
@@ -52,7 +52,7 @@ var PostgresMigrationPlanner = class {
52
52
  const result = planIssues({
53
53
  issues: schemaIssues,
54
54
  toContract: options.contract,
55
- fromContract: options.fromContract ?? null,
55
+ fromContract: options.fromContract,
56
56
  schemaName,
57
57
  codecHooks,
58
58
  storageTypes,
@@ -65,7 +65,7 @@ var PostgresMigrationPlanner = class {
65
65
  return Object.freeze({
66
66
  kind: "success",
67
67
  plan: new TypeScriptRenderablePostgresMigration(result.value.calls, {
68
- from: fromHash,
68
+ from: options.fromContract?.storage.storageHash ?? null,
69
69
  to: options.contract.storage.storageHash
70
70
  })
71
71
  });
@@ -95,4 +95,4 @@ var PostgresMigrationPlanner = class {
95
95
 
96
96
  //#endregion
97
97
  export { createPostgresMigrationPlanner as t };
98
- //# sourceMappingURL=planner-CLUvVhUN.mjs.map
98
+ //# sourceMappingURL=planner-Cm-ZLutk.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"planner-Cm-ZLutk.mjs","names":["DEFAULT_PLANNER_CONFIG: PlannerConfig","config: PlannerConfig"],"sources":["../src/core/migrations/planner.ts"],"sourcesContent":["import type { Contract } from '@prisma-next/contract/types';\nimport type {\n MigrationOperationPolicy,\n SqlMigrationPlannerPlanOptions,\n SqlPlannerFailureResult,\n} from '@prisma-next/family-sql/control';\nimport { extractCodecControlHooks, plannerFailure } from '@prisma-next/family-sql/control';\nimport { verifySqlSchema } from '@prisma-next/family-sql/schema-verify';\nimport type { TargetBoundComponentDescriptor } from '@prisma-next/framework-components/components';\nimport type {\n MigrationPlanner,\n MigrationPlanWithAuthoringSurface,\n MigrationScaffoldContext,\n SchemaIssue,\n} from '@prisma-next/framework-components/control';\nimport { parsePostgresDefault } from '../default-normalizer';\nimport { normalizeSchemaNativeType } from '../native-type-normalizer';\nimport { planIssues } from './issue-planner';\nimport { TypeScriptRenderablePostgresMigration } from './planner-produced-postgres-migration';\nimport { postgresPlannerStrategies } from './planner-strategies';\n\ntype PlannerFrameworkComponents = SqlMigrationPlannerPlanOptions extends {\n readonly frameworkComponents: infer T;\n}\n ? T\n : ReadonlyArray<unknown>;\n\ntype PlannerOptionsWithComponents = SqlMigrationPlannerPlanOptions & {\n readonly frameworkComponents: PlannerFrameworkComponents;\n};\n\ntype VerifySqlSchemaOptionsWithComponents = Parameters<typeof verifySqlSchema>[0] & {\n readonly frameworkComponents: PlannerFrameworkComponents;\n};\n\ninterface PlannerConfig {\n readonly defaultSchema: string;\n}\n\nconst DEFAULT_PLANNER_CONFIG: PlannerConfig = {\n defaultSchema: 'public',\n};\n\nexport function createPostgresMigrationPlanner(\n config: Partial<PlannerConfig> = {},\n): PostgresMigrationPlanner {\n return new PostgresMigrationPlanner({\n ...DEFAULT_PLANNER_CONFIG,\n ...config,\n });\n}\n\n/**\n * Result of `PostgresMigrationPlanner.plan()`. A discriminated union whose\n * success variant carries a `TypeScriptRenderablePostgresMigration` — a\n * migration object that both the CLI (via `renderTypeScript()`) and the\n * SQL-typed callers (via `operations`, `describe()`, etc.) consume\n * uniformly.\n */\nexport type PostgresPlanResult =\n | { readonly kind: 'success'; readonly plan: TypeScriptRenderablePostgresMigration }\n | SqlPlannerFailureResult;\n\n/**\n * Postgres migration planner — a thin wrapper over `planIssues`.\n *\n * `plan()` verifies the live schema against the target contract (producing\n * `SchemaIssue[]`) and delegates to `planIssues` with the unified\n * `postgresPlannerStrategies` list: enum-change, NOT-NULL backfill,\n * type-change, nullable-tightening, codec-hook storage types,\n * component-declared dependency installs, and shared-temp-default /\n * empty-table-guarded NOT-NULL add-column. The same strategy list runs for\n * `migration plan`, `db update`, and `db init`; behavior diverges purely on\n * `policy.allowedOperationClasses` (the data-safe strategies short-circuit\n * when `'data'` is excluded). The issue planner applies operation-class\n * policy gates and emits a single `PostgresOpFactoryCall[]` that drives both\n * the runtime-ops view (via `renderOps`) and the `renderTypeScript()`\n * authoring surface.\n */\nexport class PostgresMigrationPlanner implements MigrationPlanner<'sql', 'postgres'> {\n constructor(private readonly config: PlannerConfig) {}\n\n plan(options: {\n readonly contract: unknown;\n readonly schema: unknown;\n readonly policy: MigrationOperationPolicy;\n /**\n * The \"from\" contract (state the planner assumes the database starts\n * at), or `null` for reconciliation flows. Only `migration plan` ever\n * supplies a non-null value; `db update` / `db init` reconcile against\n * the live schema and pass `null`. When present alongside the\n * `'data'` operation class, strategies that need from/to column-shape\n * comparisons (unsafe type change, nullability tightening) activate.\n *\n * Typed as the framework `Contract | null` to satisfy the\n * `MigrationPlanner` interface contract; `planSql` narrows to the SQL\n * shape via `SqlMigrationPlannerPlanOptions`. Used to populate\n * `describe().from` on the produced plan as\n * `fromContract?.storage.storageHash ?? null`.\n */\n readonly fromContract: Contract | null;\n readonly schemaName?: string;\n readonly frameworkComponents: ReadonlyArray<TargetBoundComponentDescriptor<'sql', string>>;\n }): PostgresPlanResult {\n return this.planSql(options as SqlMigrationPlannerPlanOptions);\n }\n\n emptyMigration(context: MigrationScaffoldContext): MigrationPlanWithAuthoringSurface {\n return new TypeScriptRenderablePostgresMigration([], {\n from: context.fromHash,\n to: context.toHash,\n });\n }\n\n private planSql(options: SqlMigrationPlannerPlanOptions): PostgresPlanResult {\n const schemaName = options.schemaName ?? this.config.defaultSchema;\n const policyResult = this.ensureAdditivePolicy(options.policy);\n if (policyResult) {\n return policyResult;\n }\n\n const schemaIssues = this.collectSchemaIssues(options);\n const codecHooks = extractCodecControlHooks(options.frameworkComponents);\n const storageTypes = options.contract.storage.types ?? {};\n\n const result = planIssues({\n issues: schemaIssues,\n toContract: options.contract,\n // `fromContract` is only supplied by `migration plan`. It is `null` for\n // `db update` / `db init`, which means data-safety strategies needing\n // from/to comparisons (unsafe type change, nullable tightening) are\n // inapplicable there — reconciliation falls through to\n // `mapIssueToCall`'s direct destructive handlers.\n fromContract: options.fromContract,\n schemaName,\n codecHooks,\n storageTypes,\n schema: options.schema,\n policy: options.policy,\n frameworkComponents: options.frameworkComponents,\n strategies: postgresPlannerStrategies,\n });\n\n if (!result.ok) {\n return plannerFailure(result.failure);\n }\n\n return Object.freeze({\n kind: 'success' as const,\n plan: new TypeScriptRenderablePostgresMigration(result.value.calls, {\n from: options.fromContract?.storage.storageHash ?? null,\n to: options.contract.storage.storageHash,\n }),\n });\n }\n\n private ensureAdditivePolicy(policy: MigrationOperationPolicy) {\n if (!policy.allowedOperationClasses.includes('additive')) {\n return plannerFailure([\n {\n kind: 'unsupportedOperation',\n summary: 'Migration planner requires additive operations be allowed',\n why: 'The planner requires the \"additive\" operation class to be allowed in the policy.',\n },\n ]);\n }\n return null;\n }\n\n private collectSchemaIssues(options: PlannerOptionsWithComponents): readonly SchemaIssue[] {\n // `db init` uses additive-only policy and intentionally ignores extra\n // schema objects. Any reconciliation-capable policy (widening or\n // destructive) must inspect extras to reconcile strict equality.\n const allowed = options.policy.allowedOperationClasses;\n const strict = allowed.includes('widening') || allowed.includes('destructive');\n const verifyOptions: VerifySqlSchemaOptionsWithComponents = {\n contract: options.contract,\n schema: options.schema,\n strict,\n typeMetadataRegistry: new Map(),\n frameworkComponents: options.frameworkComponents,\n normalizeDefault: parsePostgresDefault,\n normalizeNativeType: normalizeSchemaNativeType,\n };\n const verifyResult = verifySqlSchema(verifyOptions);\n return verifyResult.schema.issues;\n }\n}\n"],"mappings":";;;;;;;;AAuCA,MAAMA,yBAAwC,EAC5C,eAAe,UAChB;AAED,SAAgB,+BACd,SAAiC,EAAE,EACT;AAC1B,QAAO,IAAI,yBAAyB;EAClC,GAAG;EACH,GAAG;EACJ,CAAC;;;;;;;;;;;;;;;;;;AA8BJ,IAAa,2BAAb,MAAqF;CACnF,YAAY,AAAiBC,QAAuB;EAAvB;;CAE7B,KAAK,SAqBkB;AACrB,SAAO,KAAK,QAAQ,QAA0C;;CAGhE,eAAe,SAAsE;AACnF,SAAO,IAAI,sCAAsC,EAAE,EAAE;GACnD,MAAM,QAAQ;GACd,IAAI,QAAQ;GACb,CAAC;;CAGJ,AAAQ,QAAQ,SAA6D;EAC3E,MAAM,aAAa,QAAQ,cAAc,KAAK,OAAO;EACrD,MAAM,eAAe,KAAK,qBAAqB,QAAQ,OAAO;AAC9D,MAAI,aACF,QAAO;EAGT,MAAM,eAAe,KAAK,oBAAoB,QAAQ;EACtD,MAAM,aAAa,yBAAyB,QAAQ,oBAAoB;EACxE,MAAM,eAAe,QAAQ,SAAS,QAAQ,SAAS,EAAE;EAEzD,MAAM,SAAS,WAAW;GACxB,QAAQ;GACR,YAAY,QAAQ;GAMpB,cAAc,QAAQ;GACtB;GACA;GACA;GACA,QAAQ,QAAQ;GAChB,QAAQ,QAAQ;GAChB,qBAAqB,QAAQ;GAC7B,YAAY;GACb,CAAC;AAEF,MAAI,CAAC,OAAO,GACV,QAAO,eAAe,OAAO,QAAQ;AAGvC,SAAO,OAAO,OAAO;GACnB,MAAM;GACN,MAAM,IAAI,sCAAsC,OAAO,MAAM,OAAO;IAClE,MAAM,QAAQ,cAAc,QAAQ,eAAe;IACnD,IAAI,QAAQ,SAAS,QAAQ;IAC9B,CAAC;GACH,CAAC;;CAGJ,AAAQ,qBAAqB,QAAkC;AAC7D,MAAI,CAAC,OAAO,wBAAwB,SAAS,WAAW,CACtD,QAAO,eAAe,CACpB;GACE,MAAM;GACN,SAAS;GACT,KAAK;GACN,CACF,CAAC;AAEJ,SAAO;;CAGT,AAAQ,oBAAoB,SAA+D;EAIzF,MAAM,UAAU,QAAQ,OAAO;EAC/B,MAAM,SAAS,QAAQ,SAAS,WAAW,IAAI,QAAQ,SAAS,cAAc;AAW9E,SADqB,gBATuC;GAC1D,UAAU,QAAQ;GAClB,QAAQ,QAAQ;GAChB;GACA,sCAAsB,IAAI,KAAK;GAC/B,qBAAqB,QAAQ;GAC7B,kBAAkB;GAClB,qBAAqB;GACtB,CACkD,CAC/B,OAAO"}
@@ -1,6 +1,6 @@
1
- import { t as PostgresMigration } from "./postgres-migration-qtmtbONe.mjs";
1
+ import { t as PostgresMigration } from "./postgres-migration-BS9vQW97.mjs";
2
2
  import { t as renderOps } from "./render-ops-D6_DHdOK.mjs";
3
- import { t as renderCallsToTypeScript } from "./render-typescript-1rF_SB4g.mjs";
3
+ import { t as renderCallsToTypeScript } from "./render-typescript-Co3Emwgz.mjs";
4
4
  import { ifDefined } from "@prisma-next/utils/defined";
5
5
 
6
6
  //#region src/core/migrations/planner-produced-postgres-migration.ts
@@ -22,7 +22,6 @@ var TypeScriptRenderablePostgresMigration = class extends PostgresMigration {
22
22
  return renderCallsToTypeScript(this.#calls, {
23
23
  from: this.#meta.from,
24
24
  to: this.#meta.to,
25
- ...ifDefined("kind", this.#meta.kind),
26
25
  ...ifDefined("labels", this.#meta.labels)
27
26
  });
28
27
  }
@@ -30,4 +29,4 @@ var TypeScriptRenderablePostgresMigration = class extends PostgresMigration {
30
29
 
31
30
  //#endregion
32
31
  export { TypeScriptRenderablePostgresMigration as t };
33
- //# sourceMappingURL=planner-produced-postgres-migration-DSSPq8QS.mjs.map
32
+ //# sourceMappingURL=planner-produced-postgres-migration-Bi-RWO4-.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"planner-produced-postgres-migration-DSSPq8QS.mjs","names":["#calls","#meta"],"sources":["../src/core/migrations/planner-produced-postgres-migration.ts"],"sourcesContent":["/**\n * Planner-produced Postgres migration.\n *\n * Returned by `PostgresMigrationPlanner.plan(...)` and `emptyMigration(...)`.\n * Holds the migration IR (`PostgresOpFactoryCall[]`) alongside\n * `MigrationMeta` and exposes both the runtime-ops view (`get operations`)\n * and the TypeScript authoring view (`renderTypeScript()`). Satisfies\n * `MigrationPlanWithAuthoringSurface` so the CLI can uniformly serialize any\n * planner result back to `migration.ts`.\n *\n * Extends the family-level `SqlMigration` alias rather than the target-local\n * migration base directly — mirrors Mongo's `PlannerProducedMongoMigration`\n * shape and keeps CLI wiring one step removed from target internals.\n *\n * Placeholder-bearing plans: `renderTypeScript()` always succeeds and embeds\n * `() => placeholder(\"slot\")` at each stub. `operations`, in contrast, is\n * _not safe to enumerate_ on a stub-bearing plan — `DataTransformCall.toOp()`\n * throws `PN-MIG-2001` because a planner-stubbed closure cannot be lowered\n * to a runtime op. Callers that know a plan may carry stubs must render to\n * `migration.ts`, let the user fill the slots, and re-load the edited\n * migration before enumerating ops. The walk-schema planner does not emit\n * `DataTransformCall`s today, so this asymmetry is invisible until the\n * issue-planner integration lands in Phase 2.\n */\n\nimport type { SqlMigrationPlanOperation } from '@prisma-next/family-sql/control';\nimport type { MigrationPlanWithAuthoringSurface } from '@prisma-next/framework-components/control';\nimport type { MigrationMeta } from '@prisma-next/migration-tools/migration';\nimport { ifDefined } from '@prisma-next/utils/defined';\nimport type { PostgresOpFactoryCall } from './op-factory-call';\nimport type { PostgresPlanTargetDetails } from './planner-target-details';\nimport { PostgresMigration } from './postgres-migration';\nimport { renderOps } from './render-ops';\nimport { renderCallsToTypeScript } from './render-typescript';\n\ntype Op = SqlMigrationPlanOperation<PostgresPlanTargetDetails>;\n\nexport class TypeScriptRenderablePostgresMigration\n extends PostgresMigration\n implements MigrationPlanWithAuthoringSurface\n{\n readonly #calls: readonly PostgresOpFactoryCall[];\n readonly #meta: MigrationMeta;\n\n constructor(calls: readonly PostgresOpFactoryCall[], meta: MigrationMeta) {\n super();\n this.#calls = calls;\n this.#meta = meta;\n }\n\n override get operations(): readonly Op[] {\n return renderOps(this.#calls);\n }\n\n override describe(): MigrationMeta {\n return this.#meta;\n }\n\n renderTypeScript(): string {\n return renderCallsToTypeScript(this.#calls, {\n from: this.#meta.from,\n to: this.#meta.to,\n ...ifDefined('kind', this.#meta.kind),\n ...ifDefined('labels', this.#meta.labels),\n });\n }\n}\n"],"mappings":";;;;;;AAqCA,IAAa,wCAAb,cACU,kBAEV;CACE,CAASA;CACT,CAASC;CAET,YAAY,OAAyC,MAAqB;AACxE,SAAO;AACP,QAAKD,QAAS;AACd,QAAKC,OAAQ;;CAGf,IAAa,aAA4B;AACvC,SAAO,UAAU,MAAKD,MAAO;;CAG/B,AAAS,WAA0B;AACjC,SAAO,MAAKC;;CAGd,mBAA2B;AACzB,SAAO,wBAAwB,MAAKD,OAAQ;GAC1C,MAAM,MAAKC,KAAM;GACjB,IAAI,MAAKA,KAAM;GACf,GAAG,UAAU,QAAQ,MAAKA,KAAM,KAAK;GACrC,GAAG,UAAU,UAAU,MAAKA,KAAM,OAAO;GAC1C,CAAC"}
1
+ {"version":3,"file":"planner-produced-postgres-migration-Bi-RWO4-.mjs","names":["#calls","#meta"],"sources":["../src/core/migrations/planner-produced-postgres-migration.ts"],"sourcesContent":["/**\n * Planner-produced Postgres migration.\n *\n * Returned by `PostgresMigrationPlanner.plan(...)` and `emptyMigration(...)`.\n * Holds the migration IR (`PostgresOpFactoryCall[]`) alongside\n * `MigrationMeta` and exposes both the runtime-ops view (`get operations`)\n * and the TypeScript authoring view (`renderTypeScript()`). Satisfies\n * `MigrationPlanWithAuthoringSurface` so the CLI can uniformly serialize any\n * planner result back to `migration.ts`.\n *\n * Extends the family-level `SqlMigration` alias rather than the target-local\n * migration base directly — mirrors Mongo's `PlannerProducedMongoMigration`\n * shape and keeps CLI wiring one step removed from target internals.\n *\n * Placeholder-bearing plans: `renderTypeScript()` always succeeds and embeds\n * `() => placeholder(\"slot\")` at each stub. `operations`, in contrast, is\n * _not safe to enumerate_ on a stub-bearing plan — `DataTransformCall.toOp()`\n * throws `PN-MIG-2001` because a planner-stubbed closure cannot be lowered\n * to a runtime op. Callers that know a plan may carry stubs must render to\n * `migration.ts`, let the user fill the slots, and re-load the edited\n * migration before enumerating ops. The walk-schema planner does not emit\n * `DataTransformCall`s today, so this asymmetry is invisible until the\n * issue-planner integration lands in Phase 2.\n */\n\nimport type { SqlMigrationPlanOperation } from '@prisma-next/family-sql/control';\nimport type { MigrationPlanWithAuthoringSurface } from '@prisma-next/framework-components/control';\nimport type { MigrationMeta } from '@prisma-next/migration-tools/migration';\nimport { ifDefined } from '@prisma-next/utils/defined';\nimport type { PostgresOpFactoryCall } from './op-factory-call';\nimport type { PostgresPlanTargetDetails } from './planner-target-details';\nimport { PostgresMigration } from './postgres-migration';\nimport { renderOps } from './render-ops';\nimport { renderCallsToTypeScript } from './render-typescript';\n\ntype Op = SqlMigrationPlanOperation<PostgresPlanTargetDetails>;\n\nexport class TypeScriptRenderablePostgresMigration\n extends PostgresMigration\n implements MigrationPlanWithAuthoringSurface\n{\n readonly #calls: readonly PostgresOpFactoryCall[];\n readonly #meta: MigrationMeta;\n\n constructor(calls: readonly PostgresOpFactoryCall[], meta: MigrationMeta) {\n super();\n this.#calls = calls;\n this.#meta = meta;\n }\n\n override get operations(): readonly Op[] {\n return renderOps(this.#calls);\n }\n\n override describe(): MigrationMeta {\n return this.#meta;\n }\n\n renderTypeScript(): string {\n return renderCallsToTypeScript(this.#calls, {\n from: this.#meta.from,\n to: this.#meta.to,\n ...ifDefined('labels', this.#meta.labels),\n });\n }\n}\n"],"mappings":";;;;;;AAqCA,IAAa,wCAAb,cACU,kBAEV;CACE,CAASA;CACT,CAASC;CAET,YAAY,OAAyC,MAAqB;AACxE,SAAO;AACP,QAAKD,QAAS;AACd,QAAKC,OAAQ;;CAGf,IAAa,aAA4B;AACvC,SAAO,UAAU,MAAKD,MAAO;;CAG/B,AAAS,WAA0B;AACjC,SAAO,MAAKC;;CAGd,mBAA2B;AACzB,SAAO,wBAAwB,MAAKD,OAAQ;GAC1C,MAAM,MAAKC,KAAM;GACjB,IAAI,MAAKA,KAAM;GACf,GAAG,UAAU,UAAU,MAAKA,KAAM,OAAO;GAC1C,CAAC"}
@@ -1,6 +1,6 @@
1
1
  import { t as PostgresPlanTargetDetails } from "./planner-target-details-DH-azLu-.mjs";
2
2
  import { b as PostgresOpFactoryCall } from "./op-factory-call-C3bWXKSP.mjs";
3
- import { t as PostgresMigration } from "./postgres-migration-BjA3Zmts.mjs";
3
+ import { t as PostgresMigration } from "./postgres-migration-BFjbb25b.mjs";
4
4
  import { SqlMigrationPlanOperation } from "@prisma-next/family-sql/control";
5
5
  import { MigrationPlanWithAuthoringSurface } from "@prisma-next/framework-components/control";
6
6
  import { MigrationMeta } from "@prisma-next/migration-tools/migration";
@@ -17,4 +17,4 @@ declare class TypeScriptRenderablePostgresMigration extends PostgresMigration im
17
17
  }
18
18
  //#endregion
19
19
  export { TypeScriptRenderablePostgresMigration as t };
20
- //# sourceMappingURL=planner-produced-postgres-migration-CRRTno6Z.d.mts.map
20
+ //# sourceMappingURL=planner-produced-postgres-migration-M3EfhWSS.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"planner-produced-postgres-migration-M3EfhWSS.d.mts","names":[],"sources":["../src/core/migrations/planner-produced-postgres-migration.ts"],"sourcesContent":[],"mappings":";;;;;;;;;KAmCK,EAAA,GAAK,0BAA0B;cAEvB,qCAAA,SACH,iBAAA,YACG;;8BAKiB,+BAA+B;6BAMvB;cAIf"}
@@ -1,5 +1,6 @@
1
+ import "./data-transform-CrpmG4uJ.mjs";
1
2
  import "./shared-Bxkt8pNO.mjs";
2
3
  import "./op-factory-call-C3bWXKSP.mjs";
3
- import "./postgres-migration-BjA3Zmts.mjs";
4
- import { t as TypeScriptRenderablePostgresMigration } from "./planner-produced-postgres-migration-CRRTno6Z.mjs";
4
+ import "./postgres-migration-BFjbb25b.mjs";
5
+ import { t as TypeScriptRenderablePostgresMigration } from "./planner-produced-postgres-migration-M3EfhWSS.mjs";
5
6
  export { TypeScriptRenderablePostgresMigration };
@@ -1,3 +1,3 @@
1
- import { t as TypeScriptRenderablePostgresMigration } from "./planner-produced-postgres-migration-DSSPq8QS.mjs";
1
+ import { t as TypeScriptRenderablePostgresMigration } from "./planner-produced-postgres-migration-Bi-RWO4-.mjs";
2
2
 
3
3
  export { TypeScriptRenderablePostgresMigration };
@@ -1,10 +1,12 @@
1
+ import "./data-transform-CrpmG4uJ.mjs";
1
2
  import "./shared-Bxkt8pNO.mjs";
2
3
  import "./op-factory-call-C3bWXKSP.mjs";
3
- import "./postgres-migration-BjA3Zmts.mjs";
4
- import { t as TypeScriptRenderablePostgresMigration } from "./planner-produced-postgres-migration-CRRTno6Z.mjs";
4
+ import "./postgres-migration-BFjbb25b.mjs";
5
+ import { t as TypeScriptRenderablePostgresMigration } from "./planner-produced-postgres-migration-M3EfhWSS.mjs";
5
6
  import { MigrationOperationPolicy, SqlPlannerFailureResult } from "@prisma-next/family-sql/control";
6
- import { MigrationPlanWithAuthoringSurface, MigrationPlanner, MigrationScaffoldContext } from "@prisma-next/framework-components/control";
7
+ import { Contract } from "@prisma-next/contract/types";
7
8
  import { TargetBoundComponentDescriptor } from "@prisma-next/framework-components/components";
9
+ import { MigrationPlanWithAuthoringSurface, MigrationPlanner, MigrationScaffoldContext } from "@prisma-next/framework-components/control";
8
10
 
9
11
  //#region src/core/migrations/planner.d.ts
10
12
  interface PlannerConfig {
@@ -45,16 +47,21 @@ declare class PostgresMigrationPlanner implements MigrationPlanner<'sql', 'postg
45
47
  readonly contract: unknown;
46
48
  readonly schema: unknown;
47
49
  readonly policy: MigrationOperationPolicy;
48
- readonly fromHash?: string;
49
50
  /**
50
51
  * The "from" contract (state the planner assumes the database starts
51
- * at). Only `migration plan` supplies this; `db update` / `db init`
52
- * reconcile against the live schema with no old contract. When present
53
- * alongside the `'data'` operation class, strategies that need from/to
54
- * column shape comparisons (unsafe type change, nullability tightening)
55
- * activate.
52
+ * at), or `null` for reconciliation flows. Only `migration plan` ever
53
+ * supplies a non-null value; `db update` / `db init` reconcile against
54
+ * the live schema and pass `null`. When present alongside the
55
+ * `'data'` operation class, strategies that need from/to column-shape
56
+ * comparisons (unsafe type change, nullability tightening) activate.
57
+ *
58
+ * Typed as the framework `Contract | null` to satisfy the
59
+ * `MigrationPlanner` interface contract; `planSql` narrows to the SQL
60
+ * shape via `SqlMigrationPlannerPlanOptions`. Used to populate
61
+ * `describe().from` on the produced plan as
62
+ * `fromContract?.storage.storageHash ?? null`.
56
63
  */
57
- readonly fromContract?: unknown;
64
+ readonly fromContract: Contract | null;
58
65
  readonly schemaName?: string;
59
66
  readonly frameworkComponents: ReadonlyArray<TargetBoundComponentDescriptor<'sql', string>>;
60
67
  }): PostgresPlanResult;
@@ -1 +1 @@
1
- {"version":3,"file":"planner.d.mts","names":[],"sources":["../src/core/migrations/planner.ts"],"sourcesContent":[],"mappings":";;;;;;;;;UAkCU,aAAA;;;iBAQM,8BAAA,UACN,QAAQ,iBACf;;AA3B2F;AAyB9F;;;;;AAgBY,KAAA,kBAAA,GAAkB;EAoBjB,SAAA,IAAA,EAAA,SAAA;EAC0B,SAAA,IAAA,EApBQ,qCAoBR;CAKlB,GAxBjB,uBAwBiB;;;;;;;;;;;;;;;;;cANR,wBAAA,YAAoC;;sBACV;;;;qBAKlB;;;;;;;;;;;;kCAYa,cAAc;MAC1C;0BAIoB,2BAA2B"}
1
+ {"version":3,"file":"planner.d.mts","names":[],"sources":["../src/core/migrations/planner.ts"],"sourcesContent":[],"mappings":";;;;;;;;;;;UAmCU,aAAA;;;iBAQM,8BAAA,UACN,QAAQ,iBACf;;;AA3B2F;AAyB9F;;;;AAE2B,KAcf,kBAAA,GAde;EAcf,SAAA,IAAA,EAAA,SAAkB;EAoBjB,SAAA,IAAA,EAnBkC,qCAmBT;CACC,GAnBnC,uBAmBmC;;;;;;;;;;;;;;;;;cAD1B,wBAAA,YAAoC;;sBACV;;;;qBAKlB;;;;;;;;;;;;;;;2BAeM;;kCAEO,cAAc;MAC1C;0BAIoB,2BAA2B"}
package/dist/planner.mjs CHANGED
@@ -1,4 +1,4 @@
1
1
  import "./issue-planner-CFjB0_oO.mjs";
2
- import { t as createPostgresMigrationPlanner } from "./planner-CLUvVhUN.mjs";
2
+ import { t as createPostgresMigrationPlanner } from "./planner-Cm-ZLutk.mjs";
3
3
 
4
4
  export { createPostgresMigrationPlanner };
@@ -1,5 +1,6 @@
1
1
  import { t as PostgresPlanTargetDetails } from "./planner-target-details-DH-azLu-.mjs";
2
- import { n as DataTransformOptions, r as PostgresDataTransformOperation } from "./data-transform-CxFRBIUp.mjs";
2
+ import { n as DataTransformOptions } from "./data-transform-CrpmG4uJ.mjs";
3
+ import { SqlMigrationPlanOperation } from "@prisma-next/family-sql/control";
3
4
  import { Migration } from "@prisma-next/family-sql/migration";
4
5
  import { Contract } from "@prisma-next/contract/types";
5
6
  import { SqlStorage } from "@prisma-next/sql-contract/types";
@@ -43,8 +44,8 @@ declare abstract class PostgresMigration extends Migration<PostgresPlanTargetDet
43
44
  * supplies the stored control adapter. Authors call this from inside
44
45
  * `get operations()`; the adapter argument is hidden from the call site.
45
46
  */
46
- protected dataTransform<TContract extends Contract<SqlStorage>>(contract: TContract, name: string, options: DataTransformOptions): PostgresDataTransformOperation;
47
+ protected dataTransform<TContract extends Contract<SqlStorage>>(contract: TContract, name: string, options: DataTransformOptions): SqlMigrationPlanOperation<PostgresPlanTargetDetails>;
47
48
  }
48
49
  //#endregion
49
50
  export { PostgresMigration as t };
50
- //# sourceMappingURL=postgres-migration-BjA3Zmts.d.mts.map
51
+ //# sourceMappingURL=postgres-migration-BFjbb25b.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"postgres-migration-BFjbb25b.d.mts","names":[],"sources":["../src/core/migrations/postgres-migration.ts"],"sourcesContent":[],"mappings":";;;;;;;;;;;;;AA8BA;;;;;;;;;;;;;;;;;;uBAAsB,iBAAA,SAA0B,UAC9C;;;;;;;;qCAWmC;sBAEf;;;;;;4CAesB,SAAS,uBACvC,kCAED,uBACR,0BAA0B"}
@@ -1,5 +1,5 @@
1
1
  import { t as errorPostgresMigrationStackMissing } from "./errors-AFvEPZ1R.mjs";
2
- import { t as dataTransform } from "./data-transform-VfEGzXWt.mjs";
2
+ import { t as dataTransform } from "./data-transform-Be_i_DBc.mjs";
3
3
  import { Migration } from "@prisma-next/family-sql/migration";
4
4
 
5
5
  //#region src/core/migrations/postgres-migration.ts
@@ -49,4 +49,4 @@ var PostgresMigration = class extends Migration {
49
49
 
50
50
  //#endregion
51
51
  export { PostgresMigration as t };
52
- //# sourceMappingURL=postgres-migration-qtmtbONe.mjs.map
52
+ //# sourceMappingURL=postgres-migration-BS9vQW97.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"postgres-migration-BS9vQW97.mjs","names":["SqlMigration"],"sources":["../src/core/migrations/postgres-migration.ts"],"sourcesContent":["import type { Contract } from '@prisma-next/contract/types';\nimport type { SqlMigrationPlanOperation } from '@prisma-next/family-sql/control';\nimport type { SqlControlAdapter } from '@prisma-next/family-sql/control-adapter';\nimport { Migration as SqlMigration } from '@prisma-next/family-sql/migration';\nimport type { ControlStack } from '@prisma-next/framework-components/control';\nimport type { SqlStorage } from '@prisma-next/sql-contract/types';\nimport { errorPostgresMigrationStackMissing } from '../errors';\nimport { type DataTransformOptions, dataTransform } from './operations/data-transform';\nimport type { PostgresPlanTargetDetails } from './planner-target-details';\n\n/**\n * Target-owned base class for Postgres migrations.\n *\n * Fixes the `SqlMigration` generic to `PostgresPlanTargetDetails` and the\n * abstract `targetId` to the Postgres target-id string literal, so both\n * user-authored migrations and renderer-generated scaffolds (the output of\n * `renderCallsToTypeScript`) can extend `PostgresMigration` directly without\n * redeclaring target-local identity.\n *\n * Mirrors `MongoMigration` in `@prisma-next/family-mongo`: the renderer\n * emits `extends Migration` against a target-specific re-export of this\n * class from `@prisma-next/target-postgres/migration`, keeping the\n * authoring surface target-scoped rather than family-scoped.\n *\n * The constructor materializes a single Postgres `SqlControlAdapter` from\n * `stack.adapter.create(stack)` and stores it; the protected `dataTransform`\n * instance method forwards to the free `dataTransform` factory with that\n * stored adapter, so user migrations can write `this.dataTransform(...)`\n * without threading the adapter through every call.\n */\nexport abstract class PostgresMigration extends SqlMigration<\n PostgresPlanTargetDetails,\n 'postgres'\n> {\n readonly targetId = 'postgres' as const;\n\n /**\n * Materialized Postgres control adapter, created once per migration\n * instance from the injected stack. `undefined` only when the migration\n * was instantiated without a stack (test fixtures); `dataTransform`\n * throws in that case to surface the misuse.\n */\n protected readonly controlAdapter: SqlControlAdapter<'postgres'> | undefined;\n\n constructor(stack?: ControlStack<'sql', 'postgres'>) {\n super(stack);\n // The descriptor `create()` is typed as the wider `ControlAdapterInstance`;\n // the Postgres descriptor concretely returns a `SqlControlAdapter<'postgres'>`,\n // so the cast holds for any Postgres-target stack assembled at runtime.\n this.controlAdapter = stack?.adapter\n ? (stack.adapter.create(stack) as SqlControlAdapter<'postgres'>)\n : undefined;\n }\n\n /**\n * Instance-method wrapper around the free `dataTransform` factory that\n * supplies the stored control adapter. Authors call this from inside\n * `get operations()`; the adapter argument is hidden from the call site.\n */\n protected dataTransform<TContract extends Contract<SqlStorage>>(\n contract: TContract,\n name: string,\n options: DataTransformOptions,\n ): SqlMigrationPlanOperation<PostgresPlanTargetDetails> {\n if (!this.controlAdapter) {\n throw errorPostgresMigrationStackMissing();\n }\n return dataTransform(contract, name, options, this.controlAdapter);\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AA8BA,IAAsB,oBAAtB,cAAgDA,UAG9C;CACA,AAAS,WAAW;;;;;;;CAQpB,AAAmB;CAEnB,YAAY,OAAyC;AACnD,QAAM,MAAM;AAIZ,OAAK,iBAAiB,OAAO,UACxB,MAAM,QAAQ,OAAO,MAAM,GAC5B;;;;;;;CAQN,AAAU,cACR,UACA,MACA,SACsD;AACtD,MAAI,CAAC,KAAK,eACR,OAAM,oCAAoC;AAE5C,SAAO,cAAc,UAAU,MAAM,SAAS,KAAK,eAAe"}
@@ -68,7 +68,6 @@ function buildDescribeMethod(meta) {
68
68
  lines.push(" return {");
69
69
  lines.push(` from: ${JSON.stringify(meta.from)},`);
70
70
  lines.push(` to: ${JSON.stringify(meta.to)},`);
71
- if (meta.kind) lines.push(` kind: ${JSON.stringify(meta.kind)},`);
72
71
  if (meta.labels && meta.labels.length > 0) lines.push(` labels: ${jsonToTsSource(meta.labels)},`);
73
72
  lines.push(" };");
74
73
  lines.push(" }");
@@ -82,4 +81,4 @@ function indent(text, spaces) {
82
81
 
83
82
  //#endregion
84
83
  export { renderCallsToTypeScript as t };
85
- //# sourceMappingURL=render-typescript-1rF_SB4g.mjs.map
84
+ //# sourceMappingURL=render-typescript-Co3Emwgz.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"render-typescript-Co3Emwgz.mjs","names":["BASE_IMPORTS: readonly ImportRequirement[]","requirements: ImportRequirement[]","lines: string[]"],"sources":["../src/core/migrations/render-typescript.ts"],"sourcesContent":["/**\n * Polymorphic TypeScript emitter for the Postgres migration IR.\n *\n * Each `PostgresOpFactoryCall` renders itself via `renderTypeScript()` and\n * declares its own `importRequirements()`; this file just composes the module\n * source around those contributions. The design mirrors the Mongo target's\n * `render-typescript.ts` deliberately — byte-for-byte alignment isn't required\n * (different factory module specifiers, different base-class name) but the\n * shape is, so future consolidation to a framework-level helper is mechanical.\n */\n\nimport { detectScaffoldRuntime, shebangLineFor } from '@prisma-next/migration-tools/migration-ts';\nimport { type ImportRequirement, jsonToTsSource, renderImports } from '@prisma-next/ts-render';\nimport type { PostgresOpFactoryCall } from './op-factory-call';\n\nexport interface RenderMigrationMeta {\n readonly from: string | null;\n readonly to: string;\n readonly labels?: readonly string[];\n}\n\n/**\n * Always-present base imports for the rendered scaffold. Both come from\n * `@prisma-next/target-postgres/migration` so an authored Postgres\n * `migration.ts` only needs a single dependency for its base class and\n * its CLI entrypoint:\n *\n * - `Migration` — the target-owned re-export fixes the `SqlMigration`\n * generic to `PostgresPlanTargetDetails` and the abstract `targetId`\n * to `'postgres'`, so user-authored migrations don't need to thread\n * target-details or redeclare `targetId`.\n * - `MigrationCLI` — the migration-file CLI entrypoint, re-exported from\n * `@prisma-next/cli/migration-cli`. Loads `prisma-next.config.ts`,\n * assembles a `ControlStack`, and instantiates the migration class.\n * The migration file owns this dependency directly: pulling CLI\n * machinery in at script run time is acceptable because the script's\n * whole purpose is to be invoked from the project that owns the\n * config.\n */\nconst BASE_IMPORTS: readonly ImportRequirement[] = [\n { moduleSpecifier: '@prisma-next/target-postgres/migration', symbol: 'Migration' },\n { moduleSpecifier: '@prisma-next/target-postgres/migration', symbol: 'MigrationCLI' },\n];\n\nexport function renderCallsToTypeScript(\n calls: ReadonlyArray<PostgresOpFactoryCall>,\n meta: RenderMigrationMeta,\n): string {\n const imports = buildImports(calls);\n const operationsBody = calls.map((c) => c.renderTypeScript()).join(',\\n');\n\n return [\n shebangLineFor(detectScaffoldRuntime()),\n imports,\n '',\n 'export default class M extends Migration {',\n buildDescribeMethod(meta),\n ' override get operations() {',\n ' return [',\n indent(operationsBody, 6),\n ' ];',\n ' }',\n '}',\n '',\n 'MigrationCLI.run(import.meta.url, M);',\n '',\n ].join('\\n');\n}\n\nfunction buildImports(calls: ReadonlyArray<PostgresOpFactoryCall>): string {\n const requirements: ImportRequirement[] = [...BASE_IMPORTS];\n for (const call of calls) {\n for (const req of call.importRequirements()) {\n requirements.push(req);\n }\n }\n return renderImports(requirements);\n}\n\nfunction buildDescribeMethod(meta: RenderMigrationMeta): string {\n const lines: string[] = [];\n lines.push(' override describe() {');\n lines.push(' return {');\n lines.push(` from: ${JSON.stringify(meta.from)},`);\n lines.push(` to: ${JSON.stringify(meta.to)},`);\n if (meta.labels && meta.labels.length > 0) {\n lines.push(` labels: ${jsonToTsSource(meta.labels)},`);\n }\n lines.push(' };');\n lines.push(' }');\n lines.push('');\n return lines.join('\\n');\n}\n\nfunction indent(text: string, spaces: number): string {\n const pad = ' '.repeat(spaces);\n return text\n .split('\\n')\n .map((line) => (line.trim() ? `${pad}${line}` : line))\n .join('\\n');\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAuCA,MAAMA,eAA6C,CACjD;CAAE,iBAAiB;CAA0C,QAAQ;CAAa,EAClF;CAAE,iBAAiB;CAA0C,QAAQ;CAAgB,CACtF;AAED,SAAgB,wBACd,OACA,MACQ;CACR,MAAM,UAAU,aAAa,MAAM;CACnC,MAAM,iBAAiB,MAAM,KAAK,MAAM,EAAE,kBAAkB,CAAC,CAAC,KAAK,MAAM;AAEzE,QAAO;EACL,eAAe,uBAAuB,CAAC;EACvC;EACA;EACA;EACA,oBAAoB,KAAK;EACzB;EACA;EACA,OAAO,gBAAgB,EAAE;EACzB;EACA;EACA;EACA;EACA;EACA;EACD,CAAC,KAAK,KAAK;;AAGd,SAAS,aAAa,OAAqD;CACzE,MAAMC,eAAoC,CAAC,GAAG,aAAa;AAC3D,MAAK,MAAM,QAAQ,MACjB,MAAK,MAAM,OAAO,KAAK,oBAAoB,CACzC,cAAa,KAAK,IAAI;AAG1B,QAAO,cAAc,aAAa;;AAGpC,SAAS,oBAAoB,MAAmC;CAC9D,MAAMC,QAAkB,EAAE;AAC1B,OAAM,KAAK,0BAA0B;AACrC,OAAM,KAAK,eAAe;AAC1B,OAAM,KAAK,eAAe,KAAK,UAAU,KAAK,KAAK,CAAC,GAAG;AACvD,OAAM,KAAK,aAAa,KAAK,UAAU,KAAK,GAAG,CAAC,GAAG;AACnD,KAAI,KAAK,UAAU,KAAK,OAAO,SAAS,EACtC,OAAM,KAAK,iBAAiB,eAAe,KAAK,OAAO,CAAC,GAAG;AAE7D,OAAM,KAAK,SAAS;AACpB,OAAM,KAAK,MAAM;AACjB,OAAM,KAAK,GAAG;AACd,QAAO,MAAM,KAAK,KAAK;;AAGzB,SAAS,OAAO,MAAc,QAAwB;CACpD,MAAM,MAAM,IAAI,OAAO,OAAO;AAC9B,QAAO,KACJ,MAAM,KAAK,CACX,KAAK,SAAU,KAAK,MAAM,GAAG,GAAG,MAAM,SAAS,KAAM,CACrD,KAAK,KAAK"}
@@ -4,9 +4,8 @@ import { b as PostgresOpFactoryCall } from "./op-factory-call-C3bWXKSP.mjs";
4
4
  //#region src/core/migrations/render-typescript.d.ts
5
5
 
6
6
  interface RenderMigrationMeta {
7
- readonly from: string;
7
+ readonly from: string | null;
8
8
  readonly to: string;
9
- readonly kind?: string;
10
9
  readonly labels?: readonly string[];
11
10
  }
12
11
  declare function renderCallsToTypeScript(calls: ReadonlyArray<PostgresOpFactoryCall>, meta: RenderMigrationMeta): string;
@@ -1 +1 @@
1
- {"version":3,"file":"render-typescript.d.mts","names":[],"sources":["../src/core/migrations/render-typescript.ts"],"sourcesContent":[],"mappings":";;;;;UAeiB,mBAAA;;;;;;iBA8BD,uBAAA,QACP,cAAc,8BACf"}
1
+ {"version":3,"file":"render-typescript.d.mts","names":[],"sources":["../src/core/migrations/render-typescript.ts"],"sourcesContent":[],"mappings":";;;;;UAeiB,mBAAA;;;;;iBA6BD,uBAAA,QACP,cAAc,8BACf"}
@@ -1,3 +1,3 @@
1
- import { t as renderCallsToTypeScript } from "./render-typescript-1rF_SB4g.mjs";
1
+ import { t as renderCallsToTypeScript } from "./render-typescript-Co3Emwgz.mjs";
2
2
 
3
3
  export { renderCallsToTypeScript };
package/dist/runtime.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { t as postgresTargetDescriptorMeta } from "./descriptor-meta-BVoVtyp-.mjs";
1
+ import { t as postgresTargetDescriptorMeta } from "./descriptor-meta-Ieg1XLOs.mjs";
2
2
  import { createCodecRegistry } from "@prisma-next/sql-relational-core/ast";
3
3
 
4
4
  //#region src/exports/runtime.ts
@@ -12,7 +12,8 @@ const ensureMarkerTableStatement = {
12
12
  canonical_version int,
13
13
  updated_at timestamptz not null default now(),
14
14
  app_tag text,
15
- meta jsonb not null default '{}'
15
+ meta jsonb not null default '{}',
16
+ invariants text[] not null default '{}'
16
17
  )`,
17
18
  params: []
18
19
  };
@@ -30,7 +31,7 @@ const ensureLedgerTableStatement = {
30
31
  )`,
31
32
  params: []
32
33
  };
33
- function buildWriteMarkerStatements(input) {
34
+ function buildMergeMarkerStatements(input) {
34
35
  const params = [
35
36
  1,
36
37
  input.storageHash,
@@ -38,7 +39,8 @@ function buildWriteMarkerStatements(input) {
38
39
  jsonParam(input.contractJson),
39
40
  input.canonicalVersion ?? null,
40
41
  input.appTag ?? null,
41
- jsonParam(input.meta ?? {})
42
+ jsonParam(input.meta ?? {}),
43
+ input.invariants
42
44
  ];
43
45
  return {
44
46
  insert: {
@@ -50,7 +52,8 @@ function buildWriteMarkerStatements(input) {
50
52
  canonical_version,
51
53
  updated_at,
52
54
  app_tag,
53
- meta
55
+ meta,
56
+ invariants
54
57
  ) values (
55
58
  $1,
56
59
  $2,
@@ -59,7 +62,8 @@ function buildWriteMarkerStatements(input) {
59
62
  $5,
60
63
  now(),
61
64
  $6,
62
- $7::jsonb
65
+ $7::jsonb,
66
+ $8::text[]
63
67
  )`,
64
68
  params
65
69
  },
@@ -71,7 +75,8 @@ function buildWriteMarkerStatements(input) {
71
75
  canonical_version = $5,
72
76
  updated_at = now(),
73
77
  app_tag = $6,
74
- meta = $7::jsonb
78
+ meta = $7::jsonb,
79
+ invariants = array(select distinct unnest(invariants || $8::text[]) order by 1)
75
80
  where id = $1`,
76
81
  params
77
82
  }
@@ -112,5 +117,5 @@ function jsonParam(value) {
112
117
  }
113
118
 
114
119
  //#endregion
115
- export { ensurePrismaContractSchemaStatement as a, ensureMarkerTableStatement as i, buildWriteMarkerStatements as n, ensureLedgerTableStatement as r, buildLedgerInsertStatement as t };
116
- //# sourceMappingURL=statement-builders-BPnmt6wx.mjs.map
120
+ export { ensurePrismaContractSchemaStatement as a, ensureMarkerTableStatement as i, buildMergeMarkerStatements as n, ensureLedgerTableStatement as r, buildLedgerInsertStatement as t };
121
+ //# sourceMappingURL=statement-builders-CHqCtSfe.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"statement-builders-CHqCtSfe.mjs","names":["ensurePrismaContractSchemaStatement: SqlStatement","ensureMarkerTableStatement: SqlStatement","ensureLedgerTableStatement: SqlStatement","params: readonly unknown[]"],"sources":["../src/core/migrations/statement-builders.ts"],"sourcesContent":["export interface SqlStatement {\n readonly sql: string;\n readonly params: readonly unknown[];\n}\n\nexport const ensurePrismaContractSchemaStatement: SqlStatement = {\n sql: 'create schema if not exists prisma_contract',\n params: [],\n};\n\nexport const ensureMarkerTableStatement: SqlStatement = {\n sql: `create table if not exists prisma_contract.marker (\n id smallint primary key default 1,\n core_hash text not null,\n profile_hash text not null,\n contract_json jsonb,\n canonical_version int,\n updated_at timestamptz not null default now(),\n app_tag text,\n meta jsonb not null default '{}',\n invariants text[] not null default '{}'\n )`,\n params: [],\n};\n\nexport const ensureLedgerTableStatement: SqlStatement = {\n sql: `create table if not exists prisma_contract.ledger (\n id bigserial primary key,\n created_at timestamptz not null default now(),\n origin_core_hash text,\n origin_profile_hash text,\n destination_core_hash text not null,\n destination_profile_hash text,\n contract_json_before jsonb,\n contract_json_after jsonb,\n operations jsonb not null\n )`,\n params: [],\n};\n\nexport interface MergeMarkerInput {\n readonly storageHash: string;\n readonly profileHash: string;\n readonly contractJson?: unknown;\n readonly canonicalVersion?: number | null;\n readonly appTag?: string | null;\n readonly meta?: Record<string, unknown>;\n /**\n * Invariants to merge into `marker.invariants`. INSERT writes them as\n * the initial value (callers are expected to pass a sorted, deduped\n * array). UPDATE merges them with the existing column server-side via\n * a single atomic SQL expression.\n */\n readonly invariants: readonly string[];\n}\n\nexport function buildMergeMarkerStatements(input: MergeMarkerInput): {\n readonly insert: SqlStatement;\n readonly update: SqlStatement;\n} {\n const params: readonly unknown[] = [\n 1,\n input.storageHash,\n input.profileHash,\n jsonParam(input.contractJson),\n input.canonicalVersion ?? null,\n input.appTag ?? null,\n jsonParam(input.meta ?? {}),\n input.invariants,\n ];\n\n return {\n insert: {\n sql: `insert into prisma_contract.marker (\n id,\n core_hash,\n profile_hash,\n contract_json,\n canonical_version,\n updated_at,\n app_tag,\n meta,\n invariants\n ) values (\n $1,\n $2,\n $3,\n $4::jsonb,\n $5,\n now(),\n $6,\n $7::jsonb,\n $8::text[]\n )`,\n params,\n },\n update: {\n // `invariants = array(select distinct unnest(invariants || $8::text[]) order by 1)`\n // reads the current column value under the UPDATE's row lock, unions\n // with the incoming array, dedupes, and sorts ascending — single\n // statement, atomic, no read-then-write window.\n sql: `update prisma_contract.marker set\n core_hash = $2,\n profile_hash = $3,\n contract_json = $4::jsonb,\n canonical_version = $5,\n updated_at = now(),\n app_tag = $6,\n meta = $7::jsonb,\n invariants = array(select distinct unnest(invariants || $8::text[]) order by 1)\n where id = $1`,\n params,\n },\n };\n}\n\nexport interface LedgerInsertInput {\n readonly originStorageHash?: string | null;\n readonly originProfileHash?: string | null;\n readonly destinationStorageHash: string;\n readonly destinationProfileHash?: string | null;\n readonly contractJsonBefore?: unknown;\n readonly contractJsonAfter?: unknown;\n readonly operations: unknown;\n}\n\nexport function buildLedgerInsertStatement(input: LedgerInsertInput): SqlStatement {\n return {\n sql: `insert into prisma_contract.ledger (\n origin_core_hash,\n origin_profile_hash,\n destination_core_hash,\n destination_profile_hash,\n contract_json_before,\n contract_json_after,\n operations\n ) values (\n $1,\n $2,\n $3,\n $4,\n $5::jsonb,\n $6::jsonb,\n $7::jsonb\n )`,\n params: [\n input.originStorageHash ?? null,\n input.originProfileHash ?? null,\n input.destinationStorageHash,\n input.destinationProfileHash ?? null,\n jsonParam(input.contractJsonBefore),\n jsonParam(input.contractJsonAfter),\n jsonParam(input.operations),\n ],\n };\n}\n\nfunction jsonParam(value: unknown): string {\n return JSON.stringify(value ?? null);\n}\n"],"mappings":";AAKA,MAAaA,sCAAoD;CAC/D,KAAK;CACL,QAAQ,EAAE;CACX;AAED,MAAaC,6BAA2C;CACtD,KAAK;;;;;;;;;;;CAWL,QAAQ,EAAE;CACX;AAED,MAAaC,6BAA2C;CACtD,KAAK;;;;;;;;;;;CAWL,QAAQ,EAAE;CACX;AAkBD,SAAgB,2BAA2B,OAGzC;CACA,MAAMC,SAA6B;EACjC;EACA,MAAM;EACN,MAAM;EACN,UAAU,MAAM,aAAa;EAC7B,MAAM,oBAAoB;EAC1B,MAAM,UAAU;EAChB,UAAU,MAAM,QAAQ,EAAE,CAAC;EAC3B,MAAM;EACP;AAED,QAAO;EACL,QAAQ;GACN,KAAK;;;;;;;;;;;;;;;;;;;;;GAqBL;GACD;EACD,QAAQ;GAKN,KAAK;;;;;;;;;;GAUL;GACD;EACF;;AAaH,SAAgB,2BAA2B,OAAwC;AACjF,QAAO;EACL,KAAK;;;;;;;;;;;;;;;;;EAiBL,QAAQ;GACN,MAAM,qBAAqB;GAC3B,MAAM,qBAAqB;GAC3B,MAAM;GACN,MAAM,0BAA0B;GAChC,UAAU,MAAM,mBAAmB;GACnC,UAAU,MAAM,kBAAkB;GAClC,UAAU,MAAM,WAAW;GAC5B;EACF;;AAGH,SAAS,UAAU,OAAwB;AACzC,QAAO,KAAK,UAAU,SAAS,KAAK"}
@@ -6,18 +6,25 @@ interface SqlStatement {
6
6
  declare const ensurePrismaContractSchemaStatement: SqlStatement;
7
7
  declare const ensureMarkerTableStatement: SqlStatement;
8
8
  declare const ensureLedgerTableStatement: SqlStatement;
9
- interface WriteMarkerInput {
9
+ interface MergeMarkerInput {
10
10
  readonly storageHash: string;
11
11
  readonly profileHash: string;
12
12
  readonly contractJson?: unknown;
13
13
  readonly canonicalVersion?: number | null;
14
14
  readonly appTag?: string | null;
15
15
  readonly meta?: Record<string, unknown>;
16
+ /**
17
+ * Invariants to merge into `marker.invariants`. INSERT writes them as
18
+ * the initial value (callers are expected to pass a sorted, deduped
19
+ * array). UPDATE merges them with the existing column server-side via
20
+ * a single atomic SQL expression.
21
+ */
22
+ readonly invariants: readonly string[];
16
23
  }
17
- declare function buildWriteMarkerStatements(input: WriteMarkerInput): {
24
+ declare function buildMergeMarkerStatements(input: MergeMarkerInput): {
18
25
  readonly insert: SqlStatement;
19
26
  readonly update: SqlStatement;
20
27
  };
21
28
  //#endregion
22
- export { type SqlStatement, buildWriteMarkerStatements, ensureLedgerTableStatement, ensureMarkerTableStatement, ensurePrismaContractSchemaStatement };
29
+ export { type SqlStatement, buildMergeMarkerStatements, ensureLedgerTableStatement, ensureMarkerTableStatement, ensurePrismaContractSchemaStatement };
23
30
  //# sourceMappingURL=statement-builders.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"statement-builders.d.mts","names":[],"sources":["../src/core/migrations/statement-builders.ts"],"sourcesContent":[],"mappings":";UAAiB,YAAA;EAAA,SAAA,GAAA,EAAA,MAAY;EAKhB,SAAA,MAAA,EAAA,SAAA,OAAA,EAAA;AAKb;AAca,cAnBA,mCAmB4B,EAnBS,YAgCjD;AAEgB,cA7BJ,0BAmCW,EAnCiB,YAmCjB;AAGR,cAxBH,0BAwB6B,EAxBD,YAwBC;AAAQ,UATjC,gBAAA,CASiC;EAC/B,SAAA,WAAA,EAAA,MAAA;EACA,SAAA,WAAA,EAAA,MAAA;EAAY,SAAA,YAAA,CAAA,EAAA,OAAA;;;kBALb;;iBAGF,0BAAA,QAAkC;mBAC/B;mBACA"}
1
+ {"version":3,"file":"statement-builders.d.mts","names":[],"sources":["../src/core/migrations/statement-builders.ts"],"sourcesContent":[],"mappings":";UAAiB,YAAA;EAAA,SAAA,GAAA,EAAA,MAAY;EAKhB,SAAA,MAAA,EAAA,SAAA,OAAA,EAAA;AAKb;AAea,cApBA,mCAoB4B,EApBS,YAiCjD;AAEgB,cA9BJ,0BAoCW,EApCiB,YAoCjB;AAUR,cA/BH,0BA+B6B,EA/BD,YA+BC;AAAQ,UAhBjC,gBAAA,CAgBiC;EAC/B,SAAA,WAAA,EAAA,MAAA;EACA,SAAA,WAAA,EAAA,MAAA;EAAY,SAAA,YAAA,CAAA,EAAA,OAAA;;;kBAZb;;;;;;;;;iBAUF,0BAAA,QAAkC;mBAC/B;mBACA"}
@@ -1,3 +1,3 @@
1
- import { a as ensurePrismaContractSchemaStatement, i as ensureMarkerTableStatement, n as buildWriteMarkerStatements, r as ensureLedgerTableStatement } from "./statement-builders-BPnmt6wx.mjs";
1
+ import { a as ensurePrismaContractSchemaStatement, i as ensureMarkerTableStatement, n as buildMergeMarkerStatements, r as ensureLedgerTableStatement } from "./statement-builders-CHqCtSfe.mjs";
2
2
 
3
- export { buildWriteMarkerStatements, ensureLedgerTableStatement, ensureMarkerTableStatement, ensurePrismaContractSchemaStatement };
3
+ export { buildMergeMarkerStatements, ensureLedgerTableStatement, ensureMarkerTableStatement, ensurePrismaContractSchemaStatement };
package/package.json CHANGED
@@ -1,25 +1,26 @@
1
1
  {
2
2
  "name": "@prisma-next/target-postgres",
3
- "version": "0.5.0-dev.6",
3
+ "version": "0.5.0-dev.60",
4
+ "license": "Apache-2.0",
4
5
  "type": "module",
5
6
  "sideEffects": false,
6
7
  "description": "Postgres target pack for Prisma Next",
7
8
  "dependencies": {
8
9
  "arktype": "^2.0.0",
9
10
  "pathe": "^2.0.3",
10
- "@prisma-next/contract": "0.5.0-dev.6",
11
- "@prisma-next/cli": "0.5.0-dev.6",
12
- "@prisma-next/errors": "0.5.0-dev.6",
13
- "@prisma-next/framework-components": "0.5.0-dev.6",
14
- "@prisma-next/family-sql": "0.5.0-dev.6",
15
- "@prisma-next/migration-tools": "0.5.0-dev.6",
16
- "@prisma-next/sql-contract": "0.5.0-dev.6",
17
- "@prisma-next/sql-operations": "0.5.0-dev.6",
18
- "@prisma-next/sql-errors": "0.5.0-dev.6",
19
- "@prisma-next/sql-relational-core": "0.5.0-dev.6",
20
- "@prisma-next/ts-render": "0.5.0-dev.6",
21
- "@prisma-next/sql-schema-ir": "0.5.0-dev.6",
22
- "@prisma-next/utils": "0.5.0-dev.6"
11
+ "@prisma-next/contract": "0.5.0-dev.60",
12
+ "@prisma-next/cli": "0.5.0-dev.60",
13
+ "@prisma-next/errors": "0.5.0-dev.60",
14
+ "@prisma-next/framework-components": "0.5.0-dev.60",
15
+ "@prisma-next/migration-tools": "0.5.0-dev.60",
16
+ "@prisma-next/family-sql": "0.5.0-dev.60",
17
+ "@prisma-next/ts-render": "0.5.0-dev.60",
18
+ "@prisma-next/sql-contract": "0.5.0-dev.60",
19
+ "@prisma-next/sql-errors": "0.5.0-dev.60",
20
+ "@prisma-next/sql-operations": "0.5.0-dev.60",
21
+ "@prisma-next/sql-relational-core": "0.5.0-dev.60",
22
+ "@prisma-next/sql-schema-ir": "0.5.0-dev.60",
23
+ "@prisma-next/utils": "0.5.0-dev.60"
23
24
  },
24
25
  "devDependencies": {
25
26
  "tsdown": "0.18.4",
@@ -1,3 +1,4 @@
1
+ import { temporalAuthoringPresets } from '@prisma-next/family-sql/control';
1
2
  import type {
2
3
  AuthoringFieldNamespace,
3
4
  AuthoringTypeNamespace,
@@ -89,15 +90,8 @@ export const postgresAuthoringFieldPresets = {
89
90
  nativeType: 'timestamptz',
90
91
  },
91
92
  },
92
- createdAt: {
93
- kind: 'fieldPreset',
94
- output: {
95
- codecId: 'pg/timestamptz@1',
96
- nativeType: 'timestamptz',
97
- default: {
98
- kind: 'function',
99
- expression: 'now()',
100
- },
101
- },
102
- },
93
+ temporal: temporalAuthoringPresets({
94
+ codecId: 'pg/timestamptz@1',
95
+ nativeType: 'timestamptz',
96
+ }),
103
97
  } as const satisfies AuthoringFieldNamespace;
@@ -28,3 +28,4 @@ export const PG_TIMETZ_CODEC_ID = 'pg/timetz@1' as const;
28
28
  export const PG_INTERVAL_CODEC_ID = 'pg/interval@1' as const;
29
29
  export const PG_JSON_CODEC_ID = 'pg/json@1' as const;
30
30
  export const PG_JSONB_CODEC_ID = 'pg/jsonb@1' as const;
31
+ export const PG_BYTEA_CODEC_ID = 'pg/bytea@1' as const;