@prisma-next/target-postgres 0.15.0-dev.9 → 0.16.0-dev.1

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 (176) hide show
  1. package/dist/{authoring-BtsOWgI3.mjs → authoring-34L18kA1.mjs} +18 -8
  2. package/dist/authoring-34L18kA1.mjs.map +1 -0
  3. package/dist/canonicalize-D1F4vUnP.d.mts.map +1 -1
  4. package/dist/{codec-ids-CI144z7g.d.mts → codec-ids-BswpvvND.d.mts} +3 -3
  5. package/dist/codec-ids-BswpvvND.d.mts.map +1 -0
  6. package/dist/{codec-ids-B10ZZHzw.mjs → codec-ids-D3G8K0YM.mjs} +3 -2
  7. package/dist/codec-ids-D3G8K0YM.mjs.map +1 -0
  8. package/dist/codec-ids.d.mts +2 -2
  9. package/dist/codec-ids.mjs +2 -2
  10. package/dist/{codec-types-CTfT4U4O.d.mts → codec-types-CQ07nOz-.d.mts} +4 -5
  11. package/dist/codec-types-CQ07nOz-.d.mts.map +1 -0
  12. package/dist/codec-types.d.mts +1 -1
  13. package/dist/{codecs-D7W9O0Xx.d.mts → codecs-G4DTY0F_.d.mts} +35 -7
  14. package/dist/codecs-G4DTY0F_.d.mts.map +1 -0
  15. package/dist/{codecs-DRbb26Or.mjs → codecs-TCsGgW-Y.mjs} +77 -5
  16. package/dist/codecs-TCsGgW-Y.mjs.map +1 -0
  17. package/dist/codecs.d.mts +2 -3
  18. package/dist/codecs.d.mts.map +1 -1
  19. package/dist/codecs.mjs +2 -2
  20. package/dist/contract-free.d.mts +2 -3
  21. package/dist/contract-free.d.mts.map +1 -1
  22. package/dist/contract-free.mjs +3 -3
  23. package/dist/{control-policy-UPteqwtU.mjs → control-policy-CZKdMztu.mjs} +4 -4
  24. package/dist/{control-policy-UPteqwtU.mjs.map → control-policy-CZKdMztu.mjs.map} +1 -1
  25. package/dist/control.d.mts +0 -1
  26. package/dist/control.d.mts.map +1 -1
  27. package/dist/control.mjs +74 -24
  28. package/dist/control.mjs.map +1 -1
  29. package/dist/data-transform-BOWpliq8.mjs.map +1 -1
  30. package/dist/{data-transform-DPzwBMhW.d.mts → data-transform-CGvE8yGx.d.mts} +1 -2
  31. package/dist/data-transform-CGvE8yGx.d.mts.map +1 -0
  32. package/dist/data-transform.d.mts +1 -1
  33. package/dist/{ddl-GTTOvjx_.mjs → ddl-DHXKzQ99.mjs} +3 -3
  34. package/dist/{ddl-GTTOvjx_.mjs.map → ddl-DHXKzQ99.mjs.map} +1 -1
  35. package/dist/ddl.d.mts +1 -1
  36. package/dist/default-normalizer-B9ZUiyUE.mjs +264 -0
  37. package/dist/default-normalizer-B9ZUiyUE.mjs.map +1 -0
  38. package/dist/default-normalizer.d.mts +14 -2
  39. package/dist/default-normalizer.d.mts.map +1 -1
  40. package/dist/default-normalizer.mjs +2 -248
  41. package/dist/{descriptor-meta-CFQKLXl_.mjs → descriptor-meta-qubYaxQA.mjs} +9 -4
  42. package/dist/descriptor-meta-qubYaxQA.mjs.map +1 -0
  43. package/dist/{diff-database-schema-47526Pv2.mjs → diff-database-schema-C-hnJ5mr.mjs} +9 -6
  44. package/dist/diff-database-schema-C-hnJ5mr.mjs.map +1 -0
  45. package/dist/diff-database-schema.d.mts +3 -3
  46. package/dist/diff-database-schema.d.mts.map +1 -1
  47. package/dist/diff-database-schema.mjs +1 -1
  48. package/dist/{errors-DO-w0EUS.mjs → errors-ByDS0xJL.mjs} +6 -6
  49. package/dist/errors-ByDS0xJL.mjs.map +1 -0
  50. package/dist/errors.d.mts +4 -4
  51. package/dist/errors.d.mts.map +1 -1
  52. package/dist/errors.mjs +1 -1
  53. package/dist/issue-planner.d.mts +1 -2
  54. package/dist/issue-planner.d.mts.map +1 -1
  55. package/dist/issue-planner.mjs +1 -1
  56. package/dist/migration.d.mts +3 -4
  57. package/dist/migration.d.mts.map +1 -1
  58. package/dist/migration.mjs +2 -2
  59. package/dist/native-type-normalizer.d.mts.map +1 -1
  60. package/dist/{nodes-Dv5eCSq9.d.mts → nodes-CQzM2hR0.d.mts} +1 -2
  61. package/dist/nodes-CQzM2hR0.d.mts.map +1 -0
  62. package/dist/{op-factory-call-Bn9zDx4_.d.mts → op-factory-call-DT7kdjVP.d.mts} +10 -7
  63. package/dist/op-factory-call-DT7kdjVP.d.mts.map +1 -0
  64. package/dist/{op-factory-call-C38NzvQD.mjs → op-factory-call-DuRj7WXX.mjs} +37 -16
  65. package/dist/{op-factory-call-C38NzvQD.mjs.map → op-factory-call-DuRj7WXX.mjs.map} +1 -1
  66. package/dist/op-factory-call.d.mts +2 -2
  67. package/dist/op-factory-call.mjs +2 -2
  68. package/dist/pack.d.mts +122 -6
  69. package/dist/pack.d.mts.map +1 -1
  70. package/dist/pack.mjs +1 -1
  71. package/dist/{planner-uHcFFWkx.mjs → planner-DPGxFcXo.mjs} +7 -7
  72. package/dist/{planner-uHcFFWkx.mjs.map → planner-DPGxFcXo.mjs.map} +1 -1
  73. package/dist/planner-ddl-builders.d.mts +1 -2
  74. package/dist/planner-ddl-builders.d.mts.map +1 -1
  75. package/dist/planner-identity-values.d.mts +0 -1
  76. package/dist/planner-identity-values.d.mts.map +1 -1
  77. package/dist/{planner-produced-postgres-migration-BEY1T0Xm.d.mts → planner-produced-postgres-migration-C-dwGdb2.d.mts} +2 -3
  78. package/dist/planner-produced-postgres-migration-C-dwGdb2.d.mts.map +1 -0
  79. package/dist/{planner-produced-postgres-migration-D7y-PEHK.mjs → planner-produced-postgres-migration-CFDpqWWE.mjs} +2 -2
  80. package/dist/planner-produced-postgres-migration-CFDpqWWE.mjs.map +1 -0
  81. package/dist/planner-produced-postgres-migration.d.mts +1 -1
  82. package/dist/planner-produced-postgres-migration.mjs +1 -1
  83. package/dist/planner-schema-lookup.d.mts +0 -1
  84. package/dist/planner-schema-lookup.d.mts.map +1 -1
  85. package/dist/{planner-sql-checks-zqNfs2XZ.mjs → planner-sql-checks-BuB877wH.mjs} +2 -2
  86. package/dist/{planner-sql-checks-zqNfs2XZ.mjs.map → planner-sql-checks-BuB877wH.mjs.map} +1 -1
  87. package/dist/planner-sql-checks.d.mts +0 -1
  88. package/dist/planner-sql-checks.d.mts.map +1 -1
  89. package/dist/planner-sql-checks.mjs +1 -1
  90. package/dist/planner-target-details-HkP4RrRO.d.mts.map +1 -1
  91. package/dist/planner.d.mts +3 -4
  92. package/dist/planner.d.mts.map +1 -1
  93. package/dist/planner.mjs +2 -2
  94. package/dist/{postgres-contract-view-C9j5cqP0.d.mts → postgres-contract-view-CeU7FJjW.d.mts} +4 -3
  95. package/dist/postgres-contract-view-CeU7FJjW.d.mts.map +1 -0
  96. package/dist/{postgres-contract-view-DM8sN1Ot.mjs → postgres-contract-view-DebHMqGR.mjs} +4 -4
  97. package/dist/{postgres-contract-view-DM8sN1Ot.mjs.map → postgres-contract-view-DebHMqGR.mjs.map} +1 -1
  98. package/dist/{postgres-database-schema-node-DJOTywwQ.d.mts → postgres-database-schema-node-DMXsIwAb.d.mts} +2 -3
  99. package/dist/postgres-database-schema-node-DMXsIwAb.d.mts.map +1 -0
  100. package/dist/{postgres-migration-arMSWU9b.mjs → postgres-migration-C_OPFhIF.mjs} +22 -6
  101. package/dist/postgres-migration-C_OPFhIF.mjs.map +1 -0
  102. package/dist/{postgres-migration-DbckK1su.d.mts → postgres-migration-DLIvzHjX.d.mts} +31 -7
  103. package/dist/postgres-migration-DLIvzHjX.d.mts.map +1 -0
  104. package/dist/{postgres-rls-policy--CSddvMR.d.mts → postgres-rls-policy-CYXdqG9B.d.mts} +1 -2
  105. package/dist/postgres-rls-policy-CYXdqG9B.d.mts.map +1 -0
  106. package/dist/{postgres-schema-Cm4DtiGA.mjs → postgres-schema-CewLYHB7.mjs} +2 -2
  107. package/dist/{postgres-schema-Cm4DtiGA.mjs.map → postgres-schema-CewLYHB7.mjs.map} +1 -1
  108. package/dist/{postgres-schema-DKq6s1P3.d.mts → postgres-schema-FdKRwe7X.d.mts} +3 -4
  109. package/dist/postgres-schema-FdKRwe7X.d.mts.map +1 -0
  110. package/dist/render-ops.d.mts +0 -1
  111. package/dist/render-ops.d.mts.map +1 -1
  112. package/dist/render-typescript.d.mts +0 -1
  113. package/dist/render-typescript.d.mts.map +1 -1
  114. package/dist/{resolve-ddl-schema-XyBaaenM.mjs → resolve-ddl-schema-D0wi_P9Q.mjs} +2 -2
  115. package/dist/{resolve-ddl-schema-XyBaaenM.mjs.map → resolve-ddl-schema-D0wi_P9Q.mjs.map} +1 -1
  116. package/dist/rls-canonicalize.d.mts +0 -1
  117. package/dist/rls-canonicalize.d.mts.map +1 -1
  118. package/dist/runtime.d.mts +1 -2
  119. package/dist/runtime.d.mts.map +1 -1
  120. package/dist/runtime.mjs +1 -1
  121. package/dist/schema-ir-annotations.d.mts +0 -1
  122. package/dist/schema-ir-annotations.d.mts.map +1 -1
  123. package/dist/schema-ir-annotations.mjs +1 -1
  124. package/dist/{schema-node-kinds-CrYzCR1i.d.mts → schema-node-kinds-DxvWh2Ic.d.mts} +1 -2
  125. package/dist/schema-node-kinds-DxvWh2Ic.d.mts.map +1 -0
  126. package/dist/sql-utils.d.mts.map +1 -1
  127. package/dist/{table-source-BvFo7gVs.d.mts → table-source-D5c2fxAQ.d.mts} +1 -2
  128. package/dist/table-source-D5c2fxAQ.d.mts.map +1 -0
  129. package/dist/{types-BDKkx8MA.d.mts → types-D2MLzLBD.d.mts} +1 -2
  130. package/dist/types-D2MLzLBD.d.mts.map +1 -0
  131. package/dist/types.d.mts +5 -5
  132. package/dist/types.mjs +1 -1
  133. package/package.json +21 -21
  134. package/src/core/authoring.ts +18 -5
  135. package/src/core/codec-helpers.ts +53 -1
  136. package/src/core/codec-ids.ts +1 -0
  137. package/src/core/codecs.ts +56 -3
  138. package/src/core/default-normalizer.ts +22 -0
  139. package/src/core/descriptor-meta.ts +2 -0
  140. package/src/core/errors.ts +5 -5
  141. package/src/core/index-types.ts +15 -0
  142. package/src/core/migrations/diff-database-schema.ts +3 -0
  143. package/src/core/migrations/op-factory-call.ts +40 -16
  144. package/src/core/migrations/operations/data-transform.ts +1 -1
  145. package/src/core/migrations/planner-produced-postgres-migration.ts +1 -1
  146. package/src/core/migrations/postgres-migration.ts +62 -2
  147. package/src/core/migrations/runner.ts +12 -11
  148. package/src/core/psl-infer/infer-psl-contract.ts +130 -12
  149. package/src/exports/codecs.ts +2 -0
  150. package/src/exports/control.ts +2 -0
  151. package/src/exports/default-normalizer.ts +1 -1
  152. package/src/exports/op-factory-call.ts +5 -0
  153. package/dist/authoring-BtsOWgI3.mjs.map +0 -1
  154. package/dist/codec-ids-B10ZZHzw.mjs.map +0 -1
  155. package/dist/codec-ids-CI144z7g.d.mts.map +0 -1
  156. package/dist/codec-types-CTfT4U4O.d.mts.map +0 -1
  157. package/dist/codecs-D7W9O0Xx.d.mts.map +0 -1
  158. package/dist/codecs-DRbb26Or.mjs.map +0 -1
  159. package/dist/data-transform-DPzwBMhW.d.mts.map +0 -1
  160. package/dist/default-normalizer.mjs.map +0 -1
  161. package/dist/descriptor-meta-CFQKLXl_.mjs.map +0 -1
  162. package/dist/diff-database-schema-47526Pv2.mjs.map +0 -1
  163. package/dist/errors-DO-w0EUS.mjs.map +0 -1
  164. package/dist/nodes-Dv5eCSq9.d.mts.map +0 -1
  165. package/dist/op-factory-call-Bn9zDx4_.d.mts.map +0 -1
  166. package/dist/planner-produced-postgres-migration-BEY1T0Xm.d.mts.map +0 -1
  167. package/dist/planner-produced-postgres-migration-D7y-PEHK.mjs.map +0 -1
  168. package/dist/postgres-contract-view-C9j5cqP0.d.mts.map +0 -1
  169. package/dist/postgres-database-schema-node-DJOTywwQ.d.mts.map +0 -1
  170. package/dist/postgres-migration-DbckK1su.d.mts.map +0 -1
  171. package/dist/postgres-migration-arMSWU9b.mjs.map +0 -1
  172. package/dist/postgres-rls-policy--CSddvMR.d.mts.map +0 -1
  173. package/dist/postgres-schema-DKq6s1P3.d.mts.map +0 -1
  174. package/dist/schema-node-kinds-CrYzCR1i.d.mts.map +0 -1
  175. package/dist/table-source-BvFo7gVs.d.mts.map +0 -1
  176. package/dist/types-BDKkx8MA.d.mts.map +0 -1
@@ -2,7 +2,6 @@ import { t as PostgresPlanTargetDetails } from "./planner-target-details-HkP4RrR
2
2
  import { StorageColumn } from "@prisma-next/sql-contract/types";
3
3
  import { SqlControlTargetDescriptor } from "@prisma-next/family-sql/control";
4
4
  import { ColumnDefault } from "@prisma-next/contract/types";
5
-
6
5
  //#region src/exports/control.d.ts
7
6
  declare function postgresRenderDefault(def: ColumnDefault, column: StorageColumn): string;
8
7
  declare const postgresTargetDescriptor: SqlControlTargetDescriptor<'postgres', PostgresPlanTargetDetails>;
@@ -1 +1 @@
1
- {"version":3,"file":"control.d.mts","names":[],"sources":["../src/exports/control.ts"],"mappings":";;;;;;iBA4BgB,qBAAA,CAAsB,GAAA,EAAK,aAAA,EAAe,MAAA,EAAQ,aAAa;AAAA,cAOzE,wBAAA,EAA0B,0BAA0B,aAAa,yBAAA"}
1
+ {"version":3,"file":"control.d.mts","names":[],"sources":["../src/exports/control.ts"],"mappings":";;;;;iBA6BgB,sBAAsB,KAAK,eAAe,QAAQ;cAO5D,0BAA0B,uCAAuC"}
package/dist/control.mjs CHANGED
@@ -1,10 +1,11 @@
1
- import { t as postgresTargetDescriptorMeta } from "./descriptor-meta-CFQKLXl_.mjs";
1
+ import { n as postgresResolveDefault } from "./default-normalizer-B9ZUiyUE.mjs";
2
+ import { t as postgresTargetDescriptorMeta } from "./descriptor-meta-qubYaxQA.mjs";
2
3
  import { a as postgresDiffSubjectGranularity, i as postgresDiffSubjectEntityKind } from "./postgres-table-schema-node-D6LvInCe.mjs";
3
4
  import { i as PostgresDatabaseSchemaNode } from "./postgres-role-schema-node-bg32e7I-.mjs";
4
- import { n as diffPostgresSchema, r as contractToPostgresDatabaseSchemaNode } from "./diff-database-schema-47526Pv2.mjs";
5
+ import { n as diffPostgresSchema, r as contractToPostgresDatabaseSchemaNode } from "./diff-database-schema-C-hnJ5mr.mjs";
5
6
  import { r as renderDefaultLiteral } from "./planner-ddl-builders-BKlmGDJl.mjs";
6
- import { n as PostgresContractSerializer } from "./postgres-contract-view-DM8sN1Ot.mjs";
7
- import { t as createPostgresMigrationPlanner } from "./planner-uHcFFWkx.mjs";
7
+ import { n as PostgresContractSerializer } from "./postgres-contract-view-DebHMqGR.mjs";
8
+ import { t as createPostgresMigrationPlanner } from "./planner-DPGxFcXo.mjs";
8
9
  import { UNBOUND_NAMESPACE_ID, coordinateKey, elementCoordinates } from "@prisma-next/framework-components/ir";
9
10
  import { blindCast } from "@prisma-next/utils/casts";
10
11
  import { buildNativeTypeExpander, runnerFailure, runnerSuccess } from "@prisma-next/family-sql/control";
@@ -87,7 +88,7 @@ var PostgresMigrationRunner = class {
87
88
  strict: options.strictVerification ?? true,
88
89
  frameworkComponents: options.frameworkComponents
89
90
  });
90
- if (!schemaVerifyResult.ok) return runnerFailure("SCHEMA_VERIFY_FAILED", schemaVerifyResult.summary, {
91
+ if (!schemaVerifyResult.ok) return runnerFailure("MIGRATION.SCHEMA_VERIFY_FAILED", schemaVerifyResult.summary, {
91
92
  why: "The resulting database schema does not satisfy the destination contract.",
92
93
  meta: { issues: schemaVerifyResult.schema.issues }
93
94
  });
@@ -191,7 +192,7 @@ var PostgresMigrationRunner = class {
191
192
  if (result.rows.length === 0) return okVoid();
192
193
  const columns = new Set(result.rows.map((row) => row.column_name));
193
194
  if (columns.has("space")) return okVoid();
194
- return runnerFailure("LEGACY_MARKER_SHAPE", "Legacy marker-table shape detected on prisma_contract.marker (no `space` column). Prisma Next is in pre-1.0; the previous transitional auto-migration to the per-space-row schema has been removed. Drop `prisma_contract.marker` and re-run `dbInit` to reinitialise from a clean baseline.", { meta: {
195
+ return runnerFailure("MIGRATION.LEGACY_MARKER_SHAPE", "Legacy marker-table shape detected on prisma_contract.marker (no `space` column). Prisma Next is in pre-1.0; the previous transitional auto-migration to the per-space-row schema has been removed. Drop `prisma_contract.marker` and re-run `dbInit` to reinitialise from a clean baseline.", { meta: {
195
196
  table: "prisma_contract.marker",
196
197
  columns: [...columns].sort()
197
198
  } });
@@ -199,7 +200,7 @@ var PostgresMigrationRunner = class {
199
200
  async runExpectationSteps(driver, steps, operation, phase) {
200
201
  for (const step of steps) {
201
202
  const result = await driver.query(step.sql, step.params ?? []);
202
- if (!this.stepResultIsTrue(result.rows)) return runnerFailure(phase === "precheck" ? "PRECHECK_FAILED" : "POSTCHECK_FAILED", `Operation ${operation.id} failed during ${phase}: ${step.description}`, { meta: {
203
+ if (!this.stepResultIsTrue(result.rows)) return runnerFailure(phase === "precheck" ? "MIGRATION.PRECHECK_FAILED" : "MIGRATION.POSTCHECK_FAILED", `Operation ${operation.id} failed during ${phase}: ${step.description}`, { meta: {
203
204
  operationId: operation.id,
204
205
  phase,
205
206
  stepDescription: step.description
@@ -211,7 +212,7 @@ var PostgresMigrationRunner = class {
211
212
  for (const step of steps) try {
212
213
  await driver.query(step.sql, step.params ?? []);
213
214
  } catch (error) {
214
- if (SqlQueryError.is(error)) return runnerFailure("EXECUTION_FAILED", `Operation ${operation.id} failed during execution: ${step.description}`, {
215
+ if (SqlQueryError.is(error)) return runnerFailure("MIGRATION.EXECUTION_FAILED", `Operation ${operation.id} failed during execution: ${step.description}`, {
215
216
  why: error.message,
216
217
  meta: {
217
218
  operationId: operation.id,
@@ -281,7 +282,7 @@ var PostgresMigrationRunner = class {
281
282
  }
282
283
  enforcePolicyCompatibility(policy, operations) {
283
284
  const allowedClasses = new Set(policy.allowedOperationClasses);
284
- for (const operation of operations) if (!allowedClasses.has(operation.operationClass)) return runnerFailure("POLICY_VIOLATION", `Operation ${operation.id} has class "${operation.operationClass}" which is not allowed by policy.`, {
285
+ for (const operation of operations) if (!allowedClasses.has(operation.operationClass)) return runnerFailure("MIGRATION.POLICY_VIOLATION", `Operation ${operation.id} has class "${operation.operationClass}" which is not allowed by policy.`, {
285
286
  why: `Policy only allows: ${policy.allowedOperationClasses.join(", ")}.`,
286
287
  meta: {
287
288
  operationId: operation.id,
@@ -294,23 +295,23 @@ var PostgresMigrationRunner = class {
294
295
  ensureMarkerCompatibility(marker, plan) {
295
296
  const origin = plan.origin ?? null;
296
297
  if (!origin) return okVoid();
297
- if (!marker) return runnerFailure("MARKER_ORIGIN_MISMATCH", `Missing contract marker: expected origin storage hash ${origin.storageHash}.`, { meta: { expectedOriginStorageHash: origin.storageHash } });
298
- if (marker.storageHash !== origin.storageHash) return runnerFailure("MARKER_ORIGIN_MISMATCH", `Existing contract marker (${marker.storageHash}) does not match plan origin (${origin.storageHash}).`, { meta: {
298
+ if (!marker) return runnerFailure("MIGRATION.MARKER_ORIGIN_MISMATCH", `Missing contract marker: expected origin storage hash ${origin.storageHash}.`, { meta: { expectedOriginStorageHash: origin.storageHash } });
299
+ if (marker.storageHash !== origin.storageHash) return runnerFailure("MIGRATION.MARKER_ORIGIN_MISMATCH", `Existing contract marker (${marker.storageHash}) does not match plan origin (${origin.storageHash}).`, { meta: {
299
300
  markerStorageHash: marker.storageHash,
300
301
  expectedOriginStorageHash: origin.storageHash
301
302
  } });
302
- if (origin.profileHash && marker.profileHash !== origin.profileHash) return runnerFailure("MARKER_ORIGIN_MISMATCH", `Existing contract marker profile hash (${marker.profileHash}) does not match plan origin profile hash (${origin.profileHash}).`, { meta: {
303
+ if (origin.profileHash && marker.profileHash !== origin.profileHash) return runnerFailure("MIGRATION.MARKER_ORIGIN_MISMATCH", `Existing contract marker profile hash (${marker.profileHash}) does not match plan origin profile hash (${origin.profileHash}).`, { meta: {
303
304
  markerProfileHash: marker.profileHash,
304
305
  expectedOriginProfileHash: origin.profileHash
305
306
  } });
306
307
  return okVoid();
307
308
  }
308
309
  ensurePlanMatchesDestinationContract(destination, contract) {
309
- if (destination.storageHash !== contract.storage.storageHash) return runnerFailure("DESTINATION_CONTRACT_MISMATCH", `Plan destination storage hash (${destination.storageHash}) does not match provided contract storage hash (${contract.storage.storageHash}).`, { meta: {
310
+ if (destination.storageHash !== contract.storage.storageHash) return runnerFailure("MIGRATION.DESTINATION_CONTRACT_MISMATCH", `Plan destination storage hash (${destination.storageHash}) does not match provided contract storage hash (${contract.storage.storageHash}).`, { meta: {
310
311
  planStorageHash: destination.storageHash,
311
312
  contractStorageHash: contract.storage.storageHash
312
313
  } });
313
- if (destination.profileHash && contract.profileHash && destination.profileHash !== contract.profileHash) return runnerFailure("DESTINATION_CONTRACT_MISMATCH", `Plan destination profile hash (${destination.profileHash}) does not match provided contract profile hash (${contract.profileHash}).`, { meta: {
314
+ if (destination.profileHash && contract.profileHash && destination.profileHash !== contract.profileHash) return runnerFailure("MIGRATION.DESTINATION_CONTRACT_MISMATCH", `Plan destination profile hash (${destination.profileHash}) does not match provided contract profile hash (${contract.profileHash}).`, { meta: {
314
315
  planProfileHash: destination.profileHash,
315
316
  contractProfileHash: contract.profileHash
316
317
  } });
@@ -335,7 +336,7 @@ var PostgresMigrationRunner = class {
335
336
  space,
336
337
  expectedFrom: existingMarker.storageHash,
337
338
  destination
338
- })) return runnerFailure("MARKER_CAS_FAILURE", "Marker was modified by another process during migration execution.", { meta: {
339
+ })) return runnerFailure("MIGRATION.MARKER_CAS_FAILURE", "Marker was modified by another process during migration execution.", { meta: {
339
340
  space,
340
341
  expectedStorageHash: existingMarker.storageHash,
341
342
  destinationStorageHash: options.plan.destination.storageHash
@@ -691,6 +692,7 @@ function resolveForeignKeys(tables, owners) {
691
692
  const resultTables = {};
692
693
  const extraRelationsByTable = /* @__PURE__ */ new Map();
693
694
  const crossSpaceFieldNamesByTable = /* @__PURE__ */ new Map();
695
+ const danglingForeignKeysByTable = /* @__PURE__ */ new Map();
694
696
  for (const [tableName, table] of Object.entries(tables)) {
695
697
  const keptForeignKeys = [];
696
698
  for (const fk of table.foreignKeys) {
@@ -718,6 +720,16 @@ function resolveForeignKeys(tables, owners) {
718
720
  }
719
721
  }
720
722
  if (tables[fk.referencedTable] !== void 0) keptForeignKeys.push(fk);
723
+ else {
724
+ const dangling = {
725
+ columns: fk.columns,
726
+ referencedSchema: fk.referencedSchema,
727
+ referencedTable: fk.referencedTable
728
+ };
729
+ const existingDangling = danglingForeignKeysByTable.get(tableName);
730
+ if (existingDangling) existingDangling.push(dangling);
731
+ else danglingForeignKeysByTable.set(tableName, [dangling]);
732
+ }
721
733
  }
722
734
  resultTables[tableName] = keptForeignKeys.length === table.foreignKeys.length ? table : new SqlTableIR({
723
735
  ...table,
@@ -727,7 +739,8 @@ function resolveForeignKeys(tables, owners) {
727
739
  return {
728
740
  tables: resultTables,
729
741
  extraRelationsByTable,
730
- crossSpaceFieldNamesByTable
742
+ crossSpaceFieldNamesByTable,
743
+ danglingForeignKeysByTable
731
744
  };
732
745
  }
733
746
  /**
@@ -801,7 +814,7 @@ function inferPostgresPslContract(tree, describedContracts) {
801
814
  if (contentNamespaces.size > 1) throw new Error(`contract infer: native enum adoption with content across multiple schemas is not yet supported (single-namespace PSL inference emits one \`namespace { … }\` block; multi-namespace output is a later slice). Schemas: ${[...contentNamespaces].sort().join(", ")}.`);
802
815
  wrapNamespaceName = [...contentNamespaces][0];
803
816
  }
804
- const { tables: resolvedTables, extraRelationsByTable, crossSpaceFieldNamesByTable } = resolveForeignKeys(tables, owners);
817
+ const { tables: resolvedTables, extraRelationsByTable, crossSpaceFieldNamesByTable, danglingForeignKeysByTable } = resolveForeignKeys(tables, owners);
805
818
  const schemaIR = new SqlSchemaIR({ tables: resolvedTables });
806
819
  const enumTypeNames = new Set(enumDefinitions.keys());
807
820
  if (wrapNamespaceName !== void 0) for (const typeName of enumDefinitions.keys()) enumTypeNames.add(`${wrapNamespaceName}.${typeName}`);
@@ -816,12 +829,13 @@ function inferPostgresPslContract(tree, describedContracts) {
816
829
  ...enumDefinitions.size > 0 ? { enumInfo } : {}
817
830
  }, {
818
831
  extraRelationsByTable,
819
- crossSpaceFieldNamesByTable
832
+ crossSpaceFieldNamesByTable,
833
+ danglingForeignKeysByTable
820
834
  }, wrapNamespaceName);
821
835
  }
822
836
  function buildPslDocumentAst(schemaIR, options, foreignKeyExtras, namespaceName) {
823
837
  const { typeMap, defaultMapping, parseRawDefault: rawDefaultParser } = options;
824
- const { extraRelationsByTable, crossSpaceFieldNamesByTable } = foreignKeyExtras;
838
+ const { extraRelationsByTable, crossSpaceFieldNamesByTable, danglingForeignKeysByTable } = foreignKeyExtras;
825
839
  const modelNames = buildTopLevelNameMap(Object.keys(schemaIR.tables), toModelName, "model", "table");
826
840
  const modelNameMap = new Map([...modelNames].map(([tableName, result]) => [tableName, result.name]));
827
841
  const { enumNameMap: bareEnumNameMap, enumBlocks } = buildNativeEnumBlocks(options.enumInfo?.definitions ?? /* @__PURE__ */ new Map(), modelNames);
@@ -832,7 +846,7 @@ function buildPslDocumentAst(schemaIR, options, foreignKeyExtras, namespaceName)
832
846
  const { relationsByTable } = inferRelations(schemaIR.tables, modelNameMap);
833
847
  const namedTypes = seedNamedTypeRegistry(schemaIR, typeMap, enumNameMap, reservedNamedTypeNames);
834
848
  const models = [];
835
- for (const table of Object.values(schemaIR.tables)) models.push(buildModel(table, typeMap, enumNameMap, fieldNamesByTable, namedTypes, defaultMapping, rawDefaultParser, [...relationsByTable.get(table.name) ?? [], ...extraRelationsByTable.get(table.name) ?? []]));
849
+ for (const table of Object.values(schemaIR.tables)) models.push(buildModel(table, typeMap, enumNameMap, fieldNamesByTable, namedTypes, defaultMapping, rawDefaultParser, [...relationsByTable.get(table.name) ?? [], ...extraRelationsByTable.get(table.name) ?? []], danglingForeignKeysByTable.get(table.name) ?? []));
836
850
  const sortedModels = topologicalSort(models, schemaIR.tables, modelNameMap);
837
851
  const namedTypeEntries = [...namedTypes.entriesByKey.values()].sort((a, b) => a.name.localeCompare(b.name));
838
852
  const types = namedTypeEntries.length > 0 ? {
@@ -909,7 +923,7 @@ function buildNativeEnumBlock(name, typeName, values) {
909
923
  span: SYNTHETIC_SPAN
910
924
  };
911
925
  }
912
- function buildModel(table, typeMap, enumNameMap, fieldNamesByTable, namedTypes, defaultMapping, rawDefaultParser, relationFields) {
926
+ function buildModel(table, typeMap, enumNameMap, fieldNamesByTable, namedTypes, defaultMapping, rawDefaultParser, relationFields, danglingForeignKeys) {
913
927
  const { name: modelName, map: mapName } = toModelName(table.name);
914
928
  const fieldNameMap = fieldNamesByTable.get(table.name);
915
929
  const pkColumns = new Set(table.primaryKey?.columns ?? []);
@@ -939,7 +953,10 @@ function buildModel(table, typeMap, enumNameMap, fieldNamesByTable, namedTypes,
939
953
  modelAttributes.push(buildModelConstraintAttribute("index", indexFieldNames, index.name, index.type));
940
954
  }
941
955
  if (mapName) modelAttributes.push(buildMapAttribute("model", mapName));
942
- const comment = table.primaryKey ? void 0 : "// WARNING: This table has no primary key in the database";
956
+ const warnings = [];
957
+ if (!table.primaryKey) warnings.push("This table has no primary key in the database");
958
+ if (danglingForeignKeys.length > 0) warnings.push(buildDanglingForeignKeyWarning(danglingForeignKeys, fieldNamesByTable, table.name));
959
+ const comment = warnings.length > 0 ? `// WARNING: ${warnings.join(" ")}` : void 0;
943
960
  return {
944
961
  kind: "model",
945
962
  name: modelName,
@@ -949,6 +966,20 @@ function buildModel(table, typeMap, enumNameMap, fieldNamesByTable, namedTypes,
949
966
  ...comment !== void 0 ? { comment } : {}
950
967
  };
951
968
  }
969
+ /**
970
+ * Explains a foreign key `resolveForeignKeys` dropped as dangling: the
971
+ * database enforces it, but its target lives outside the introspected
972
+ * schema, so infer has no model to point a relation at. The suggested fix
973
+ * targets the common cause — an unconfigured extension pack's schema
974
+ * (e.g. Supabase's `auth`).
975
+ */
976
+ function buildDanglingForeignKeyWarning(danglingForeignKeys, fieldNamesByTable, tableName) {
977
+ return `Foreign key ${danglingForeignKeys.map((fk) => {
978
+ const fieldNames = fk.columns.map((columnName) => resolveColumnFieldName(fieldNamesByTable, tableName, columnName));
979
+ const target = fk.referencedSchema !== void 0 ? `${fk.referencedSchema}.${fk.referencedTable}` : fk.referencedTable;
980
+ return `"${fieldNames.join(", ")}" -> "${target}"`;
981
+ }).join(", ")} exists in the database, but its target schema is outside the introspected scope, so no relation field was generated. If the target schema is described by an extension pack, add it to extensionPacks and re-run infer.`;
982
+ }
952
983
  function buildScalarField(column, table, typeMap, enumNameMap, fieldNameMap, namedTypes, defaultMapping, rawDefaultParser, pkColumns, isSinglePk, singlePkConstraintName, uniqueColumns) {
953
984
  const resolvedField = fieldNameMap?.get(column.name);
954
985
  const fieldName = resolvedField?.fieldName ?? toFieldName(column.name).name;
@@ -983,7 +1014,11 @@ function buildScalarField(column, table, typeMap, enumNameMap, fieldNameMap, nam
983
1014
  const attributes = [];
984
1015
  const isId = isSinglePk && pkColumns.has(column.name);
985
1016
  if (isId) attributes.push(buildSimpleConstraintFieldAttribute("id", singlePkConstraintName));
986
- if (column.default !== void 0) {
1017
+ if (column.default === void 0 && column.resolvedDefault?.kind === "function" && column.resolvedDefault.expression === "autoincrement()") attributes.push(parseDefaultAttributeString("@default(autoincrement())"));
1018
+ else if (column.many === true && column.resolvedDefault?.kind === "literal") {
1019
+ const formatted = Array.isArray(column.resolvedDefault.value) ? formatPslListLiteralValue(column.resolvedDefault.value) : void 0;
1020
+ if (formatted !== void 0) attributes.push(parseDefaultAttributeString(`@default(${formatted})`));
1021
+ } else if (column.default !== void 0) {
987
1022
  const parsed = parseColumnDefault(column.default, column.nativeType, rawDefaultParser);
988
1023
  if (parsed) {
989
1024
  const result = mapDefault(parsed, defaultMapping);
@@ -1094,6 +1129,20 @@ function escapePslString(value) {
1094
1129
  return value.replace(/\\/g, "\\\\").replace(/"/g, "\\\"").replace(/\n/g, "\\n").replace(/\r/g, "\\r");
1095
1130
  }
1096
1131
  /**
1132
+ * Formats a resolved literal-default array as PSL literal-list syntax
1133
+ * (`[1, 2, 3]`, `["a", "b"]`, `[]`). PSL's list-literal grammar only accepts
1134
+ * string/number/boolean elements, so any other element (e.g. `null`, a
1135
+ * nested array/object) makes the value unrepresentable and this returns
1136
+ * `undefined`.
1137
+ */
1138
+ function formatPslListLiteralValue(elements) {
1139
+ const parts = [];
1140
+ for (const element of elements) if (typeof element === "string") parts.push(`"${escapePslString(element)}"`);
1141
+ else if (typeof element === "number" || typeof element === "boolean") parts.push(String(element));
1142
+ else return;
1143
+ return `[${parts.join(", ")}]`;
1144
+ }
1145
+ /**
1097
1146
  * Resolves a `SqlColumnIR.default` value into a normalized {@link ColumnDefault}.
1098
1147
  *
1099
1148
  * `SqlSchemaIR` types the column default as `string` (a raw database default
@@ -1283,7 +1332,8 @@ const postgresTargetDescriptor = {
1283
1332
  return contractToPostgresDatabaseSchemaNode(blindCast(contract), {
1284
1333
  annotationNamespace: "pg",
1285
1334
  ...ifDefined("expandNativeType", expander),
1286
- renderDefault: postgresRenderDefault
1335
+ renderDefault: postgresRenderDefault,
1336
+ resolveDefault: postgresResolveDefault
1287
1337
  });
1288
1338
  }
1289
1339
  },