@prisma-next/target-postgres 0.16.0-dev.3 → 0.16.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 (166) hide show
  1. package/README.md +1 -1
  2. package/dist/{authoring-34L18kA1.mjs → authoring-DnO1B0N9.mjs} +29 -18
  3. package/dist/authoring-DnO1B0N9.mjs.map +1 -0
  4. package/dist/canonicalize-C7zKHw8m.mjs +59 -0
  5. package/dist/canonicalize-C7zKHw8m.mjs.map +1 -0
  6. package/dist/{canonicalize-D1F4vUnP.d.mts → canonicalize-CQlxSR4D.d.mts} +3 -18
  7. package/dist/canonicalize-CQlxSR4D.d.mts.map +1 -0
  8. package/dist/{codec-types-CQ07nOz-.d.mts → codec-types-DdoPc2dy.d.mts} +3 -2
  9. package/dist/codec-types-DdoPc2dy.d.mts.map +1 -0
  10. package/dist/codec-types.d.mts +1 -1
  11. package/dist/{codecs-G4DTY0F_.d.mts → codecs-CGE5dh94.d.mts} +7 -2
  12. package/dist/codecs-CGE5dh94.d.mts.map +1 -0
  13. package/dist/{codecs-TCsGgW-Y.mjs → codecs-Deand7sy.mjs} +84 -26
  14. package/dist/codecs-Deand7sy.mjs.map +1 -0
  15. package/dist/codecs.d.mts +2 -2
  16. package/dist/codecs.mjs +2 -2
  17. package/dist/contract-free.d.mts +1 -1
  18. package/dist/contract-free.d.mts.map +1 -1
  19. package/dist/contract-free.mjs +2 -2
  20. package/dist/{control-policy-CZKdMztu.mjs → control-policy-DEwdS3oK.mjs} +29 -29
  21. package/dist/control-policy-DEwdS3oK.mjs.map +1 -0
  22. package/dist/control.mjs +91 -239
  23. package/dist/control.mjs.map +1 -1
  24. package/dist/data-transform-BOWpliq8.mjs.map +1 -1
  25. package/dist/{ddl-DHXKzQ99.mjs → ddl-BQC6u-L9.mjs} +28 -4
  26. package/dist/{ddl-DHXKzQ99.mjs.map → ddl-BQC6u-L9.mjs.map} +1 -1
  27. package/dist/ddl.d.mts +3 -3
  28. package/dist/ddl.mjs +2 -2
  29. package/dist/{descriptor-meta-qubYaxQA.mjs → descriptor-meta-DGlJurgA.mjs} +4 -4
  30. package/dist/{descriptor-meta-qubYaxQA.mjs.map → descriptor-meta-DGlJurgA.mjs.map} +1 -1
  31. package/dist/{diff-database-schema-C-hnJ5mr.mjs → diff-database-schema-qRPwuYBH.mjs} +37 -15
  32. package/dist/diff-database-schema-qRPwuYBH.mjs.map +1 -0
  33. package/dist/diff-database-schema.mjs +1 -1
  34. package/dist/{errors-ByDS0xJL.mjs → errors-DBSNx7EJ.mjs} +6 -2
  35. package/dist/errors-DBSNx7EJ.mjs.map +1 -0
  36. package/dist/errors.d.mts +4 -1
  37. package/dist/errors.d.mts.map +1 -1
  38. package/dist/errors.mjs +2 -2
  39. package/dist/issue-planner.d.mts +2 -2
  40. package/dist/issue-planner.d.mts.map +1 -1
  41. package/dist/issue-planner.mjs +1 -1
  42. package/dist/migration.d.mts +2 -2
  43. package/dist/migration.mjs +2 -2
  44. package/dist/{nodes-DJC5B8Id.mjs → nodes-04EILM-z.mjs} +65 -2
  45. package/dist/nodes-04EILM-z.mjs.map +1 -0
  46. package/dist/{nodes-CQzM2hR0.d.mts → nodes-DjCsN-uv.d.mts} +69 -4
  47. package/dist/nodes-DjCsN-uv.d.mts.map +1 -0
  48. package/dist/{op-factory-call-DT7kdjVP.d.mts → op-factory-call-0TB5XNij.d.mts} +46 -8
  49. package/dist/op-factory-call-0TB5XNij.d.mts.map +1 -0
  50. package/dist/{op-factory-call-DuRj7WXX.mjs → op-factory-call-CIaPDDUc.mjs} +147 -64
  51. package/dist/op-factory-call-CIaPDDUc.mjs.map +1 -0
  52. package/dist/op-factory-call.d.mts +2 -2
  53. package/dist/op-factory-call.mjs +2 -2
  54. package/dist/pack.d.mts +2 -2
  55. package/dist/pack.d.mts.map +1 -1
  56. package/dist/pack.mjs +1 -1
  57. package/dist/{planner-DPGxFcXo.mjs → planner-BhnkIJX-.mjs} +121 -13
  58. package/dist/planner-BhnkIJX-.mjs.map +1 -0
  59. package/dist/{planner-ddl-builders-BKlmGDJl.mjs → planner-ddl-builders-CVo3L7Nd.mjs} +12 -7
  60. package/dist/planner-ddl-builders-CVo3L7Nd.mjs.map +1 -0
  61. package/dist/planner-ddl-builders.d.mts.map +1 -1
  62. package/dist/planner-ddl-builders.mjs +1 -1
  63. package/dist/{planner-produced-postgres-migration-CFDpqWWE.mjs → planner-produced-postgres-migration-BE3EJIRK.mjs} +9 -6
  64. package/dist/planner-produced-postgres-migration-BE3EJIRK.mjs.map +1 -0
  65. package/dist/{planner-produced-postgres-migration-C-dwGdb2.d.mts → planner-produced-postgres-migration-CRAHl6ak.d.mts} +3 -3
  66. package/dist/planner-produced-postgres-migration-CRAHl6ak.d.mts.map +1 -0
  67. package/dist/planner-produced-postgres-migration.d.mts +1 -1
  68. package/dist/planner-produced-postgres-migration.mjs +1 -1
  69. package/dist/{planner-schema-lookup-CiVaAQP-.mjs → planner-schema-lookup-D3Y_OL-C.mjs} +3 -3
  70. package/dist/planner-schema-lookup-D3Y_OL-C.mjs.map +1 -0
  71. package/dist/planner-schema-lookup.mjs +1 -1
  72. package/dist/{planner-sql-checks-BuB877wH.mjs → planner-sql-checks-CmiQ6Nei.mjs} +3 -3
  73. package/dist/{planner-sql-checks-BuB877wH.mjs.map → planner-sql-checks-CmiQ6Nei.mjs.map} +1 -1
  74. package/dist/planner-sql-checks.mjs +1 -1
  75. package/dist/planner.d.mts +27 -1
  76. package/dist/planner.d.mts.map +1 -1
  77. package/dist/planner.mjs +2 -2
  78. package/dist/{postgres-contract-view-DebHMqGR.mjs → postgres-contract-view-BeIEyZfD.mjs} +3 -3
  79. package/dist/{postgres-contract-view-DebHMqGR.mjs.map → postgres-contract-view-BeIEyZfD.mjs.map} +1 -1
  80. package/dist/{postgres-migration-C_OPFhIF.mjs → postgres-migration--BzvpA92.mjs} +9 -6
  81. package/dist/postgres-migration--BzvpA92.mjs.map +1 -0
  82. package/dist/{postgres-migration-DLIvzHjX.d.mts → postgres-migration-BXelnqHO.d.mts} +15 -10
  83. package/dist/postgres-migration-BXelnqHO.d.mts.map +1 -0
  84. package/dist/{postgres-schema-CewLYHB7.mjs → postgres-schema-CTplQZDK.mjs} +2 -2
  85. package/dist/{postgres-schema-CewLYHB7.mjs.map → postgres-schema-CTplQZDK.mjs.map} +1 -1
  86. package/dist/{render-ops-BREh1kHe.mjs → render-ops-TcY9XEkz.mjs} +7 -2
  87. package/dist/render-ops-TcY9XEkz.mjs.map +1 -0
  88. package/dist/render-ops.d.mts.map +1 -1
  89. package/dist/render-ops.mjs +1 -1
  90. package/dist/{render-typescript-7yqILcwr.mjs → render-typescript-Ta7_6CGf.mjs} +20 -8
  91. package/dist/render-typescript-Ta7_6CGf.mjs.map +1 -0
  92. package/dist/render-typescript.d.mts +2 -0
  93. package/dist/render-typescript.d.mts.map +1 -1
  94. package/dist/render-typescript.mjs +1 -1
  95. package/dist/{resolve-ddl-schema-D0wi_P9Q.mjs → resolve-ddl-schema-BAsJEKW8.mjs} +2 -2
  96. package/dist/{resolve-ddl-schema-D0wi_P9Q.mjs.map → resolve-ddl-schema-BAsJEKW8.mjs.map} +1 -1
  97. package/dist/rls-canonicalize.d.mts +2 -26
  98. package/dist/rls-canonicalize.mjs +2 -2
  99. package/dist/runtime.mjs +1 -1
  100. package/dist/schema-ir-annotations.mjs +1 -1
  101. package/dist/{sql-utils-SU4FDvIV.mjs → sql-utils-B2lzkKfP.mjs} +22 -19
  102. package/dist/sql-utils-B2lzkKfP.mjs.map +1 -0
  103. package/dist/sql-utils.d.mts +4 -9
  104. package/dist/sql-utils.d.mts.map +1 -1
  105. package/dist/sql-utils.mjs +2 -2
  106. package/dist/types.mjs +1 -1
  107. package/package.json +20 -20
  108. package/src/contract-free/ddl.ts +47 -0
  109. package/src/core/authoring.ts +35 -26
  110. package/src/core/codec-helpers.ts +69 -16
  111. package/src/core/codec-type-map.ts +2 -0
  112. package/src/core/codecs.ts +29 -14
  113. package/src/core/ddl/nodes.ts +104 -0
  114. package/src/core/errors.ts +30 -0
  115. package/src/core/migrations/column-ddl-rendering.ts +2 -1
  116. package/src/core/migrations/contract-to-postgres-database-schema-node.ts +38 -14
  117. package/src/core/migrations/issue-planner.ts +40 -13
  118. package/src/core/migrations/op-factory-call.ts +189 -44
  119. package/src/core/migrations/operations/constraints.ts +3 -2
  120. package/src/core/migrations/operations/data-transform.ts +1 -1
  121. package/src/core/migrations/operations/indexes.ts +80 -32
  122. package/src/core/migrations/operations/rls.ts +4 -1
  123. package/src/core/migrations/planner-ddl-builders.ts +16 -6
  124. package/src/core/migrations/planner-produced-postgres-migration.ts +8 -1
  125. package/src/core/migrations/planner-schema-lookup.ts +2 -2
  126. package/src/core/migrations/planner.ts +163 -5
  127. package/src/core/migrations/postgres-migration.ts +26 -8
  128. package/src/core/migrations/render-ops.ts +4 -1
  129. package/src/core/migrations/render-typescript.ts +20 -8
  130. package/src/core/migrations/runner.ts +7 -3
  131. package/src/core/psl-infer/infer-psl-contract.ts +36 -185
  132. package/src/core/psl-infer/postgres-type-map.ts +43 -65
  133. package/src/core/rls/canonicalize.ts +4 -21
  134. package/src/core/sql-utils.ts +16 -27
  135. package/src/exports/codecs.ts +2 -0
  136. package/src/exports/ddl.ts +4 -0
  137. package/src/exports/errors.ts +1 -1
  138. package/src/exports/op-factory-call.ts +1 -0
  139. package/src/exports/rls-canonicalize.ts +0 -6
  140. package/src/exports/sql-utils.ts +0 -1
  141. package/dist/authoring-34L18kA1.mjs.map +0 -1
  142. package/dist/canonicalize-D1F4vUnP.d.mts.map +0 -1
  143. package/dist/codec-types-CQ07nOz-.d.mts.map +0 -1
  144. package/dist/codecs-G4DTY0F_.d.mts.map +0 -1
  145. package/dist/codecs-TCsGgW-Y.mjs.map +0 -1
  146. package/dist/control-policy-CZKdMztu.mjs.map +0 -1
  147. package/dist/diff-database-schema-C-hnJ5mr.mjs.map +0 -1
  148. package/dist/errors-ByDS0xJL.mjs.map +0 -1
  149. package/dist/nodes-CQzM2hR0.d.mts.map +0 -1
  150. package/dist/nodes-DJC5B8Id.mjs.map +0 -1
  151. package/dist/op-factory-call-DT7kdjVP.d.mts.map +0 -1
  152. package/dist/op-factory-call-DuRj7WXX.mjs.map +0 -1
  153. package/dist/planner-DPGxFcXo.mjs.map +0 -1
  154. package/dist/planner-ddl-builders-BKlmGDJl.mjs.map +0 -1
  155. package/dist/planner-produced-postgres-migration-C-dwGdb2.d.mts.map +0 -1
  156. package/dist/planner-produced-postgres-migration-CFDpqWWE.mjs.map +0 -1
  157. package/dist/planner-schema-lookup-CiVaAQP-.mjs.map +0 -1
  158. package/dist/postgres-migration-C_OPFhIF.mjs.map +0 -1
  159. package/dist/postgres-migration-DLIvzHjX.d.mts.map +0 -1
  160. package/dist/render-ops-BREh1kHe.mjs.map +0 -1
  161. package/dist/render-typescript-7yqILcwr.mjs.map +0 -1
  162. package/dist/rls-canonicalize.d.mts.map +0 -1
  163. package/dist/sql-utils-SU4FDvIV.mjs.map +0 -1
  164. package/dist/wire-name-DbQ9-2RC.mjs +0 -104
  165. package/dist/wire-name-DbQ9-2RC.mjs.map +0 -1
  166. package/src/core/rls/wire-name.ts +0 -33
@@ -1,13 +1,15 @@
1
+ import { n as postgresError } from "./errors-DBSNx7EJ.mjs";
1
2
  import { t as DEFAULT_NAMESPACE_ID } from "./namespace-ids-xtp_ZY86.mjs";
2
- import { a as quoteQualifiedName, i as quoteIdentifier, n as escapeLiteral, o as validateEnumValueLength } from "./sql-utils-SU4FDvIV.mjs";
3
- import { C as rlsPolicyExistsAst, S as rlsEnabledAst, T as tableIsEmptyAst, _ as extensionExistsAst, a as createSchema, b as nativeEnumValueExistsAst, c as disableRowLevelSecurity$1, d as dropType, f as columnDefaultAst, g as constraintExistsAst, h as columnTypeAst, i as createPolicy, l as dropDefaultAction, m as columnNullabilityAst, n as alterPolicyRename, o as createTable, p as columnExistsAst, r as alterTable, s as createType, t as addColumnAction, u as dropPolicy, v as indexExistsAst, w as tableExistsAst, x as noNullValuesAst, y as nativeEnumTypeExistsAst } from "./ddl-DHXKzQ99.mjs";
4
- import { n as qualifyTableName } from "./planner-sql-checks-BuB877wH.mjs";
5
- import { n as buildColumnTypeSql } from "./planner-ddl-builders-BKlmGDJl.mjs";
3
+ import { a as validateEnumValueLength, i as quoteQualifiedName, r as quoteIdentifier, t as escapeLiteral } from "./sql-utils-B2lzkKfP.mjs";
4
+ import { C as nativeEnumValueExistsAst, D as tableExistsAst, E as rlsPolicyExistsAst, O as tableIsEmptyAst, S as nativeEnumTypeExistsAst, T as rlsEnabledAst, _ as columnNullabilityAst, a as createIndex$1, b as extensionExistsAst, c as createTable, d as dropDefaultAction, f as dropIndex$1, g as columnExistsAst, h as columnDefaultAst, i as alterTable, l as createType, m as dropType, n as alterIndexRename, o as createPolicy, p as dropPolicy, r as alterPolicyRename, s as createSchema, t as addColumnAction, u as disableRowLevelSecurity$1, v as columnTypeAst, w as noNullValuesAst, x as indexExistsAst, y as constraintExistsAst } from "./ddl-BQC6u-L9.mjs";
5
+ import { n as qualifyTableName } from "./planner-sql-checks-CmiQ6Nei.mjs";
6
+ import { n as buildColumnTypeSql } from "./planner-ddl-builders-CVo3L7Nd.mjs";
6
7
  import { FunctionColumnDefault, LiteralColumnDefault } from "@prisma-next/sql-relational-core/ast";
7
8
  import { UNBOUND_NAMESPACE_ID } from "@prisma-next/framework-components/ir";
8
9
  import { blindCast } from "@prisma-next/utils/casts";
9
10
  import { ifDefined } from "@prisma-next/utils/defined";
10
11
  import { col } from "@prisma-next/sql-relational-core/contract-free";
12
+ import { InternalError, assertNever } from "@prisma-next/utils/internal-error";
11
13
  import { errorUnfilledPlaceholder } from "@prisma-next/errors/migration";
12
14
  import { TsExpression, jsonToTsSource } from "@prisma-next/ts-render";
13
15
  import { REFERENTIAL_ACTION_SQL } from "@prisma-next/sql-contract/referential-action-sql";
@@ -265,12 +267,12 @@ FOREIGN KEY (${fk.columns.map(quoteIdentifier).join(", ")})
265
267
  REFERENCES ${qualifyTableName(fk.references.schema, fk.references.table)} (${fk.references.columns.map(quoteIdentifier).join(", ")})`;
266
268
  if (fk.onDelete !== void 0) {
267
269
  const action = REFERENTIAL_ACTION_SQL[fk.onDelete];
268
- if (!action) throw new Error(`Unknown referential action for onDelete: ${String(fk.onDelete)}`);
270
+ if (!action) throw new InternalError(`Unknown referential action for onDelete: ${String(fk.onDelete)}`);
269
271
  sql += `\nON DELETE ${action}`;
270
272
  }
271
273
  if (fk.onUpdate !== void 0) {
272
274
  const action = REFERENTIAL_ACTION_SQL[fk.onUpdate];
273
- if (!action) throw new Error(`Unknown referential action for onUpdate: ${String(fk.onUpdate)}`);
275
+ if (!action) throw new InternalError(`Unknown referential action for onUpdate: ${String(fk.onUpdate)}`);
274
276
  sql += `\nON UPDATE ${action}`;
275
277
  }
276
278
  return sql;
@@ -446,21 +448,22 @@ async function indexExistsSteps(lowerer, schemaName, indexName) {
446
448
  absent: await lowerer.lowerToExecuteRequest(checks.indexAbsent())
447
449
  };
448
450
  }
449
- function renderIndexOptionValue(key, value) {
450
- if (typeof value === "string") return `'${escapeLiteral(value)}'`;
451
- if (typeof value === "number" && Number.isFinite(value)) return String(value);
452
- if (typeof value === "boolean") return value ? "true" : "false";
453
- throw new Error(`Index option "${key}" must be a string, finite number, or boolean; got ${typeof value}`);
454
- }
455
- function renderIndexOptions(options) {
456
- return Object.entries(options).map(([key, value]) => `${quoteIdentifier(key)} = ${renderIndexOptionValue(key, value)}`).join(", ");
451
+ /** An unbound-namespace object renders unqualified: the DDL node takes no schema. */
452
+ function ddlSchemaOf(schemaName) {
453
+ return schemaName === UNBOUND_NAMESPACE_ID ? void 0 : schemaName;
457
454
  }
458
- async function createIndex(schemaName, tableName, indexName, columns, lowerer, extras) {
459
- const qualified = qualifyTableName(schemaName, tableName);
460
- const columnList = columns.map(quoteIdentifier).join(", ");
461
- const using = extras?.type ? ` USING ${quoteIdentifier(extras.type)}` : "";
462
- const options = extras?.options;
463
- const withClause = options && Object.keys(options).length > 0 ? ` WITH (${renderIndexOptions(options)})` : "";
455
+ async function createIndex(schemaName, tableName, indexName, elements, lowerer, extras) {
456
+ const ddlNode = createIndex$1({
457
+ schema: ddlSchemaOf(schemaName),
458
+ table: tableName,
459
+ name: indexName,
460
+ unique: extras?.unique === true,
461
+ elements,
462
+ type: extras?.type,
463
+ options: extras?.options,
464
+ where: extras?.where
465
+ });
466
+ const execute = await lowerer.lowerToExecuteRequest(ddlNode);
464
467
  const { present, absent } = await indexExistsSteps(lowerer, schemaName, indexName);
465
468
  return {
466
469
  id: `index.${tableName}.${indexName}`,
@@ -468,11 +471,44 @@ async function createIndex(schemaName, tableName, indexName, columns, lowerer, e
468
471
  operationClass: "additive",
469
472
  target: targetDetails("index", indexName, schemaName, tableName),
470
473
  precheck: [step(`ensure index "${indexName}" does not exist`, absent.sql, absent.params)],
471
- execute: [step(`create index "${indexName}"`, `CREATE INDEX ${quoteIdentifier(indexName)} ON ${qualified}${using} (${columnList})${withClause}`)],
474
+ execute: [step(`create index "${indexName}"`, execute.sql, execute.params)],
472
475
  postcheck: [step(`verify index "${indexName}" exists`, present.sql, present.params)]
473
476
  };
474
477
  }
478
+ /**
479
+ * `ALTER INDEX … RENAME TO`. `widening` for the same typology reason as the
480
+ * RLS policy rename: a rename is neither additive creation nor destructive,
481
+ * and the class vocabulary has no neutral middle class — it is NOT that a
482
+ * rename widens anything.
483
+ */
484
+ async function renameIndex(schemaName, tableName, fromName, toName, lowerer) {
485
+ const fromChecks = indexExistsAst(schemaName, fromName);
486
+ const toChecks = indexExistsAst(schemaName, toName);
487
+ const fromPresent = await lowerer.lowerToExecuteRequest(fromChecks.indexPresent());
488
+ const toAbsent = await lowerer.lowerToExecuteRequest(toChecks.indexAbsent());
489
+ const toPresent = await lowerer.lowerToExecuteRequest(toChecks.indexPresent());
490
+ const ddlNode = alterIndexRename({
491
+ schema: ddlSchemaOf(schemaName),
492
+ from: fromName,
493
+ to: toName
494
+ });
495
+ const execute = await lowerer.lowerToExecuteRequest(ddlNode);
496
+ return {
497
+ id: `index.${schemaName}.${tableName}.${fromName}.rename`,
498
+ label: `Rename index "${fromName}" to "${toName}" on "${tableName}"`,
499
+ operationClass: "widening",
500
+ target: targetDetails("index", toName, schemaName, tableName),
501
+ precheck: [step(`ensure index "${fromName}" exists`, fromPresent.sql, fromPresent.params), step(`ensure index "${toName}" does not exist`, toAbsent.sql, toAbsent.params)],
502
+ execute: [step(`rename index "${fromName}" to "${toName}"`, execute.sql, execute.params)],
503
+ postcheck: [step(`verify index "${toName}" exists`, toPresent.sql, toPresent.params)]
504
+ };
505
+ }
475
506
  async function dropIndex(schemaName, tableName, indexName, lowerer) {
507
+ const ddlNode = dropIndex$1({
508
+ schema: ddlSchemaOf(schemaName),
509
+ name: indexName
510
+ });
511
+ const execute = await lowerer.lowerToExecuteRequest(ddlNode);
476
512
  const { present, absent } = await indexExistsSteps(lowerer, schemaName, indexName);
477
513
  return {
478
514
  id: `dropIndex.${tableName}.${indexName}`,
@@ -480,7 +516,7 @@ async function dropIndex(schemaName, tableName, indexName, lowerer) {
480
516
  operationClass: "destructive",
481
517
  target: targetDetails("index", indexName, schemaName, tableName),
482
518
  precheck: [step(`ensure index "${indexName}" exists`, present.sql, present.params)],
483
- execute: [step(`drop index "${indexName}"`, `DROP INDEX ${qualifyTableName(schemaName, indexName)}`)],
519
+ execute: [step(`drop index "${indexName}"`, execute.sql, execute.params)],
484
520
  postcheck: [step(`verify index "${indexName}" does not exist`, absent.sql, absent.params)]
485
521
  };
486
522
  }
@@ -533,7 +569,10 @@ async function dropNativeEnumType(schemaName, typeName, lowerer) {
533
569
  //#region src/core/migrations/operations/rls.ts
534
570
  const PLAIN_IDENTIFIER = /^[A-Za-z_][A-Za-z0-9_$]*$/;
535
571
  function validateRoleName(role) {
536
- if (!PLAIN_IDENTIFIER.test(role)) throw new Error(`Invalid role name ${JSON.stringify(role)}: role names must be plain SQL identifiers matching ^[A-Za-z_][A-Za-z0-9_$]*$`);
572
+ if (!PLAIN_IDENTIFIER.test(role)) throw postgresError("CONTRACT.ROLE_INVALID", `Invalid role name ${JSON.stringify(role)}: role names must be plain SQL identifiers matching ^[A-Za-z_][A-Za-z0-9_$]*$`, { meta: {
573
+ role,
574
+ reason: "not-a-plain-identifier"
575
+ } });
537
576
  return role;
538
577
  }
539
578
  async function createRlsPolicy(schemaName, tableName, policy, lowerer) {
@@ -791,7 +830,10 @@ function postgresDefaultToDdlColumnDefault(columnDefault) {
791
830
  if (columnDefault.expression === "autoincrement()") return void 0;
792
831
  return new FunctionColumnDefault(columnDefault.expression);
793
832
  case "sequence": return new FunctionColumnDefault(`nextval('${escapeLiteral(quoteIdentifier(columnDefault.name))}'::regclass)`);
794
- default: throw new Error(`postgresDefaultToDdlColumnDefault: unhandled kind "${blindCast(columnDefault).kind}"`);
833
+ default: {
834
+ const exhaustive = columnDefault;
835
+ return assertNever(exhaustive, `postgresDefaultToDdlColumnDefault: unhandled kind "${blindCast(exhaustive).kind}"`);
836
+ }
795
837
  }
796
838
  }
797
839
  function renderDdlColumnDefault(def) {
@@ -865,7 +907,7 @@ var CreateTableCall = class extends PostgresOpFactoryCallNode {
865
907
  this.freeze();
866
908
  }
867
909
  async toOp(lowerer) {
868
- if (lowerer === void 0) throw new Error(`CreateTableCall.toOp: a DDL lowerer is required on the Postgres planner path (table "${this.tableName}"). Pass the control adapter to createPostgresMigrationPlanner.`);
910
+ if (lowerer === void 0) throw postgresError("MIGRATION.POSTGRES_CONTROL_STACK_MISSING", `CreateTableCall.toOp: a DDL lowerer is required on the Postgres planner path (table "${this.tableName}"). Pass the control adapter to createPostgresMigrationPlanner.`, { meta: { factory: "CreateTableCall" } });
869
911
  const ddlNode = createTable({
870
912
  ...ifDefined("schema", boundSchema(this.schemaName)),
871
913
  table: this.tableName,
@@ -936,7 +978,7 @@ var DropTableCall = class extends PostgresOpFactoryCallNode {
936
978
  this.freeze();
937
979
  }
938
980
  async toOp(lowerer) {
939
- if (lowerer === void 0) throw new Error(`DropTableCall.toOp: a lowerer is required on the Postgres planner path (table "${this.tableName}"). Pass the control adapter to createPostgresMigrationPlanner.`);
981
+ if (lowerer === void 0) throw postgresError("MIGRATION.POSTGRES_CONTROL_STACK_MISSING", `DropTableCall.toOp: a lowerer is required on the Postgres planner path (table "${this.tableName}"). Pass the control adapter to createPostgresMigrationPlanner.`, { meta: { factory: "DropTableCall" } });
940
982
  return dropTable(this.schemaName, this.tableName, lowerer);
941
983
  }
942
984
  renderTypeScript() {
@@ -965,7 +1007,7 @@ var AddColumnCall = class extends PostgresOpFactoryCallNode {
965
1007
  this.freeze();
966
1008
  }
967
1009
  async toOp(lowerer) {
968
- if (lowerer === void 0) throw new Error(`AddColumnCall.toOp: a DDL lowerer is required on the Postgres planner path (column "${this.column.name}" on table "${this.tableName}"). Pass the control adapter to createPostgresMigrationPlanner.`);
1010
+ if (lowerer === void 0) throw postgresError("MIGRATION.POSTGRES_CONTROL_STACK_MISSING", `AddColumnCall.toOp: a DDL lowerer is required on the Postgres planner path (column "${this.column.name}" on table "${this.tableName}"). Pass the control adapter to createPostgresMigrationPlanner.`, { meta: { factory: "AddColumnCall" } });
969
1011
  const ddlNode = alterTable({
970
1012
  ...ifDefined("schema", boundSchema(this.schemaName)),
971
1013
  table: this.tableName,
@@ -1027,7 +1069,7 @@ var DropColumnCall = class extends PostgresOpFactoryCallNode {
1027
1069
  this.freeze();
1028
1070
  }
1029
1071
  async toOp(lowerer) {
1030
- if (lowerer === void 0) throw new Error(`DropColumnCall.toOp: a lowerer is required on the Postgres planner path (column "${this.columnName}" on table "${this.tableName}"). Pass the control adapter to createPostgresMigrationPlanner.`);
1072
+ if (lowerer === void 0) throw postgresError("MIGRATION.POSTGRES_CONTROL_STACK_MISSING", `DropColumnCall.toOp: a lowerer is required on the Postgres planner path (column "${this.columnName}" on table "${this.tableName}"). Pass the control adapter to createPostgresMigrationPlanner.`, { meta: { factory: "DropColumnCall" } });
1031
1073
  return dropColumn(this.schemaName, this.tableName, this.columnName, lowerer);
1032
1074
  }
1033
1075
  renderTypeScript() {
@@ -1059,7 +1101,7 @@ var AlterColumnTypeCall = class extends PostgresOpFactoryCallNode {
1059
1101
  this.freeze();
1060
1102
  }
1061
1103
  async toOp(lowerer) {
1062
- if (lowerer === void 0) throw new Error(`AlterColumnTypeCall.toOp: a lowerer is required on the Postgres planner path (column "${this.columnName}" on table "${this.tableName}"). Pass the control adapter to createPostgresMigrationPlanner.`);
1104
+ if (lowerer === void 0) throw postgresError("MIGRATION.POSTGRES_CONTROL_STACK_MISSING", `AlterColumnTypeCall.toOp: a lowerer is required on the Postgres planner path (column "${this.columnName}" on table "${this.tableName}"). Pass the control adapter to createPostgresMigrationPlanner.`, { meta: { factory: "AlterColumnTypeCall" } });
1063
1105
  return alterColumnType(this.schemaName, this.tableName, this.columnName, this.options, lowerer);
1064
1106
  }
1065
1107
  renderTypeScript() {
@@ -1090,7 +1132,7 @@ var SetNotNullCall = class extends PostgresOpFactoryCallNode {
1090
1132
  this.freeze();
1091
1133
  }
1092
1134
  async toOp(lowerer) {
1093
- if (lowerer === void 0) throw new Error(`SetNotNullCall.toOp: a lowerer is required on the Postgres planner path (column "${this.columnName}" on table "${this.tableName}"). Pass the control adapter to createPostgresMigrationPlanner.`);
1135
+ if (lowerer === void 0) throw postgresError("MIGRATION.POSTGRES_CONTROL_STACK_MISSING", `SetNotNullCall.toOp: a lowerer is required on the Postgres planner path (column "${this.columnName}" on table "${this.tableName}"). Pass the control adapter to createPostgresMigrationPlanner.`, { meta: { factory: "SetNotNullCall" } });
1094
1136
  return setNotNull(this.schemaName, this.tableName, this.columnName, lowerer);
1095
1137
  }
1096
1138
  renderTypeScript() {
@@ -1120,7 +1162,7 @@ var DropNotNullCall = class extends PostgresOpFactoryCallNode {
1120
1162
  this.freeze();
1121
1163
  }
1122
1164
  async toOp(lowerer) {
1123
- if (lowerer === void 0) throw new Error(`DropNotNullCall.toOp: a lowerer is required on the Postgres planner path (column "${this.columnName}" on table "${this.tableName}"). Pass the control adapter to createPostgresMigrationPlanner.`);
1165
+ if (lowerer === void 0) throw postgresError("MIGRATION.POSTGRES_CONTROL_STACK_MISSING", `DropNotNullCall.toOp: a lowerer is required on the Postgres planner path (column "${this.columnName}" on table "${this.tableName}"). Pass the control adapter to createPostgresMigrationPlanner.`, { meta: { factory: "DropNotNullCall" } });
1124
1166
  return dropNotNull(this.schemaName, this.tableName, this.columnName, lowerer);
1125
1167
  }
1126
1168
  renderTypeScript() {
@@ -1153,7 +1195,7 @@ var SetDefaultCall = class extends PostgresOpFactoryCallNode {
1153
1195
  this.freeze();
1154
1196
  }
1155
1197
  async toOp(lowerer) {
1156
- if (lowerer === void 0) throw new Error(`SetDefaultCall.toOp: a lowerer is required on the Postgres planner path (column "${this.columnName}" on table "${this.tableName}"). Pass the control adapter to createPostgresMigrationPlanner.`);
1198
+ if (lowerer === void 0) throw postgresError("MIGRATION.POSTGRES_CONTROL_STACK_MISSING", `SetDefaultCall.toOp: a lowerer is required on the Postgres planner path (column "${this.columnName}" on table "${this.tableName}"). Pass the control adapter to createPostgresMigrationPlanner.`, { meta: { factory: "SetDefaultCall" } });
1157
1199
  return setDefault(this.schemaName, this.tableName, this.columnName, this.defaultSql, lowerer, this.operationClass);
1158
1200
  }
1159
1201
  renderTypeScript() {
@@ -1185,7 +1227,7 @@ var DropDefaultCall = class extends PostgresOpFactoryCallNode {
1185
1227
  this.freeze();
1186
1228
  }
1187
1229
  async toOp(lowerer) {
1188
- if (lowerer === void 0) throw new Error(`DropDefaultCall.toOp: a lowerer is required on the Postgres planner path (column "${this.columnName}" on table "${this.tableName}"). Pass the control adapter to createPostgresMigrationPlanner.`);
1230
+ if (lowerer === void 0) throw postgresError("MIGRATION.POSTGRES_CONTROL_STACK_MISSING", `DropDefaultCall.toOp: a lowerer is required on the Postgres planner path (column "${this.columnName}" on table "${this.tableName}"). Pass the control adapter to createPostgresMigrationPlanner.`, { meta: { factory: "DropDefaultCall" } });
1189
1231
  return dropDefault(this.schemaName, this.tableName, this.columnName, lowerer);
1190
1232
  }
1191
1233
  renderTypeScript() {
@@ -1225,7 +1267,7 @@ var AddNotNullColumnDirectCall = class extends PostgresOpFactoryCallNode {
1225
1267
  this.freeze();
1226
1268
  }
1227
1269
  async toOp(lowerer) {
1228
- if (lowerer === void 0) throw new Error(`AddNotNullColumnDirectCall.toOp: a lowerer is required on the Postgres planner path (column "${this.columnName}" on table "${this.tableName}"). Pass the control adapter to createPostgresMigrationPlanner.`);
1270
+ if (lowerer === void 0) throw postgresError("MIGRATION.POSTGRES_CONTROL_STACK_MISSING", `AddNotNullColumnDirectCall.toOp: a lowerer is required on the Postgres planner path (column "${this.columnName}" on table "${this.tableName}"). Pass the control adapter to createPostgresMigrationPlanner.`, { meta: { factory: "AddNotNullColumnDirectCall" } });
1229
1271
  return addNotNullColumnDirect(this.schemaName, this.tableName, this.column, lowerer);
1230
1272
  }
1231
1273
  renderTypeScript() {
@@ -1270,7 +1312,7 @@ var AddNotNullColumnWithTempDefaultCall = class extends PostgresOpFactoryCallNod
1270
1312
  this.freeze();
1271
1313
  }
1272
1314
  async toOp(lowerer) {
1273
- if (lowerer === void 0) throw new Error(`AddNotNullColumnWithTempDefaultCall.toOp: a lowerer is required on the Postgres planner path (column "${this.columnName}" on table "${this.tableName}"). Pass the control adapter to createPostgresMigrationPlanner.`);
1315
+ if (lowerer === void 0) throw postgresError("MIGRATION.POSTGRES_CONTROL_STACK_MISSING", `AddNotNullColumnWithTempDefaultCall.toOp: a lowerer is required on the Postgres planner path (column "${this.columnName}" on table "${this.tableName}"). Pass the control adapter to createPostgresMigrationPlanner.`, { meta: { factory: "AddNotNullColumnWithTempDefaultCall" } });
1274
1316
  return buildAddNotNullColumnWithTemporaryDefaultOperation({
1275
1317
  schema: this.schemaName,
1276
1318
  tableName: this.tableName,
@@ -1315,7 +1357,7 @@ var AddPrimaryKeyCall = class extends PostgresOpFactoryCallNode {
1315
1357
  this.freeze();
1316
1358
  }
1317
1359
  async toOp(lowerer) {
1318
- if (lowerer === void 0) throw new Error(`AddPrimaryKeyCall.toOp: a lowerer is required on the Postgres planner path (constraint "${this.constraintName}" on table "${this.tableName}"). Pass the control adapter to createPostgresMigrationPlanner.`);
1360
+ if (lowerer === void 0) throw postgresError("MIGRATION.POSTGRES_CONTROL_STACK_MISSING", `AddPrimaryKeyCall.toOp: a lowerer is required on the Postgres planner path (constraint "${this.constraintName}" on table "${this.tableName}"). Pass the control adapter to createPostgresMigrationPlanner.`, { meta: { factory: "AddPrimaryKeyCall" } });
1319
1361
  return addPrimaryKey(this.schemaName, this.tableName, this.constraintName, this.columns, lowerer);
1320
1362
  }
1321
1363
  renderTypeScript() {
@@ -1343,7 +1385,7 @@ var AddUniqueCall = class extends PostgresOpFactoryCallNode {
1343
1385
  this.freeze();
1344
1386
  }
1345
1387
  async toOp(lowerer) {
1346
- if (lowerer === void 0) throw new Error(`AddUniqueCall.toOp: a lowerer is required on the Postgres planner path (constraint "${this.constraintName}" on table "${this.tableName}"). Pass the control adapter to createPostgresMigrationPlanner.`);
1388
+ if (lowerer === void 0) throw postgresError("MIGRATION.POSTGRES_CONTROL_STACK_MISSING", `AddUniqueCall.toOp: a lowerer is required on the Postgres planner path (constraint "${this.constraintName}" on table "${this.tableName}"). Pass the control adapter to createPostgresMigrationPlanner.`, { meta: { factory: "AddUniqueCall" } });
1347
1389
  return addUnique(this.schemaName, this.tableName, this.constraintName, this.columns, lowerer);
1348
1390
  }
1349
1391
  renderTypeScript() {
@@ -1369,7 +1411,7 @@ var AddForeignKeyCall = class extends PostgresOpFactoryCallNode {
1369
1411
  this.freeze();
1370
1412
  }
1371
1413
  async toOp(lowerer) {
1372
- if (lowerer === void 0) throw new Error(`AddForeignKeyCall.toOp: a lowerer is required on the Postgres planner path (constraint "${this.fk.name}" on table "${this.tableName}"). Pass the control adapter to createPostgresMigrationPlanner.`);
1414
+ if (lowerer === void 0) throw postgresError("MIGRATION.POSTGRES_CONTROL_STACK_MISSING", `AddForeignKeyCall.toOp: a lowerer is required on the Postgres planner path (constraint "${this.fk.name}" on table "${this.tableName}"). Pass the control adapter to createPostgresMigrationPlanner.`, { meta: { factory: "AddForeignKeyCall" } });
1373
1415
  return addForeignKey(this.schemaName, this.tableName, this.fk, lowerer);
1374
1416
  }
1375
1417
  renderTypeScript() {
@@ -1401,7 +1443,7 @@ var DropConstraintCall = class extends PostgresOpFactoryCallNode {
1401
1443
  this.freeze();
1402
1444
  }
1403
1445
  async toOp(lowerer) {
1404
- if (lowerer === void 0) throw new Error(`DropConstraintCall.toOp: a lowerer is required on the Postgres planner path (constraint "${this.constraintName}" on table "${this.tableName}"). Pass the control adapter to createPostgresMigrationPlanner.`);
1446
+ if (lowerer === void 0) throw postgresError("MIGRATION.POSTGRES_CONTROL_STACK_MISSING", `DropConstraintCall.toOp: a lowerer is required on the Postgres planner path (constraint "${this.constraintName}" on table "${this.tableName}"). Pass the control adapter to createPostgresMigrationPlanner.`, { meta: { factory: "DropConstraintCall" } });
1405
1447
  return dropConstraint(this.schemaName, this.tableName, this.constraintName, lowerer, this.kind);
1406
1448
  }
1407
1449
  renderTypeScript() {
@@ -1433,7 +1475,7 @@ var AddCheckConstraintCall = class extends PostgresOpFactoryCallNode {
1433
1475
  this.freeze();
1434
1476
  }
1435
1477
  async toOp(lowerer) {
1436
- if (lowerer === void 0) throw new Error(`AddCheckConstraintCall.toOp: a lowerer is required on the Postgres planner path (constraint "${this.constraintName}" on table "${this.tableName}"). Pass the control adapter to createPostgresMigrationPlanner.`);
1478
+ if (lowerer === void 0) throw postgresError("MIGRATION.POSTGRES_CONTROL_STACK_MISSING", `AddCheckConstraintCall.toOp: a lowerer is required on the Postgres planner path (constraint "${this.constraintName}" on table "${this.tableName}"). Pass the control adapter to createPostgresMigrationPlanner.`, { meta: { factory: "AddCheckConstraintCall" } });
1437
1479
  return addCheckConstraint(this.schemaName, this.tableName, this.constraintName, this.column, this.values, lowerer);
1438
1480
  }
1439
1481
  renderTypeScript() {
@@ -1459,7 +1501,7 @@ var DropCheckConstraintCall = class extends PostgresOpFactoryCallNode {
1459
1501
  this.freeze();
1460
1502
  }
1461
1503
  async toOp(lowerer) {
1462
- if (lowerer === void 0) throw new Error(`DropCheckConstraintCall.toOp: a lowerer is required on the Postgres planner path (constraint "${this.constraintName}" on table "${this.tableName}"). Pass the control adapter to createPostgresMigrationPlanner.`);
1504
+ if (lowerer === void 0) throw postgresError("MIGRATION.POSTGRES_CONTROL_STACK_MISSING", `DropCheckConstraintCall.toOp: a lowerer is required on the Postgres planner path (constraint "${this.constraintName}" on table "${this.tableName}"). Pass the control adapter to createPostgresMigrationPlanner.`, { meta: { factory: "DropCheckConstraintCall" } });
1463
1505
  return dropCheckConstraint(this.schemaName, this.tableName, this.constraintName, lowerer);
1464
1506
  }
1465
1507
  renderTypeScript() {
@@ -1475,38 +1517,51 @@ var CreateIndexCall = class extends PostgresOpFactoryCallNode {
1475
1517
  schemaName;
1476
1518
  tableName;
1477
1519
  indexName;
1520
+ /** Column tuple when the index is column-based; absent for expression indexes. */
1478
1521
  columns;
1522
+ /** Opaque whole element list when the index is expression-based. */
1523
+ expression;
1479
1524
  indexType;
1480
1525
  options;
1526
+ where;
1527
+ unique;
1481
1528
  label;
1482
- constructor(schemaName, tableName, indexName, columns, extras) {
1529
+ constructor(schemaName, tableName, indexName, elements, extras) {
1483
1530
  super();
1484
1531
  this.schemaName = schemaName;
1485
1532
  this.tableName = tableName;
1486
1533
  this.indexName = indexName;
1487
- this.columns = columns;
1534
+ this.columns = "columns" in elements ? elements.columns : void 0;
1535
+ this.expression = "expression" in elements ? elements.expression : void 0;
1488
1536
  this.indexType = extras?.type;
1489
1537
  this.options = extras?.options;
1538
+ this.where = extras?.where;
1539
+ this.unique = extras?.unique === true;
1490
1540
  this.label = `Create index "${indexName}" on "${tableName}"`;
1491
1541
  this.freeze();
1492
1542
  }
1493
1543
  async toOp(lowerer) {
1494
- if (lowerer === void 0) throw new Error(`CreateIndexCall.toOp: a lowerer is required on the Postgres planner path (index "${this.indexName}" on table "${this.tableName}"). Pass the control adapter to createPostgresMigrationPlanner.`);
1544
+ if (lowerer === void 0) throw postgresError("MIGRATION.POSTGRES_CONTROL_STACK_MISSING", `CreateIndexCall.toOp: a lowerer is required on the Postgres planner path (index "${this.indexName}" on table "${this.tableName}"). Pass the control adapter to createPostgresMigrationPlanner.`, { meta: { factory: "CreateIndexCall" } });
1495
1545
  const extras = {};
1496
1546
  if (this.indexType !== void 0) extras.type = this.indexType;
1497
1547
  if (this.options !== void 0) extras.options = this.options;
1498
- return createIndex(this.schemaName, this.tableName, this.indexName, this.columns, lowerer, extras);
1548
+ if (this.where !== void 0) extras.where = this.where;
1549
+ if (this.unique) extras.unique = true;
1550
+ return createIndex(this.schemaName, this.tableName, this.indexName, this.columns !== void 0 ? { columns: this.columns } : { expression: this.expression ?? "" }, lowerer, extras);
1499
1551
  }
1500
1552
  renderTypeScript() {
1501
1553
  const opts = [];
1502
1554
  if (this.schemaName !== UNBOUND_NAMESPACE_ID) opts.push(`schema: ${jsonToTsSource(this.schemaName)}`);
1503
1555
  opts.push(`table: ${jsonToTsSource(this.tableName)}`);
1504
1556
  opts.push(`index: ${jsonToTsSource(this.indexName)}`);
1505
- opts.push(`columns: ${jsonToTsSource(this.columns)}`);
1506
- if (this.indexType !== void 0 || this.options !== void 0) {
1557
+ if (this.columns !== void 0) opts.push(`columns: ${jsonToTsSource(this.columns)}`);
1558
+ else opts.push(`expression: ${jsonToTsSource(this.expression ?? "")}`);
1559
+ if (this.indexType !== void 0 || this.options !== void 0 || this.where !== void 0 || this.unique) {
1507
1560
  const extrasParts = [];
1508
1561
  if (this.indexType !== void 0) extrasParts.push(`type: ${jsonToTsSource(this.indexType)}`);
1509
1562
  if (this.options !== void 0) extrasParts.push(`options: ${jsonToTsSource(this.options)}`);
1563
+ if (this.where !== void 0) extrasParts.push(`where: ${jsonToTsSource(this.where)}`);
1564
+ if (this.unique) extrasParts.push("unique: true");
1510
1565
  opts.push(`extras: { ${extrasParts.join(", ")} }`);
1511
1566
  }
1512
1567
  return `this.createIndex({ ${opts.join(", ")} })`;
@@ -1515,6 +1570,39 @@ var CreateIndexCall = class extends PostgresOpFactoryCallNode {
1515
1570
  return [];
1516
1571
  }
1517
1572
  };
1573
+ var RenameIndexCall = class extends PostgresOpFactoryCallNode {
1574
+ factoryName = "renameIndex";
1575
+ operationClass = "widening";
1576
+ schemaName;
1577
+ tableName;
1578
+ oldIndexName;
1579
+ newIndexName;
1580
+ label;
1581
+ constructor(schemaName, tableName, oldIndexName, newIndexName) {
1582
+ super();
1583
+ this.schemaName = schemaName;
1584
+ this.tableName = tableName;
1585
+ this.oldIndexName = oldIndexName;
1586
+ this.newIndexName = newIndexName;
1587
+ this.label = `Rename index "${oldIndexName}" to "${newIndexName}" on "${tableName}"`;
1588
+ this.freeze();
1589
+ }
1590
+ async toOp(lowerer) {
1591
+ if (lowerer === void 0) throw postgresError("MIGRATION.POSTGRES_CONTROL_STACK_MISSING", `RenameIndexCall.toOp: a lowerer is required on the Postgres planner path (index "${this.oldIndexName}" on table "${this.tableName}"). Pass the control adapter to createPostgresMigrationPlanner.`, { meta: { factory: "RenameIndexCall" } });
1592
+ return renameIndex(this.schemaName, this.tableName, this.oldIndexName, this.newIndexName, lowerer);
1593
+ }
1594
+ renderTypeScript() {
1595
+ const opts = [];
1596
+ if (this.schemaName !== UNBOUND_NAMESPACE_ID) opts.push(`schema: ${jsonToTsSource(this.schemaName)}`);
1597
+ opts.push(`table: ${jsonToTsSource(this.tableName)}`);
1598
+ opts.push(`from: ${jsonToTsSource(this.oldIndexName)}`);
1599
+ opts.push(`to: ${jsonToTsSource(this.newIndexName)}`);
1600
+ return `this.renameIndex({ ${opts.join(", ")} })`;
1601
+ }
1602
+ importRequirements() {
1603
+ return [];
1604
+ }
1605
+ };
1518
1606
  var DropIndexCall = class extends PostgresOpFactoryCallNode {
1519
1607
  factoryName = "dropIndex";
1520
1608
  operationClass = "destructive";
@@ -1531,7 +1619,7 @@ var DropIndexCall = class extends PostgresOpFactoryCallNode {
1531
1619
  this.freeze();
1532
1620
  }
1533
1621
  async toOp(lowerer) {
1534
- if (lowerer === void 0) throw new Error(`DropIndexCall.toOp: a lowerer is required on the Postgres planner path (index "${this.indexName}" on table "${this.tableName}"). Pass the control adapter to createPostgresMigrationPlanner.`);
1622
+ if (lowerer === void 0) throw postgresError("MIGRATION.POSTGRES_CONTROL_STACK_MISSING", `DropIndexCall.toOp: a lowerer is required on the Postgres planner path (index "${this.indexName}" on table "${this.tableName}"). Pass the control adapter to createPostgresMigrationPlanner.`, { meta: { factory: "DropIndexCall" } });
1535
1623
  return dropIndex(this.schemaName, this.tableName, this.indexName, lowerer);
1536
1624
  }
1537
1625
  renderTypeScript() {
@@ -1607,7 +1695,7 @@ var CreateSchemaCall = class extends PostgresOpFactoryCallNode {
1607
1695
  this.freeze();
1608
1696
  }
1609
1697
  async toOp(lowerer) {
1610
- if (lowerer === void 0) throw new Error(`CreateSchemaCall.toOp: a DDL lowerer is required on the Postgres planner path (schema "${this.schemaName}"). Pass the control adapter to createPostgresMigrationPlanner.`);
1698
+ if (lowerer === void 0) throw postgresError("MIGRATION.POSTGRES_CONTROL_STACK_MISSING", `CreateSchemaCall.toOp: a DDL lowerer is required on the Postgres planner path (schema "${this.schemaName}"). Pass the control adapter to createPostgresMigrationPlanner.`, { meta: { factory: "CreateSchemaCall" } });
1611
1699
  const ddlNode = createSchema({
1612
1700
  schema: this.schemaName,
1613
1701
  ifNotExists: true
@@ -1651,7 +1739,7 @@ var CreateNativeEnumTypeCall = class extends PostgresOpFactoryCallNode {
1651
1739
  this.freeze();
1652
1740
  }
1653
1741
  async toOp(lowerer) {
1654
- if (lowerer === void 0) throw new Error(`CreateNativeEnumTypeCall.toOp: a DDL lowerer is required on the Postgres planner path (type "${this.typeName}"). Pass the control adapter to createPostgresMigrationPlanner.`);
1742
+ if (lowerer === void 0) throw postgresError("MIGRATION.POSTGRES_CONTROL_STACK_MISSING", `CreateNativeEnumTypeCall.toOp: a DDL lowerer is required on the Postgres planner path (type "${this.typeName}"). Pass the control adapter to createPostgresMigrationPlanner.`, { meta: { factory: "CreateNativeEnumTypeCall" } });
1655
1743
  return createNativeEnumType(this.schemaName, this.typeName, this.members, lowerer);
1656
1744
  }
1657
1745
  renderTypeScript() {
@@ -1679,7 +1767,7 @@ var DropNativeEnumTypeCall = class extends PostgresOpFactoryCallNode {
1679
1767
  this.freeze();
1680
1768
  }
1681
1769
  async toOp(lowerer) {
1682
- if (lowerer === void 0) throw new Error(`DropNativeEnumTypeCall.toOp: a DDL lowerer is required on the Postgres planner path (type "${this.typeName}"). Pass the control adapter to createPostgresMigrationPlanner.`);
1770
+ if (lowerer === void 0) throw postgresError("MIGRATION.POSTGRES_CONTROL_STACK_MISSING", `DropNativeEnumTypeCall.toOp: a DDL lowerer is required on the Postgres planner path (type "${this.typeName}"). Pass the control adapter to createPostgresMigrationPlanner.`, { meta: { factory: "DropNativeEnumTypeCall" } });
1683
1771
  return dropNativeEnumType(this.schemaName, this.typeName, lowerer);
1684
1772
  }
1685
1773
  renderTypeScript() {
@@ -1724,7 +1812,7 @@ var AddNativeEnumValueCall = class extends PostgresOpFactoryCallNode {
1724
1812
  this.freeze();
1725
1813
  }
1726
1814
  async toOp(lowerer) {
1727
- if (lowerer === void 0) throw new Error(`AddNativeEnumValueCall.toOp: a lowerer is required on the Postgres planner path (type "${this.typeName}"). Pass the control adapter to createPostgresMigrationPlanner.`);
1815
+ if (lowerer === void 0) throw postgresError("MIGRATION.POSTGRES_CONTROL_STACK_MISSING", `AddNativeEnumValueCall.toOp: a lowerer is required on the Postgres planner path (type "${this.typeName}"). Pass the control adapter to createPostgresMigrationPlanner.`, { meta: { factory: "AddNativeEnumValueCall" } });
1728
1816
  const { schemaName, typeName, value } = this;
1729
1817
  const typeChecks = nativeEnumTypeExistsAst(schemaName, typeName);
1730
1818
  const valueChecks = nativeEnumValueExistsAst({
@@ -1794,11 +1882,6 @@ var DataTransformCall = class extends PostgresOpFactoryCallNode {
1794
1882
  return [{
1795
1883
  moduleSpecifier: POSTGRES_MIGRATION_FACADE,
1796
1884
  symbol: "placeholder"
1797
- }, {
1798
- moduleSpecifier: "./end-contract.json",
1799
- symbol: "endContract",
1800
- kind: "default",
1801
- attributes: { type: "json" }
1802
1885
  }];
1803
1886
  }
1804
1887
  };
@@ -1818,7 +1901,7 @@ var CreatePostgresRlsPolicyCall = class extends PostgresOpFactoryCallNode {
1818
1901
  this.freeze();
1819
1902
  }
1820
1903
  async toOp(lowerer) {
1821
- if (lowerer === void 0) throw new Error(`CreatePostgresRlsPolicyCall.toOp: a lowerer is required on the Postgres planner path (policy "${this.policy.name}" on table "${this.tableName}"). Pass the control adapter to createPostgresMigrationPlanner.`);
1904
+ if (lowerer === void 0) throw postgresError("MIGRATION.POSTGRES_CONTROL_STACK_MISSING", `CreatePostgresRlsPolicyCall.toOp: a lowerer is required on the Postgres planner path (policy "${this.policy.name}" on table "${this.tableName}"). Pass the control adapter to createPostgresMigrationPlanner.`, { meta: { factory: "CreatePostgresRlsPolicyCall" } });
1822
1905
  return createRlsPolicy(this.schemaName, this.tableName, this.policy, lowerer);
1823
1906
  }
1824
1907
  renderTypeScript() {
@@ -1856,7 +1939,7 @@ var DropPostgresRlsPolicyCall = class extends PostgresOpFactoryCallNode {
1856
1939
  this.freeze();
1857
1940
  }
1858
1941
  async toOp(lowerer) {
1859
- if (lowerer === void 0) throw new Error(`DropPostgresRlsPolicyCall.toOp: a lowerer is required on the Postgres planner path (policy "${this.policyName}" on table "${this.tableName}"). Pass the control adapter to createPostgresMigrationPlanner.`);
1942
+ if (lowerer === void 0) throw postgresError("MIGRATION.POSTGRES_CONTROL_STACK_MISSING", `DropPostgresRlsPolicyCall.toOp: a lowerer is required on the Postgres planner path (policy "${this.policyName}" on table "${this.tableName}"). Pass the control adapter to createPostgresMigrationPlanner.`, { meta: { factory: "DropPostgresRlsPolicyCall" } });
1860
1943
  return dropRlsPolicy(this.schemaName, this.tableName, this.policyName, lowerer);
1861
1944
  }
1862
1945
  renderTypeScript() {
@@ -1880,7 +1963,7 @@ var EnableRowLevelSecurityCall = class extends PostgresOpFactoryCallNode {
1880
1963
  this.freeze();
1881
1964
  }
1882
1965
  async toOp(lowerer) {
1883
- if (lowerer === void 0) throw new Error(`EnableRowLevelSecurityCall.toOp: a lowerer is required on the Postgres planner path (table "${this.tableName}"). Pass the control adapter to createPostgresMigrationPlanner.`);
1966
+ if (lowerer === void 0) throw postgresError("MIGRATION.POSTGRES_CONTROL_STACK_MISSING", `EnableRowLevelSecurityCall.toOp: a lowerer is required on the Postgres planner path (table "${this.tableName}"). Pass the control adapter to createPostgresMigrationPlanner.`, { meta: { factory: "EnableRowLevelSecurityCall" } });
1884
1967
  return enableRowLevelSecurity(this.schemaName, this.tableName, lowerer);
1885
1968
  }
1886
1969
  renderTypeScript() {
@@ -1904,7 +1987,7 @@ var DisableRowLevelSecurityCall = class extends PostgresOpFactoryCallNode {
1904
1987
  this.freeze();
1905
1988
  }
1906
1989
  async toOp(lowerer) {
1907
- if (lowerer === void 0) throw new Error(`DisableRowLevelSecurityCall.toOp: a lowerer is required on the Postgres planner path (table "${this.tableName}"). Pass the control adapter to createPostgresMigrationPlanner.`);
1990
+ if (lowerer === void 0) throw postgresError("MIGRATION.POSTGRES_CONTROL_STACK_MISSING", `DisableRowLevelSecurityCall.toOp: a lowerer is required on the Postgres planner path (table "${this.tableName}"). Pass the control adapter to createPostgresMigrationPlanner.`, { meta: { factory: "DisableRowLevelSecurityCall" } });
1908
1991
  return disableRowLevelSecurity(this.schemaName, this.tableName, lowerer);
1909
1992
  }
1910
1993
  renderTypeScript() {
@@ -1932,7 +2015,7 @@ var RenamePostgresRlsPolicyCall = class extends PostgresOpFactoryCallNode {
1932
2015
  this.freeze();
1933
2016
  }
1934
2017
  async toOp(lowerer) {
1935
- if (lowerer === void 0) throw new Error(`RenamePostgresRlsPolicyCall.toOp: a lowerer is required on the Postgres planner path (policy "${this.oldPolicyName}" on table "${this.tableName}"). Pass the control adapter to createPostgresMigrationPlanner.`);
2018
+ if (lowerer === void 0) throw postgresError("MIGRATION.POSTGRES_CONTROL_STACK_MISSING", `RenamePostgresRlsPolicyCall.toOp: a lowerer is required on the Postgres planner path (policy "${this.oldPolicyName}" on table "${this.tableName}"). Pass the control adapter to createPostgresMigrationPlanner.`, { meta: { factory: "RenamePostgresRlsPolicyCall" } });
1936
2019
  return renameRlsPolicy(this.schemaName, this.tableName, this.oldPolicyName, this.newPolicyName, lowerer);
1937
2020
  }
1938
2021
  renderTypeScript() {
@@ -1943,6 +2026,6 @@ var RenamePostgresRlsPolicyCall = class extends PostgresOpFactoryCallNode {
1943
2026
  }
1944
2027
  };
1945
2028
  //#endregion
1946
- export { SetDefaultCall as A, DropNativeEnumTypeCall as C, EnableRowLevelSecurityCall as D, DropTableCall as E, installExtension as F, postgresDefaultToDdlColumnDefault as M, buildTargetDetails as N, RawSqlCall as O, createExtension as P, DropIndexCall as S, DropPostgresRlsPolicyCall as T, DisableRowLevelSecurityCall as _, AddNotNullColumnDirectCall as a, DropConstraintCall as b, AddUniqueCall as c, CreateIndexCall as d, CreateNativeEnumTypeCall as f, DataTransformCall as g, CreateTableCall as h, AddNativeEnumValueCall as i, SetNotNullCall as j, RenamePostgresRlsPolicyCall as k, AlterColumnTypeCall as l, CreateSchemaCall as m, AddColumnCall as n, AddNotNullColumnWithTempDefaultCall as o, CreatePostgresRlsPolicyCall as p, AddForeignKeyCall as r, AddPrimaryKeyCall as s, AddCheckConstraintCall as t, CreateExtensionCall as u, DropCheckConstraintCall as v, DropNotNullCall as w, DropDefaultCall as x, DropColumnCall as y };
2029
+ export { RenamePostgresRlsPolicyCall as A, DropNativeEnumTypeCall as C, EnableRowLevelSecurityCall as D, DropTableCall as E, createExtension as F, installExtension as I, SetNotNullCall as M, postgresDefaultToDdlColumnDefault as N, RawSqlCall as O, buildTargetDetails as P, DropIndexCall as S, DropPostgresRlsPolicyCall as T, DisableRowLevelSecurityCall as _, AddNotNullColumnDirectCall as a, DropConstraintCall as b, AddUniqueCall as c, CreateIndexCall as d, CreateNativeEnumTypeCall as f, DataTransformCall as g, CreateTableCall as h, AddNativeEnumValueCall as i, SetDefaultCall as j, RenameIndexCall as k, AlterColumnTypeCall as l, CreateSchemaCall as m, AddColumnCall as n, AddNotNullColumnWithTempDefaultCall as o, CreatePostgresRlsPolicyCall as p, AddForeignKeyCall as r, AddPrimaryKeyCall as s, AddCheckConstraintCall as t, CreateExtensionCall as u, DropCheckConstraintCall as v, DropNotNullCall as w, DropDefaultCall as x, DropColumnCall as y };
1947
2030
 
1948
- //# sourceMappingURL=op-factory-call-DuRj7WXX.mjs.map
2031
+ //# sourceMappingURL=op-factory-call-CIaPDDUc.mjs.map