@prisma-next/target-postgres 0.16.0-dev.21 → 0.16.0-dev.23

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 (92) hide show
  1. package/dist/{authoring-34L18kA1.mjs → authoring-BCzcFRay.mjs} +27 -9
  2. package/dist/authoring-BCzcFRay.mjs.map +1 -0
  3. package/dist/codecs-CGE5dh94.d.mts.map +1 -1
  4. package/dist/{codecs-DOgD_C1A.mjs → codecs-Deand7sy.mjs} +75 -19
  5. package/dist/codecs-Deand7sy.mjs.map +1 -0
  6. package/dist/codecs.mjs +1 -1
  7. package/dist/contract-free.mjs +2 -2
  8. package/dist/{control-policy-BrcqeM82.mjs → control-policy-B-_34g05.mjs} +8 -7
  9. package/dist/control-policy-B-_34g05.mjs.map +1 -0
  10. package/dist/control.mjs +28 -17
  11. package/dist/control.mjs.map +1 -1
  12. package/dist/{ddl-DHXKzQ99.mjs → ddl-DYEob9xQ.mjs} +2 -2
  13. package/dist/{ddl-DHXKzQ99.mjs.map → ddl-DYEob9xQ.mjs.map} +1 -1
  14. package/dist/{descriptor-meta-CiYV9DzH.mjs → descriptor-meta-D_0ZKcj-.mjs} +4 -4
  15. package/dist/{descriptor-meta-CiYV9DzH.mjs.map → descriptor-meta-D_0ZKcj-.mjs.map} +1 -1
  16. package/dist/{diff-database-schema-CK0FM2Z-.mjs → diff-database-schema-C9H09OD3.mjs} +17 -6
  17. package/dist/diff-database-schema-C9H09OD3.mjs.map +1 -0
  18. package/dist/diff-database-schema.mjs +1 -1
  19. package/dist/{errors-ByDS0xJL.mjs → errors-DBSNx7EJ.mjs} +6 -2
  20. package/dist/errors-DBSNx7EJ.mjs.map +1 -0
  21. package/dist/errors.d.mts +1 -0
  22. package/dist/errors.d.mts.map +1 -1
  23. package/dist/errors.mjs +1 -1
  24. package/dist/issue-planner.mjs +1 -1
  25. package/dist/migration.mjs +2 -2
  26. package/dist/{op-factory-call-PBYfcv8h.mjs → op-factory-call-BVYLIojV.mjs} +49 -38
  27. package/dist/op-factory-call-BVYLIojV.mjs.map +1 -0
  28. package/dist/op-factory-call-DT7kdjVP.d.mts.map +1 -1
  29. package/dist/op-factory-call.mjs +1 -1
  30. package/dist/pack.d.mts.map +1 -1
  31. package/dist/pack.mjs +1 -1
  32. package/dist/{planner-CiXCo6BT.mjs → planner-4sj5cJCY.mjs} +7 -7
  33. package/dist/{planner-CiXCo6BT.mjs.map → planner-4sj5cJCY.mjs.map} +1 -1
  34. package/dist/{planner-ddl-builders-AIpFmG1i.mjs → planner-ddl-builders-CVo3L7Nd.mjs} +11 -7
  35. package/dist/planner-ddl-builders-CVo3L7Nd.mjs.map +1 -0
  36. package/dist/planner-ddl-builders.d.mts.map +1 -1
  37. package/dist/planner-ddl-builders.mjs +1 -1
  38. package/dist/{planner-produced-postgres-migration-PIgjJYrY.mjs → planner-produced-postgres-migration-CcQPDWmX.mjs} +3 -3
  39. package/dist/{planner-produced-postgres-migration-PIgjJYrY.mjs.map → planner-produced-postgres-migration-CcQPDWmX.mjs.map} +1 -1
  40. package/dist/planner-produced-postgres-migration.mjs +1 -1
  41. package/dist/{planner-sql-checks-BuB877wH.mjs → planner-sql-checks-CmiQ6Nei.mjs} +3 -3
  42. package/dist/{planner-sql-checks-BuB877wH.mjs.map → planner-sql-checks-CmiQ6Nei.mjs.map} +1 -1
  43. package/dist/planner-sql-checks.mjs +1 -1
  44. package/dist/planner.d.mts.map +1 -1
  45. package/dist/planner.mjs +2 -2
  46. package/dist/{postgres-contract-view-DebHMqGR.mjs → postgres-contract-view-B8yXVWYe.mjs} +3 -3
  47. package/dist/{postgres-contract-view-DebHMqGR.mjs.map → postgres-contract-view-B8yXVWYe.mjs.map} +1 -1
  48. package/dist/postgres-migration-DLIvzHjX.d.mts.map +1 -1
  49. package/dist/{postgres-migration-BkIplcRz.mjs → postgres-migration-GIOABsAa.mjs} +5 -5
  50. package/dist/{postgres-migration-BkIplcRz.mjs.map → postgres-migration-GIOABsAa.mjs.map} +1 -1
  51. package/dist/{postgres-schema-CewLYHB7.mjs → postgres-schema-CTplQZDK.mjs} +2 -2
  52. package/dist/{postgres-schema-CewLYHB7.mjs.map → postgres-schema-CTplQZDK.mjs.map} +1 -1
  53. package/dist/{render-ops-BREh1kHe.mjs → render-ops-TcY9XEkz.mjs} +7 -2
  54. package/dist/render-ops-TcY9XEkz.mjs.map +1 -0
  55. package/dist/render-ops.d.mts.map +1 -1
  56. package/dist/render-ops.mjs +1 -1
  57. package/dist/{resolve-ddl-schema-D0wi_P9Q.mjs → resolve-ddl-schema-BAsJEKW8.mjs} +2 -2
  58. package/dist/{resolve-ddl-schema-D0wi_P9Q.mjs.map → resolve-ddl-schema-BAsJEKW8.mjs.map} +1 -1
  59. package/dist/runtime.mjs +1 -1
  60. package/dist/schema-ir-annotations.mjs +1 -1
  61. package/dist/{sql-utils-SU4FDvIV.mjs → sql-utils-B2lzkKfP.mjs} +22 -19
  62. package/dist/sql-utils-B2lzkKfP.mjs.map +1 -0
  63. package/dist/sql-utils.d.mts +4 -9
  64. package/dist/sql-utils.d.mts.map +1 -1
  65. package/dist/sql-utils.mjs +2 -2
  66. package/dist/types.mjs +1 -1
  67. package/package.json +20 -20
  68. package/src/core/authoring.ts +28 -7
  69. package/src/core/codec-helpers.ts +69 -16
  70. package/src/core/codecs.ts +11 -2
  71. package/src/core/errors.ts +30 -0
  72. package/src/core/migrations/column-ddl-rendering.ts +2 -1
  73. package/src/core/migrations/contract-to-postgres-database-schema-node.ts +14 -2
  74. package/src/core/migrations/op-factory-call.ts +88 -29
  75. package/src/core/migrations/operations/constraints.ts +3 -2
  76. package/src/core/migrations/operations/indexes.ts +4 -1
  77. package/src/core/migrations/operations/rls.ts +4 -1
  78. package/src/core/migrations/planner-ddl-builders.ts +13 -4
  79. package/src/core/migrations/render-ops.ts +4 -1
  80. package/src/core/migrations/runner.ts +7 -3
  81. package/src/core/psl-infer/infer-psl-contract.ts +22 -6
  82. package/src/core/sql-utils.ts +16 -27
  83. package/src/exports/sql-utils.ts +0 -1
  84. package/dist/authoring-34L18kA1.mjs.map +0 -1
  85. package/dist/codecs-DOgD_C1A.mjs.map +0 -1
  86. package/dist/control-policy-BrcqeM82.mjs.map +0 -1
  87. package/dist/diff-database-schema-CK0FM2Z-.mjs.map +0 -1
  88. package/dist/errors-ByDS0xJL.mjs.map +0 -1
  89. package/dist/op-factory-call-PBYfcv8h.mjs.map +0 -1
  90. package/dist/planner-ddl-builders-AIpFmG1i.mjs.map +0 -1
  91. package/dist/render-ops-BREh1kHe.mjs.map +0 -1
  92. package/dist/sql-utils-SU4FDvIV.mjs.map +0 -1
@@ -38,6 +38,7 @@ import { FunctionColumnDefault, LiteralColumnDefault } from '@prisma-next/sql-re
38
38
  import { type ImportRequirement, jsonToTsSource, TsExpression } from '@prisma-next/ts-render';
39
39
  import { blindCast } from '@prisma-next/utils/casts';
40
40
  import { ifDefined } from '@prisma-next/utils/defined';
41
+ import { assertNever } from '@prisma-next/utils/internal-error';
41
42
  import {
42
43
  columnExistsAst,
43
44
  nativeEnumTypeExistsAst,
@@ -45,6 +46,7 @@ import {
45
46
  tableExistsAst,
46
47
  } from '../../contract-free/checks';
47
48
  import * as contractFreeDdl from '../../contract-free/ddl';
49
+ import { postgresError } from '../errors';
48
50
  import type { PostgresRlsPolicy, PostgresRlsPolicyInput } from '../postgres-rls-policy';
49
51
  import {
50
52
  escapeLiteral,
@@ -138,7 +140,8 @@ export function postgresDefaultToDdlColumnDefault(
138
140
  );
139
141
  default: {
140
142
  const exhaustive: never = columnDefault;
141
- throw new Error(
143
+ return assertNever(
144
+ exhaustive,
142
145
  `postgresDefaultToDdlColumnDefault: unhandled kind "${blindCast<{ kind: string }, 'exhaustiveness: surface the unhandled default kind'>(exhaustive).kind}"`,
143
146
  );
144
147
  }
@@ -241,8 +244,10 @@ export class CreateTableCall extends PostgresOpFactoryCallNode {
241
244
 
242
245
  async toOp(lowerer?: ExecuteRequestLowerer): Promise<Op> {
243
246
  if (lowerer === undefined) {
244
- throw new Error(
247
+ throw postgresError(
248
+ 'MIGRATION.POSTGRES_CONTROL_STACK_MISSING',
245
249
  `CreateTableCall.toOp: a DDL lowerer is required on the Postgres planner path (table "${this.tableName}"). Pass the control adapter to createPostgresMigrationPlanner.`,
250
+ { meta: { factory: 'CreateTableCall' } },
246
251
  );
247
252
  }
248
253
  const ddlNode = contractFreeDdl.createTable({
@@ -324,8 +329,10 @@ export class DropTableCall extends PostgresOpFactoryCallNode {
324
329
 
325
330
  async toOp(lowerer?: ExecuteRequestLowerer): Promise<Op> {
326
331
  if (lowerer === undefined) {
327
- throw new Error(
332
+ throw postgresError(
333
+ 'MIGRATION.POSTGRES_CONTROL_STACK_MISSING',
328
334
  `DropTableCall.toOp: a lowerer is required on the Postgres planner path (table "${this.tableName}"). Pass the control adapter to createPostgresMigrationPlanner.`,
335
+ { meta: { factory: 'DropTableCall' } },
329
336
  );
330
337
  }
331
338
  return dropTable(this.schemaName, this.tableName, lowerer);
@@ -368,8 +375,10 @@ export class AddColumnCall extends PostgresOpFactoryCallNode {
368
375
 
369
376
  async toOp(lowerer?: ExecuteRequestLowerer): Promise<Op> {
370
377
  if (lowerer === undefined) {
371
- throw new Error(
378
+ throw postgresError(
379
+ 'MIGRATION.POSTGRES_CONTROL_STACK_MISSING',
372
380
  `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.`,
381
+ { meta: { factory: 'AddColumnCall' } },
373
382
  );
374
383
  }
375
384
  const ddlNode = contractFreeDdl.alterTable({
@@ -435,8 +444,10 @@ export class DropColumnCall extends PostgresOpFactoryCallNode {
435
444
 
436
445
  async toOp(lowerer?: ExecuteRequestLowerer): Promise<Op> {
437
446
  if (lowerer === undefined) {
438
- throw new Error(
447
+ throw postgresError(
448
+ 'MIGRATION.POSTGRES_CONTROL_STACK_MISSING',
439
449
  `DropColumnCall.toOp: a lowerer is required on the Postgres planner path (column "${this.columnName}" on table "${this.tableName}"). Pass the control adapter to createPostgresMigrationPlanner.`,
450
+ { meta: { factory: 'DropColumnCall' } },
440
451
  );
441
452
  }
442
453
  return dropColumn(this.schemaName, this.tableName, this.columnName, lowerer);
@@ -490,8 +501,10 @@ export class AlterColumnTypeCall extends PostgresOpFactoryCallNode {
490
501
 
491
502
  async toOp(lowerer?: ExecuteRequestLowerer): Promise<Op> {
492
503
  if (lowerer === undefined) {
493
- throw new Error(
504
+ throw postgresError(
505
+ 'MIGRATION.POSTGRES_CONTROL_STACK_MISSING',
494
506
  `AlterColumnTypeCall.toOp: a lowerer is required on the Postgres planner path (column "${this.columnName}" on table "${this.tableName}"). Pass the control adapter to createPostgresMigrationPlanner.`,
507
+ { meta: { factory: 'AlterColumnTypeCall' } },
495
508
  );
496
509
  }
497
510
  return alterColumnType(this.schemaName, this.tableName, this.columnName, this.options, lowerer);
@@ -532,8 +545,10 @@ export class SetNotNullCall extends PostgresOpFactoryCallNode {
532
545
 
533
546
  async toOp(lowerer?: ExecuteRequestLowerer): Promise<Op> {
534
547
  if (lowerer === undefined) {
535
- throw new Error(
548
+ throw postgresError(
549
+ 'MIGRATION.POSTGRES_CONTROL_STACK_MISSING',
536
550
  `SetNotNullCall.toOp: a lowerer is required on the Postgres planner path (column "${this.columnName}" on table "${this.tableName}"). Pass the control adapter to createPostgresMigrationPlanner.`,
551
+ { meta: { factory: 'SetNotNullCall' } },
537
552
  );
538
553
  }
539
554
  return setNotNull(this.schemaName, this.tableName, this.columnName, lowerer);
@@ -573,8 +588,10 @@ export class DropNotNullCall extends PostgresOpFactoryCallNode {
573
588
 
574
589
  async toOp(lowerer?: ExecuteRequestLowerer): Promise<Op> {
575
590
  if (lowerer === undefined) {
576
- throw new Error(
591
+ throw postgresError(
592
+ 'MIGRATION.POSTGRES_CONTROL_STACK_MISSING',
577
593
  `DropNotNullCall.toOp: a lowerer is required on the Postgres planner path (column "${this.columnName}" on table "${this.tableName}"). Pass the control adapter to createPostgresMigrationPlanner.`,
594
+ { meta: { factory: 'DropNotNullCall' } },
578
595
  );
579
596
  }
580
597
  return dropNotNull(this.schemaName, this.tableName, this.columnName, lowerer);
@@ -623,8 +640,10 @@ export class SetDefaultCall extends PostgresOpFactoryCallNode {
623
640
 
624
641
  async toOp(lowerer?: ExecuteRequestLowerer): Promise<Op> {
625
642
  if (lowerer === undefined) {
626
- throw new Error(
643
+ throw postgresError(
644
+ 'MIGRATION.POSTGRES_CONTROL_STACK_MISSING',
627
645
  `SetDefaultCall.toOp: a lowerer is required on the Postgres planner path (column "${this.columnName}" on table "${this.tableName}"). Pass the control adapter to createPostgresMigrationPlanner.`,
646
+ { meta: { factory: 'SetDefaultCall' } },
628
647
  );
629
648
  }
630
649
  return setDefault(
@@ -675,8 +694,10 @@ export class DropDefaultCall extends PostgresOpFactoryCallNode {
675
694
 
676
695
  async toOp(lowerer?: ExecuteRequestLowerer): Promise<Op> {
677
696
  if (lowerer === undefined) {
678
- throw new Error(
697
+ throw postgresError(
698
+ 'MIGRATION.POSTGRES_CONTROL_STACK_MISSING',
679
699
  `DropDefaultCall.toOp: a lowerer is required on the Postgres planner path (column "${this.columnName}" on table "${this.tableName}"). Pass the control adapter to createPostgresMigrationPlanner.`,
700
+ { meta: { factory: 'DropDefaultCall' } },
680
701
  );
681
702
  }
682
703
  return dropDefault(this.schemaName, this.tableName, this.columnName, lowerer);
@@ -730,8 +751,10 @@ export class AddNotNullColumnDirectCall extends PostgresOpFactoryCallNode {
730
751
 
731
752
  async toOp(lowerer?: ExecuteRequestLowerer): Promise<Op> {
732
753
  if (lowerer === undefined) {
733
- throw new Error(
754
+ throw postgresError(
755
+ 'MIGRATION.POSTGRES_CONTROL_STACK_MISSING',
734
756
  `AddNotNullColumnDirectCall.toOp: a lowerer is required on the Postgres planner path (column "${this.columnName}" on table "${this.tableName}"). Pass the control adapter to createPostgresMigrationPlanner.`,
757
+ { meta: { factory: 'AddNotNullColumnDirectCall' } },
735
758
  );
736
759
  }
737
760
  return addNotNullColumnDirect(this.schemaName, this.tableName, this.column, lowerer);
@@ -787,8 +810,10 @@ export class AddNotNullColumnWithTempDefaultCall extends PostgresOpFactoryCallNo
787
810
 
788
811
  async toOp(lowerer?: ExecuteRequestLowerer): Promise<Op> {
789
812
  if (lowerer === undefined) {
790
- throw new Error(
813
+ throw postgresError(
814
+ 'MIGRATION.POSTGRES_CONTROL_STACK_MISSING',
791
815
  `AddNotNullColumnWithTempDefaultCall.toOp: a lowerer is required on the Postgres planner path (column "${this.columnName}" on table "${this.tableName}"). Pass the control adapter to createPostgresMigrationPlanner.`,
816
+ { meta: { factory: 'AddNotNullColumnWithTempDefaultCall' } },
792
817
  );
793
818
  }
794
819
  return buildAddNotNullColumnWithTemporaryDefaultOperation({
@@ -852,8 +877,10 @@ export class AddPrimaryKeyCall extends PostgresOpFactoryCallNode {
852
877
 
853
878
  async toOp(lowerer?: ExecuteRequestLowerer): Promise<Op> {
854
879
  if (lowerer === undefined) {
855
- throw new Error(
880
+ throw postgresError(
881
+ 'MIGRATION.POSTGRES_CONTROL_STACK_MISSING',
856
882
  `AddPrimaryKeyCall.toOp: a lowerer is required on the Postgres planner path (constraint "${this.constraintName}" on table "${this.tableName}"). Pass the control adapter to createPostgresMigrationPlanner.`,
883
+ { meta: { factory: 'AddPrimaryKeyCall' } },
857
884
  );
858
885
  }
859
886
  return addPrimaryKey(
@@ -900,8 +927,10 @@ export class AddUniqueCall extends PostgresOpFactoryCallNode {
900
927
 
901
928
  async toOp(lowerer?: ExecuteRequestLowerer): Promise<Op> {
902
929
  if (lowerer === undefined) {
903
- throw new Error(
930
+ throw postgresError(
931
+ 'MIGRATION.POSTGRES_CONTROL_STACK_MISSING',
904
932
  `AddUniqueCall.toOp: a lowerer is required on the Postgres planner path (constraint "${this.constraintName}" on table "${this.tableName}"). Pass the control adapter to createPostgresMigrationPlanner.`,
933
+ { meta: { factory: 'AddUniqueCall' } },
905
934
  );
906
935
  }
907
936
  return addUnique(this.schemaName, this.tableName, this.constraintName, this.columns, lowerer);
@@ -935,8 +964,10 @@ export class AddForeignKeyCall extends PostgresOpFactoryCallNode {
935
964
 
936
965
  async toOp(lowerer?: ExecuteRequestLowerer): Promise<Op> {
937
966
  if (lowerer === undefined) {
938
- throw new Error(
967
+ throw postgresError(
968
+ 'MIGRATION.POSTGRES_CONTROL_STACK_MISSING',
939
969
  `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.`,
970
+ { meta: { factory: 'AddForeignKeyCall' } },
940
971
  );
941
972
  }
942
973
  return addForeignKey(this.schemaName, this.tableName, this.fk, lowerer);
@@ -983,8 +1014,10 @@ export class DropConstraintCall extends PostgresOpFactoryCallNode {
983
1014
 
984
1015
  async toOp(lowerer?: ExecuteRequestLowerer): Promise<Op> {
985
1016
  if (lowerer === undefined) {
986
- throw new Error(
1017
+ throw postgresError(
1018
+ 'MIGRATION.POSTGRES_CONTROL_STACK_MISSING',
987
1019
  `DropConstraintCall.toOp: a lowerer is required on the Postgres planner path (constraint "${this.constraintName}" on table "${this.tableName}"). Pass the control adapter to createPostgresMigrationPlanner.`,
1020
+ { meta: { factory: 'DropConstraintCall' } },
988
1021
  );
989
1022
  }
990
1023
  return dropConstraint(this.schemaName, this.tableName, this.constraintName, lowerer, this.kind);
@@ -1032,8 +1065,10 @@ export class AddCheckConstraintCall extends PostgresOpFactoryCallNode {
1032
1065
 
1033
1066
  async toOp(lowerer?: ExecuteRequestLowerer): Promise<Op> {
1034
1067
  if (lowerer === undefined) {
1035
- throw new Error(
1068
+ throw postgresError(
1069
+ 'MIGRATION.POSTGRES_CONTROL_STACK_MISSING',
1036
1070
  `AddCheckConstraintCall.toOp: a lowerer is required on the Postgres planner path (constraint "${this.constraintName}" on table "${this.tableName}"). Pass the control adapter to createPostgresMigrationPlanner.`,
1071
+ { meta: { factory: 'AddCheckConstraintCall' } },
1037
1072
  );
1038
1073
  }
1039
1074
  return addCheckConstraint(
@@ -1074,8 +1109,10 @@ export class DropCheckConstraintCall extends PostgresOpFactoryCallNode {
1074
1109
 
1075
1110
  async toOp(lowerer?: ExecuteRequestLowerer): Promise<Op> {
1076
1111
  if (lowerer === undefined) {
1077
- throw new Error(
1112
+ throw postgresError(
1113
+ 'MIGRATION.POSTGRES_CONTROL_STACK_MISSING',
1078
1114
  `DropCheckConstraintCall.toOp: a lowerer is required on the Postgres planner path (constraint "${this.constraintName}" on table "${this.tableName}"). Pass the control adapter to createPostgresMigrationPlanner.`,
1115
+ { meta: { factory: 'DropCheckConstraintCall' } },
1079
1116
  );
1080
1117
  }
1081
1118
  return dropCheckConstraint(this.schemaName, this.tableName, this.constraintName, lowerer);
@@ -1127,8 +1164,10 @@ export class CreateIndexCall extends PostgresOpFactoryCallNode {
1127
1164
 
1128
1165
  async toOp(lowerer?: ExecuteRequestLowerer): Promise<Op> {
1129
1166
  if (lowerer === undefined) {
1130
- throw new Error(
1167
+ throw postgresError(
1168
+ 'MIGRATION.POSTGRES_CONTROL_STACK_MISSING',
1131
1169
  `CreateIndexCall.toOp: a lowerer is required on the Postgres planner path (index "${this.indexName}" on table "${this.tableName}"). Pass the control adapter to createPostgresMigrationPlanner.`,
1170
+ { meta: { factory: 'CreateIndexCall' } },
1132
1171
  );
1133
1172
  }
1134
1173
  const extras: { type?: string; options?: Record<string, unknown> } = {};
@@ -1185,8 +1224,10 @@ export class DropIndexCall extends PostgresOpFactoryCallNode {
1185
1224
 
1186
1225
  async toOp(lowerer?: ExecuteRequestLowerer): Promise<Op> {
1187
1226
  if (lowerer === undefined) {
1188
- throw new Error(
1227
+ throw postgresError(
1228
+ 'MIGRATION.POSTGRES_CONTROL_STACK_MISSING',
1189
1229
  `DropIndexCall.toOp: a lowerer is required on the Postgres planner path (index "${this.indexName}" on table "${this.tableName}"). Pass the control adapter to createPostgresMigrationPlanner.`,
1230
+ { meta: { factory: 'DropIndexCall' } },
1190
1231
  );
1191
1232
  }
1192
1233
  return dropIndex(this.schemaName, this.tableName, this.indexName, lowerer);
@@ -1288,8 +1329,10 @@ export class CreateSchemaCall extends PostgresOpFactoryCallNode {
1288
1329
 
1289
1330
  async toOp(lowerer?: ExecuteRequestLowerer): Promise<Op> {
1290
1331
  if (lowerer === undefined) {
1291
- throw new Error(
1332
+ throw postgresError(
1333
+ 'MIGRATION.POSTGRES_CONTROL_STACK_MISSING',
1292
1334
  `CreateSchemaCall.toOp: a DDL lowerer is required on the Postgres planner path (schema "${this.schemaName}"). Pass the control adapter to createPostgresMigrationPlanner.`,
1335
+ { meta: { factory: 'CreateSchemaCall' } },
1293
1336
  );
1294
1337
  }
1295
1338
  const ddlNode = contractFreeDdl.createSchema({ schema: this.schemaName, ifNotExists: true });
@@ -1344,8 +1387,10 @@ export class CreateNativeEnumTypeCall extends PostgresOpFactoryCallNode {
1344
1387
 
1345
1388
  async toOp(lowerer?: ExecuteRequestLowerer): Promise<Op> {
1346
1389
  if (lowerer === undefined) {
1347
- throw new Error(
1390
+ throw postgresError(
1391
+ 'MIGRATION.POSTGRES_CONTROL_STACK_MISSING',
1348
1392
  `CreateNativeEnumTypeCall.toOp: a DDL lowerer is required on the Postgres planner path (type "${this.typeName}"). Pass the control adapter to createPostgresMigrationPlanner.`,
1393
+ { meta: { factory: 'CreateNativeEnumTypeCall' } },
1349
1394
  );
1350
1395
  }
1351
1396
  return createNativeEnumType(this.schemaName, this.typeName, this.members, lowerer);
@@ -1382,8 +1427,10 @@ export class DropNativeEnumTypeCall extends PostgresOpFactoryCallNode {
1382
1427
 
1383
1428
  async toOp(lowerer?: ExecuteRequestLowerer): Promise<Op> {
1384
1429
  if (lowerer === undefined) {
1385
- throw new Error(
1430
+ throw postgresError(
1431
+ 'MIGRATION.POSTGRES_CONTROL_STACK_MISSING',
1386
1432
  `DropNativeEnumTypeCall.toOp: a DDL lowerer is required on the Postgres planner path (type "${this.typeName}"). Pass the control adapter to createPostgresMigrationPlanner.`,
1433
+ { meta: { factory: 'DropNativeEnumTypeCall' } },
1387
1434
  );
1388
1435
  }
1389
1436
  return dropNativeEnumType(this.schemaName, this.typeName, lowerer);
@@ -1444,8 +1491,10 @@ export class AddNativeEnumValueCall extends PostgresOpFactoryCallNode {
1444
1491
 
1445
1492
  async toOp(lowerer?: ExecuteRequestLowerer): Promise<Op> {
1446
1493
  if (lowerer === undefined) {
1447
- throw new Error(
1494
+ throw postgresError(
1495
+ 'MIGRATION.POSTGRES_CONTROL_STACK_MISSING',
1448
1496
  `AddNativeEnumValueCall.toOp: a lowerer is required on the Postgres planner path (type "${this.typeName}"). Pass the control adapter to createPostgresMigrationPlanner.`,
1497
+ { meta: { factory: 'AddNativeEnumValueCall' } },
1449
1498
  );
1450
1499
  }
1451
1500
  const { schemaName, typeName, value } = this;
@@ -1571,8 +1620,10 @@ export class CreatePostgresRlsPolicyCall extends PostgresOpFactoryCallNode {
1571
1620
 
1572
1621
  async toOp(lowerer?: ExecuteRequestLowerer): Promise<Op> {
1573
1622
  if (lowerer === undefined) {
1574
- throw new Error(
1623
+ throw postgresError(
1624
+ 'MIGRATION.POSTGRES_CONTROL_STACK_MISSING',
1575
1625
  `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.`,
1626
+ { meta: { factory: 'CreatePostgresRlsPolicyCall' } },
1576
1627
  );
1577
1628
  }
1578
1629
  return createRlsPolicy(this.schemaName, this.tableName, this.policy, lowerer);
@@ -1618,8 +1669,10 @@ export class DropPostgresRlsPolicyCall extends PostgresOpFactoryCallNode {
1618
1669
 
1619
1670
  async toOp(lowerer?: ExecuteRequestLowerer): Promise<Op> {
1620
1671
  if (lowerer === undefined) {
1621
- throw new Error(
1672
+ throw postgresError(
1673
+ 'MIGRATION.POSTGRES_CONTROL_STACK_MISSING',
1622
1674
  `DropPostgresRlsPolicyCall.toOp: a lowerer is required on the Postgres planner path (policy "${this.policyName}" on table "${this.tableName}"). Pass the control adapter to createPostgresMigrationPlanner.`,
1675
+ { meta: { factory: 'DropPostgresRlsPolicyCall' } },
1623
1676
  );
1624
1677
  }
1625
1678
  return dropRlsPolicy(this.schemaName, this.tableName, this.policyName, lowerer);
@@ -1651,8 +1704,10 @@ export class EnableRowLevelSecurityCall extends PostgresOpFactoryCallNode {
1651
1704
 
1652
1705
  async toOp(lowerer?: ExecuteRequestLowerer): Promise<Op> {
1653
1706
  if (lowerer === undefined) {
1654
- throw new Error(
1707
+ throw postgresError(
1708
+ 'MIGRATION.POSTGRES_CONTROL_STACK_MISSING',
1655
1709
  `EnableRowLevelSecurityCall.toOp: a lowerer is required on the Postgres planner path (table "${this.tableName}"). Pass the control adapter to createPostgresMigrationPlanner.`,
1710
+ { meta: { factory: 'EnableRowLevelSecurityCall' } },
1656
1711
  );
1657
1712
  }
1658
1713
  return enableRowLevelSecurity(this.schemaName, this.tableName, lowerer);
@@ -1684,8 +1739,10 @@ export class DisableRowLevelSecurityCall extends PostgresOpFactoryCallNode {
1684
1739
 
1685
1740
  async toOp(lowerer?: ExecuteRequestLowerer): Promise<Op> {
1686
1741
  if (lowerer === undefined) {
1687
- throw new Error(
1742
+ throw postgresError(
1743
+ 'MIGRATION.POSTGRES_CONTROL_STACK_MISSING',
1688
1744
  `DisableRowLevelSecurityCall.toOp: a lowerer is required on the Postgres planner path (table "${this.tableName}"). Pass the control adapter to createPostgresMigrationPlanner.`,
1745
+ { meta: { factory: 'DisableRowLevelSecurityCall' } },
1689
1746
  );
1690
1747
  }
1691
1748
  return disableRowLevelSecurity(this.schemaName, this.tableName, lowerer);
@@ -1725,8 +1782,10 @@ export class RenamePostgresRlsPolicyCall extends PostgresOpFactoryCallNode {
1725
1782
 
1726
1783
  async toOp(lowerer?: ExecuteRequestLowerer): Promise<Op> {
1727
1784
  if (lowerer === undefined) {
1728
- throw new Error(
1785
+ throw postgresError(
1786
+ 'MIGRATION.POSTGRES_CONTROL_STACK_MISSING',
1729
1787
  `RenamePostgresRlsPolicyCall.toOp: a lowerer is required on the Postgres planner path (policy "${this.oldPolicyName}" on table "${this.tableName}"). Pass the control adapter to createPostgresMigrationPlanner.`,
1788
+ { meta: { factory: 'RenamePostgresRlsPolicyCall' } },
1730
1789
  );
1731
1790
  }
1732
1791
  return renameRlsPolicy(
@@ -1,5 +1,6 @@
1
1
  import type { ExecuteRequestLowerer } from '@prisma-next/family-sql/control-adapter';
2
2
  import { REFERENTIAL_ACTION_SQL } from '@prisma-next/sql-contract/referential-action-sql';
3
+ import { InternalError } from '@prisma-next/utils/internal-error';
3
4
  import { constraintExistsAst } from '../../../contract-free/checks';
4
5
  import { escapeLiteral, quoteIdentifier } from '../../sql-utils';
5
6
  import { qualifyTableName } from '../planner-sql-checks';
@@ -29,14 +30,14 @@ REFERENCES ${qualifyTableName(fk.references.schema, fk.references.table)} (${fk.
29
30
  if (fk.onDelete !== undefined) {
30
31
  const action = REFERENTIAL_ACTION_SQL[fk.onDelete];
31
32
  if (!action) {
32
- throw new Error(`Unknown referential action for onDelete: ${String(fk.onDelete)}`);
33
+ throw new InternalError(`Unknown referential action for onDelete: ${String(fk.onDelete)}`);
33
34
  }
34
35
  sql += `\nON DELETE ${action}`;
35
36
  }
36
37
  if (fk.onUpdate !== undefined) {
37
38
  const action = REFERENTIAL_ACTION_SQL[fk.onUpdate];
38
39
  if (!action) {
39
- throw new Error(`Unknown referential action for onUpdate: ${String(fk.onUpdate)}`);
40
+ throw new InternalError(`Unknown referential action for onUpdate: ${String(fk.onUpdate)}`);
40
41
  }
41
42
  sql += `\nON UPDATE ${action}`;
42
43
  }
@@ -1,5 +1,6 @@
1
1
  import type { ExecuteRequestLowerer } from '@prisma-next/family-sql/control-adapter';
2
2
  import { indexExistsAst } from '../../../contract-free/checks';
3
+ import { postgresError } from '../../errors';
3
4
  import { escapeLiteral, quoteIdentifier } from '../../sql-utils';
4
5
  import { qualifyTableName } from '../planner-sql-checks';
5
6
  import { type Op, step, targetDetails } from './shared';
@@ -26,8 +27,10 @@ function renderIndexOptionValue(key: string, value: unknown): string {
26
27
  if (typeof value === 'string') return `'${escapeLiteral(value)}'`;
27
28
  if (typeof value === 'number' && Number.isFinite(value)) return String(value);
28
29
  if (typeof value === 'boolean') return value ? 'true' : 'false';
29
- throw new Error(
30
+ throw postgresError(
31
+ 'CONTRACT.INDEX_INVALID',
30
32
  `Index option "${key}" must be a string, finite number, or boolean; got ${typeof value}`,
33
+ { meta: { key, valueType: typeof value } },
31
34
  );
32
35
  }
33
36
 
@@ -7,6 +7,7 @@ import {
7
7
  disableRowLevelSecurity as disableRowLevelSecurityDdl,
8
8
  dropPolicy,
9
9
  } from '../../../contract-free/ddl';
10
+ import { postgresError } from '../../errors';
10
11
  import type { PostgresRlsPolicy } from '../../postgres-rls-policy';
11
12
  import { qualifyTableName } from '../planner-sql-checks';
12
13
  import { type Op, step, targetDetails } from './shared';
@@ -15,8 +16,10 @@ const PLAIN_IDENTIFIER = /^[A-Za-z_][A-Za-z0-9_$]*$/;
15
16
 
16
17
  function validateRoleName(role: string): string {
17
18
  if (!PLAIN_IDENTIFIER.test(role)) {
18
- throw new Error(
19
+ throw postgresError(
20
+ 'CONTRACT.ROLE_INVALID',
19
21
  `Invalid role name ${JSON.stringify(role)}: role names must be plain SQL identifiers matching ^[A-Za-z_][A-Za-z0-9_$]*$`,
22
+ { meta: { role, reason: 'not-a-plain-identifier' } },
20
23
  );
21
24
  }
22
25
  return role;
@@ -2,6 +2,7 @@ import type { CodecControlHooks } from '@prisma-next/family-sql/control';
2
2
  import type { StorageColumn, StorageTypeInstance } from '@prisma-next/sql-contract/types';
3
3
  import { ifDefined } from '@prisma-next/utils/defined';
4
4
  import { isPgEnumParams } from '../codecs';
5
+ import { postgresError } from '../errors';
5
6
  import { escapeLiteral, quoteIdentifier, quoteQualifiedName } from '../sql-utils';
6
7
  import type { PostgresColumnDefault } from '../types';
7
8
  import { resolveColumnTypeMetadata } from './planner-type-resolution';
@@ -15,9 +16,11 @@ const SAFE_NATIVE_TYPE_PATTERN = /^[a-zA-Z][a-zA-Z0-9_ ]*(\[\])?$/;
15
16
 
16
17
  function assertSafeNativeType(nativeType: string): void {
17
18
  if (!SAFE_NATIVE_TYPE_PATTERN.test(nativeType)) {
18
- throw new Error(
19
+ throw postgresError(
20
+ 'CONTRACT.NATIVE_TYPE_INVALID',
19
21
  `Unsafe native type name in contract: "${nativeType}". ` +
20
22
  'Native type names must match /^[a-zA-Z][a-zA-Z0-9_ ]*(\\[\\])?$/',
23
+ { meta: { nativeType } },
21
24
  );
22
25
  }
23
26
  }
@@ -29,9 +32,11 @@ function assertSafeNativeType(nativeType: string): void {
29
32
  */
30
33
  function assertSafeDefaultExpression(expression: string): void {
31
34
  if (expression.includes(';') || /--|\/\*|\$\$|\bSELECT\b/i.test(expression)) {
32
- throw new Error(
35
+ throw postgresError(
36
+ 'CONTRACT.DEFAULT_INVALID',
33
37
  `Unsafe default expression in contract: "${expression}". ` +
34
38
  'Default expressions must not contain semicolons, SQL comment tokens, dollar-quoting, or subqueries.',
39
+ { meta: { expression } },
35
40
  );
36
41
  }
37
42
  }
@@ -99,9 +104,11 @@ function expandParameterizedTypeSql(
99
104
  }
100
105
 
101
106
  if (!column.codecId) {
102
- throw new Error(
107
+ throw postgresError(
108
+ 'CONTRACT.CODEC_DESCRIPTOR_MISSING',
103
109
  `Column declares typeParams for nativeType "${column.nativeType}" but has no codecId. ` +
104
110
  'Ensure the column is associated with a codec.',
111
+ { meta: { nativeType: column.nativeType } },
105
112
  );
106
113
  }
107
114
 
@@ -110,10 +117,12 @@ function expandParameterizedTypeSql(
110
117
  if (hooks?.planTypeOperations) {
111
118
  return null;
112
119
  }
113
- throw new Error(
120
+ throw postgresError(
121
+ 'CONTRACT.PACK_CONTRIBUTION_INVALID',
114
122
  `Column declares typeParams for nativeType "${column.nativeType}" ` +
115
123
  `but no expandNativeType hook is registered for codecId "${column.codecId}". ` +
116
124
  'Ensure the extension providing this codec is included in extensions.',
125
+ { meta: { codecId: column.codecId, nativeType: column.nativeType } },
117
126
  );
118
127
  }
119
128
 
@@ -6,6 +6,7 @@ import type {
6
6
  } from '@prisma-next/framework-components/control';
7
7
  import { blindCast } from '@prisma-next/utils/casts';
8
8
  import { isThenable } from '@prisma-next/utils/promise';
9
+ import { postgresError } from '../errors';
9
10
  import type { PostgresPlanTargetDetails } from './planner-target-details';
10
11
 
11
12
  type Op = SqlMigrationPlanOperation<PostgresPlanTargetDetails>;
@@ -23,8 +24,10 @@ function assertPostgresOp(op: MigrationPlanOperation, callFactoryName: string):
23
24
  'op.target is present on concrete SqlMigrationPlanOperation but absent on the framework MigrationPlanOperation base'
24
25
  >(op).target?.id;
25
26
  if (targetId !== 'postgres') {
26
- throw new Error(
27
+ throw postgresError(
28
+ 'MIGRATION.TARGET_MISMATCH',
27
29
  `renderOps: expected postgres op but got target.id="${String(targetId)}" for op.id="${op.id}" (factoryName="${callFactoryName}"). An OpFactoryCall produced an op for a different target on the postgres planner path; check the call's target binding.`,
30
+ { meta: { opId: op.id, targetId: String(targetId), factoryName: callFactoryName } },
28
31
  );
29
32
  }
30
33
  }
@@ -20,8 +20,10 @@ import { SqlQueryError } from '@prisma-next/sql-errors';
20
20
  import type { SqlExecuteRequest } from '@prisma-next/sql-relational-core/ast';
21
21
  import { blindCast } from '@prisma-next/utils/casts';
22
22
  import { ifDefined } from '@prisma-next/utils/defined';
23
+ import { InternalError } from '@prisma-next/utils/internal-error';
23
24
  import type { Result } from '@prisma-next/utils/result';
24
25
  import { notOk, ok, okVoid } from '@prisma-next/utils/result';
26
+ import { postgresError } from '../errors';
25
27
  import type { PostgresPlanTargetDetails } from './planner-target-details';
26
28
 
27
29
  interface ApplyPlanSuccessValue {
@@ -76,8 +78,10 @@ class PostgresMigrationRunner implements SqlMigrationRunner<PostgresPlanTargetDe
76
78
  UNBOUND_NAMESPACE_ID;
77
79
  const driver = options.driver;
78
80
  if (options.space !== undefined && options.space !== options.plan.spaceId) {
79
- throw new Error(
81
+ throw postgresError(
82
+ 'MIGRATION.CONTRACT_SPACE_VIOLATION',
80
83
  `SqlMigrationRunner: options.space (${options.space}) does not match plan.spaceId (${options.plan.spaceId})`,
84
+ { meta: { space: options.space, planSpaceId: options.plan.spaceId } },
81
85
  );
82
86
  }
83
87
  const space = options.plan.spaceId;
@@ -283,7 +287,7 @@ class PostgresMigrationRunner implements SqlMigrationRunner<PostgresPlanTargetDe
283
287
  const bootstrapQueries = this.family.bootstrapControlTableQueries();
284
288
  const [schemaQuery, ...tableQueries] = bootstrapQueries;
285
289
  if (schemaQuery === undefined) {
286
- throw new Error('Postgres control-table bootstrap must include CREATE SCHEMA');
290
+ throw new InternalError('Postgres control-table bootstrap must include CREATE SCHEMA');
287
291
  }
288
292
  await this.executeStatement(driver, await this.family.lowerAst(schemaQuery, lowererContext));
289
293
  const legacyDetection = await this.detectLegacyMarkerShape(driver);
@@ -640,7 +644,7 @@ class PostgresMigrationRunner implements SqlMigrationRunner<PostgresPlanTargetDe
640
644
  const edges = options.migrationEdges;
641
645
  const totalEdgeOps = edges.reduce((sum, edge) => sum + edge.operationCount, 0);
642
646
  if (totalEdgeOps !== planOpsLength) {
643
- throw new Error(
647
+ throw new InternalError(
644
648
  `Ledger write: plan.operations length (${planOpsLength}) does not match sum of migrationEdges operationCount (${totalEdgeOps})`,
645
649
  );
646
650
  }
@@ -46,6 +46,8 @@ import type { SqlColumnIR, SqlForeignKeyIR } from '@prisma-next/sql-schema-ir/ty
46
46
  import { SqlSchemaIR, SqlTableIR } from '@prisma-next/sql-schema-ir/types';
47
47
  import { blindCast } from '@prisma-next/utils/casts';
48
48
  import { ifDefined } from '@prisma-next/utils/defined';
49
+ import { InternalError } from '@prisma-next/utils/internal-error';
50
+ import { postgresError } from '../errors';
49
51
  import type { PostgresDatabaseSchemaNode } from '../schema-ir/postgres-database-schema-node';
50
52
  import { createPostgresDefaultMapping } from './postgres-default-mapping';
51
53
  import { createPostgresTypeMap } from './postgres-type-map';
@@ -224,11 +226,13 @@ function resolveForeignKeys(
224
226
  if (owner !== undefined) {
225
227
  const target = resolveCrossSpaceTarget(owner, fk.referencedSchema, fk.referencedTable);
226
228
  if (target === undefined) {
227
- throw new Error(
229
+ throw postgresError(
230
+ 'CONTRACT.PACK_CONTRIBUTION_INVALID',
228
231
  `contract infer: described contract space "${owner.spaceId}" owns storage ` +
229
232
  `coordinate "${fk.referencedSchema}.${fk.referencedTable}" but declares no ` +
230
233
  'domain model mapped to it. A pack that describes a table must also declare the ' +
231
234
  'domain model it maps to; this pack is malformed.',
235
+ { meta: { spaceId: owner.spaceId, tableName: fk.referencedTable } },
232
236
  );
233
237
  }
234
238
 
@@ -384,22 +388,26 @@ export function inferPostgresPslContract(
384
388
  continue;
385
389
  }
386
390
  if (tables[tableName] !== undefined) {
387
- throw new Error(
391
+ throw postgresError(
392
+ 'CONTRACT.INFER_UNSUPPORTED',
388
393
  `contract infer: duplicate table name "${tableName}" across schemas is not yet supported ` +
389
394
  '(single-namespace PSL inference emits one flat bucket; multi-namespace `namespace { … }` ' +
390
395
  'output is a later slice).',
396
+ { meta: { tableName } },
391
397
  );
392
398
  }
393
399
  if (ownedEnumTypes !== undefined) {
394
400
  for (const column of Object.values(table.columns)) {
395
401
  const owningSpaceId = ownedEnumTypes.get(column.nativeType);
396
402
  if (owningSpaceId !== undefined) {
397
- throw new Error(
403
+ throw postgresError(
404
+ 'CONTRACT.INFER_UNSUPPORTED',
398
405
  `contract infer: column "${tableName}"."${column.name}" is typed by native enum ` +
399
406
  `type "${column.nativeType}", which extension pack space "${owningSpaceId}" ` +
400
407
  'already describes. A cross-space enum-typed column has no authorable PSL form ' +
401
408
  "yet; describe the table in that pack's contract or retype the column before " +
402
409
  're-running contract infer.',
410
+ { meta: { tableName, columnName: column.name } },
403
411
  );
404
412
  }
405
413
  }
@@ -418,12 +426,14 @@ export function inferPostgresPslContract(
418
426
  if (enumDefinitions.size > 0) {
419
427
  const contentNamespaces = new Set([...enumNamespaceNames, ...tableNamespaceNames]);
420
428
  if (contentNamespaces.size > 1) {
421
- throw new Error(
429
+ throw postgresError(
430
+ 'CONTRACT.INFER_UNSUPPORTED',
422
431
  'contract infer: native enum adoption with content across multiple schemas is not yet ' +
423
432
  'supported (single-namespace PSL inference emits one `namespace { … }` block; ' +
424
433
  `multi-namespace output is a later slice). Schemas: ${[...contentNamespaces]
425
434
  .sort()
426
435
  .join(', ')}.`,
436
+ { meta: { schemas: [...contentNamespaces].sort() } },
427
437
  );
428
438
  }
429
439
  wrapNamespaceName = [...contentNamespaces][0];
@@ -1222,7 +1232,11 @@ function buildTopLevelNameMap(
1222
1232
  .map((source) => `"${source}"`)
1223
1233
  .join(', ')}`,
1224
1234
  );
1225
- throw new Error(`PSL ${kind} name collisions detected:\n${details.join('\n')}`);
1235
+ throw postgresError(
1236
+ 'CONTRACT.NAME_DUPLICATE',
1237
+ `PSL ${kind} name collisions detected:\n${details.join('\n')}`,
1238
+ { meta: { kind, names: duplicates.map(([normalizedName]) => normalizedName) } },
1239
+ );
1226
1240
  }
1227
1241
 
1228
1242
  return results;
@@ -1331,7 +1345,9 @@ function resolveNamedTypeName(
1331
1345
  return existing.name;
1332
1346
  }
1333
1347
 
1334
- throw new Error(`Named type registry was not seeded for native type "${resolution.nativeType}"`);
1348
+ throw new InternalError(
1349
+ `Named type registry was not seeded for native type "${resolution.nativeType}"`,
1350
+ );
1335
1351
  }
1336
1352
 
1337
1353
  function createNamedTypeSignatureKey(resolution: {