@prisma-next/target-postgres 0.13.0-dev.35 → 0.13.0-dev.36

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (81) hide show
  1. package/dist/contract-free.d.mts +147 -14
  2. package/dist/contract-free.d.mts.map +1 -1
  3. package/dist/contract-free.mjs +3 -16
  4. package/dist/contract-free.mjs.map +1 -1
  5. package/dist/control.mjs +2 -2
  6. package/dist/ddl-QDyOSeLc.mjs +251 -0
  7. package/dist/ddl-QDyOSeLc.mjs.map +1 -0
  8. package/dist/{issue-planner-9AVUEL74.mjs → issue-planner-CoI_0uM1.mjs} +8 -118
  9. package/dist/issue-planner-CoI_0uM1.mjs.map +1 -0
  10. package/dist/issue-planner.d.mts +1 -1
  11. package/dist/issue-planner.d.mts.map +1 -1
  12. package/dist/issue-planner.mjs +1 -1
  13. package/dist/migration.d.mts +4 -80
  14. package/dist/migration.d.mts.map +1 -1
  15. package/dist/migration.mjs +3 -3
  16. package/dist/{op-factory-call-CvDOetGa.mjs → op-factory-call-B1bXWtfa.mjs} +551 -241
  17. package/dist/op-factory-call-B1bXWtfa.mjs.map +1 -0
  18. package/dist/{op-factory-call-CdtMyrlU.d.mts → op-factory-call-DmQEc3XV.d.mts} +111 -20
  19. package/dist/op-factory-call-DmQEc3XV.d.mts.map +1 -0
  20. package/dist/op-factory-call.d.mts +1 -1
  21. package/dist/op-factory-call.mjs +1 -1
  22. package/dist/{planner-BZxjjT8T.mjs → planner-DS5XBhmi.mjs} +4 -4
  23. package/dist/{planner-BZxjjT8T.mjs.map → planner-DS5XBhmi.mjs.map} +1 -1
  24. package/dist/{planner-produced-postgres-migration-CkECqqTy.mjs → planner-produced-postgres-migration-DTwCCek_.mjs} +2 -2
  25. package/dist/{planner-produced-postgres-migration-CkECqqTy.mjs.map → planner-produced-postgres-migration-DTwCCek_.mjs.map} +1 -1
  26. package/dist/{planner-produced-postgres-migration-wLhnJMMA.d.mts → planner-produced-postgres-migration-QqHa2C2l.d.mts} +2 -2
  27. package/dist/{planner-produced-postgres-migration-wLhnJMMA.d.mts.map → planner-produced-postgres-migration-QqHa2C2l.d.mts.map} +1 -1
  28. package/dist/planner-produced-postgres-migration.d.mts +1 -1
  29. package/dist/planner-produced-postgres-migration.mjs +1 -1
  30. package/dist/planner-sql-checks-jqUUGyQR.mjs +152 -0
  31. package/dist/planner-sql-checks-jqUUGyQR.mjs.map +1 -0
  32. package/dist/planner-sql-checks.d.mts +1 -47
  33. package/dist/planner-sql-checks.d.mts.map +1 -1
  34. package/dist/planner-sql-checks.mjs +2 -2
  35. package/dist/planner.d.mts +1 -1
  36. package/dist/planner.mjs +1 -1
  37. package/dist/{postgres-contract-serializer-sdg1B6Og.mjs → postgres-contract-serializer-E92REOFk.mjs} +2 -2
  38. package/dist/{postgres-contract-serializer-sdg1B6Og.mjs.map → postgres-contract-serializer-E92REOFk.mjs.map} +1 -1
  39. package/dist/postgres-migration-Y4YBJqkS.d.mts +181 -0
  40. package/dist/postgres-migration-Y4YBJqkS.d.mts.map +1 -0
  41. package/dist/postgres-migration-otiaw3Ru.mjs +145 -0
  42. package/dist/postgres-migration-otiaw3Ru.mjs.map +1 -0
  43. package/dist/{postgres-schema-CDaLWZwd.mjs → postgres-schema-COGZ1ark.mjs} +61 -8
  44. package/dist/postgres-schema-COGZ1ark.mjs.map +1 -0
  45. package/dist/runtime.mjs +1 -1
  46. package/dist/table-source-BvFo7gVs.d.mts +15 -0
  47. package/dist/table-source-BvFo7gVs.d.mts.map +1 -0
  48. package/dist/types.d.mts +26 -6
  49. package/dist/types.d.mts.map +1 -1
  50. package/dist/types.mjs +1 -1
  51. package/package.json +17 -17
  52. package/src/contract-free/checks.ts +363 -0
  53. package/src/core/migrations/op-factory-call.ts +417 -94
  54. package/src/core/migrations/operations/columns.ts +175 -140
  55. package/src/core/migrations/operations/constraints.ts +79 -108
  56. package/src/core/migrations/operations/dependencies.ts +16 -14
  57. package/src/core/migrations/operations/indexes.ts +31 -28
  58. package/src/core/migrations/operations/shared.ts +2 -2
  59. package/src/core/migrations/operations/tables.ts +13 -14
  60. package/src/core/migrations/planner-recipes.ts +42 -33
  61. package/src/core/migrations/planner-sql-checks.ts +1 -172
  62. package/src/core/migrations/planner-strategies.ts +25 -73
  63. package/src/core/migrations/postgres-migration.ts +272 -7
  64. package/src/core/postgres-schema.ts +47 -6
  65. package/src/exports/contract-free.ts +21 -0
  66. package/src/exports/migration.ts +1 -22
  67. package/src/exports/planner-sql-checks.ts +0 -7
  68. package/dist/ddl-DY2R_Yqz.mjs +0 -45
  69. package/dist/ddl-DY2R_Yqz.mjs.map +0 -1
  70. package/dist/issue-planner-9AVUEL74.mjs.map +0 -1
  71. package/dist/op-factory-call-CdtMyrlU.d.mts.map +0 -1
  72. package/dist/op-factory-call-CvDOetGa.mjs.map +0 -1
  73. package/dist/planner-sql-checks-Bj4G0_gO.mjs +0 -272
  74. package/dist/planner-sql-checks-Bj4G0_gO.mjs.map +0 -1
  75. package/dist/postgres-migration-DLXL0GBf.d.mts +0 -77
  76. package/dist/postgres-migration-DLXL0GBf.d.mts.map +0 -1
  77. package/dist/postgres-migration-DMnWjdni.mjs +0 -75
  78. package/dist/postgres-migration-DMnWjdni.mjs.map +0 -1
  79. package/dist/postgres-schema-CDaLWZwd.mjs.map +0 -1
  80. package/dist/shared-jcsbXxiW.d.mts +0 -25
  81. package/dist/shared-jcsbXxiW.d.mts.map +0 -1
@@ -21,13 +21,14 @@
21
21
  */
22
22
 
23
23
  import { errorUnfilledPlaceholder } from '@prisma-next/errors/migration';
24
- import type { SqlMigrationPlanOperation } from '@prisma-next/family-sql/control';
24
+ import type { CodecControlHooks, SqlMigrationPlanOperation } from '@prisma-next/family-sql/control';
25
25
  import type { ExecuteRequestLowerer, Lowerer } from '@prisma-next/family-sql/control-adapter';
26
26
  import type {
27
27
  OpFactoryCall as FrameworkOpFactoryCall,
28
28
  MigrationOperationClass,
29
29
  } from '@prisma-next/framework-components/control';
30
30
  import { UNBOUND_NAMESPACE_ID } from '@prisma-next/framework-components/ir';
31
+ import type { StorageColumn, StorageTypeInstance } from '@prisma-next/sql-contract/types';
31
32
  import type {
32
33
  AnyDdlColumnDefault,
33
34
  DdlColumn,
@@ -37,10 +38,12 @@ import { FunctionColumnDefault, LiteralColumnDefault } from '@prisma-next/sql-re
37
38
  import { type ImportRequirement, jsonToTsSource, TsExpression } from '@prisma-next/ts-render';
38
39
  import { blindCast } from '@prisma-next/utils/casts';
39
40
  import { ifDefined } from '@prisma-next/utils/defined';
41
+ import { columnExistsAst, tableExistsAst } from '../../contract-free/checks';
40
42
  import * as contractFreeDdl from '../../contract-free/ddl';
41
43
  import { escapeLiteral, quoteIdentifier } from '../sql-utils';
42
44
  import type { PostgresColumnDefault } from '../types';
43
45
  import {
46
+ addNotNullColumnDirect,
44
47
  alterColumnType,
45
48
  dropColumn,
46
49
  dropDefault,
@@ -61,7 +64,7 @@ import { createIndex, dropIndex } from './operations/indexes';
61
64
  import type { ForeignKeySpec } from './operations/shared';
62
65
  import { step, targetDetails } from './operations/shared';
63
66
  import { dropTable } from './operations/tables';
64
- import { columnExistsCheck, toRegclassLiteral } from './planner-sql-checks';
67
+ import { buildAddNotNullColumnWithTemporaryDefaultOperation } from './planner-recipes';
65
68
  import type { PostgresPlanTargetDetails } from './planner-target-details';
66
69
 
67
70
  type Op = SqlMigrationPlanOperation<PostgresPlanTargetDetails>;
@@ -231,18 +234,16 @@ export class CreateTableCall extends PostgresOpFactoryCallNode {
231
234
  const statement = await lowerer.lowerToExecuteRequest(ddlNode);
232
235
  const schemaName = this.schemaName;
233
236
  const tableName = this.tableName;
237
+ const checks = tableExistsAst(schemaName, tableName);
238
+ const absent = await lowerer.lowerToExecuteRequest(checks.tableAbsent());
239
+ const present = await lowerer.lowerToExecuteRequest(checks.tablePresent());
234
240
  return {
235
241
  id: `table.${tableName}`,
236
242
  label: `Create table "${tableName}"`,
237
243
  summary: `Creates table "${tableName}"`,
238
244
  operationClass: 'additive',
239
245
  target: targetDetails('table', tableName, schemaName),
240
- precheck: [
241
- step(
242
- `ensure table "${tableName}" does not exist`,
243
- `SELECT to_regclass(${toRegclassLiteral(schemaName, tableName)}) IS NULL`,
244
- ),
245
- ],
246
+ precheck: [step(`ensure table "${tableName}" does not exist`, absent.sql, absent.params)],
246
247
  execute: [
247
248
  {
248
249
  description: `create table "${tableName}"`,
@@ -250,12 +251,7 @@ export class CreateTableCall extends PostgresOpFactoryCallNode {
250
251
  params: statement.params ?? [],
251
252
  },
252
253
  ],
253
- postcheck: [
254
- step(
255
- `verify table "${tableName}" exists`,
256
- `SELECT to_regclass(${toRegclassLiteral(schemaName, tableName)}) IS NOT NULL`,
257
- ),
258
- ],
254
+ postcheck: [step(`verify table "${tableName}" exists`, present.sql, present.params)],
259
255
  };
260
256
  }
261
257
 
@@ -306,12 +302,26 @@ export class DropTableCall extends PostgresOpFactoryCallNode {
306
302
  this.freeze();
307
303
  }
308
304
 
309
- toOp(): Op {
310
- return dropTable(this.schemaName, this.tableName);
305
+ async toOp(lowerer?: ExecuteRequestLowerer): Promise<Op> {
306
+ if (lowerer === undefined) {
307
+ throw new Error(
308
+ `DropTableCall.toOp: a lowerer is required on the Postgres planner path (table "${this.tableName}"). Pass the control adapter to createPostgresMigrationPlanner.`,
309
+ );
310
+ }
311
+ return dropTable(this.schemaName, this.tableName, lowerer);
311
312
  }
312
313
 
313
314
  renderTypeScript(): string {
314
- return `dropTable(${jsonToTsSource(this.schemaName)}, ${jsonToTsSource(this.tableName)})`;
315
+ const opts: string[] = [];
316
+ if (this.schemaName !== UNBOUND_NAMESPACE_ID) {
317
+ opts.push(`schema: ${jsonToTsSource(this.schemaName)}`);
318
+ }
319
+ opts.push(`table: ${jsonToTsSource(this.tableName)}`);
320
+ return `this.dropTable({ ${opts.join(', ')} })`;
321
+ }
322
+
323
+ override importRequirements(): readonly ImportRequirement[] {
324
+ return [];
315
325
  }
316
326
  }
317
327
 
@@ -351,29 +361,17 @@ export class AddColumnCall extends PostgresOpFactoryCallNode {
351
361
  const schemaName = this.schemaName;
352
362
  const tableName = this.tableName;
353
363
  const columnName = this.column.name;
364
+ const colChecks = columnExistsAst({ schema: schemaName, table: tableName, column: columnName });
365
+ const absent = await lowerer.lowerToExecuteRequest(colChecks.columnAbsent());
366
+ const present = await lowerer.lowerToExecuteRequest(colChecks.columnPresent());
354
367
  return {
355
368
  id: `column.${tableName}.${columnName}`,
356
369
  label: `Add column "${columnName}" to "${tableName}"`,
357
370
  operationClass: 'additive',
358
371
  target: targetDetails('column', columnName, schemaName, tableName),
359
- precheck: [
360
- step(
361
- `ensure column "${columnName}" is missing`,
362
- columnExistsCheck({
363
- schema: schemaName,
364
- table: tableName,
365
- column: columnName,
366
- exists: false,
367
- }),
368
- ),
369
- ],
372
+ precheck: [step(`ensure column "${columnName}" is missing`, absent.sql, absent.params)],
370
373
  execute: [step(`add column "${columnName}"`, statement.sql)],
371
- postcheck: [
372
- step(
373
- `verify column "${columnName}" exists`,
374
- columnExistsCheck({ schema: schemaName, table: tableName, column: columnName }),
375
- ),
376
- ],
374
+ postcheck: [step(`verify column "${columnName}" exists`, present.sql, present.params)],
377
375
  };
378
376
  }
379
377
 
@@ -415,12 +413,27 @@ export class DropColumnCall extends PostgresOpFactoryCallNode {
415
413
  this.freeze();
416
414
  }
417
415
 
418
- toOp(): Op {
419
- return dropColumn(this.schemaName, this.tableName, this.columnName);
416
+ async toOp(lowerer?: ExecuteRequestLowerer): Promise<Op> {
417
+ if (lowerer === undefined) {
418
+ throw new Error(
419
+ `DropColumnCall.toOp: a lowerer is required on the Postgres planner path (column "${this.columnName}" on table "${this.tableName}"). Pass the control adapter to createPostgresMigrationPlanner.`,
420
+ );
421
+ }
422
+ return dropColumn(this.schemaName, this.tableName, this.columnName, lowerer);
420
423
  }
421
424
 
422
425
  renderTypeScript(): string {
423
- return `dropColumn(${jsonToTsSource(this.schemaName)}, ${jsonToTsSource(this.tableName)}, ${jsonToTsSource(this.columnName)})`;
426
+ const opts: string[] = [];
427
+ if (this.schemaName !== UNBOUND_NAMESPACE_ID) {
428
+ opts.push(`schema: ${jsonToTsSource(this.schemaName)}`);
429
+ }
430
+ opts.push(`table: ${jsonToTsSource(this.tableName)}`);
431
+ opts.push(`column: ${jsonToTsSource(this.columnName)}`);
432
+ return `this.dropColumn({ ${opts.join(', ')} })`;
433
+ }
434
+
435
+ override importRequirements(): readonly ImportRequirement[] {
436
+ return [];
424
437
  }
425
438
  }
426
439
 
@@ -455,12 +468,28 @@ export class AlterColumnTypeCall extends PostgresOpFactoryCallNode {
455
468
  this.freeze();
456
469
  }
457
470
 
458
- toOp(): Op {
459
- return alterColumnType(this.schemaName, this.tableName, this.columnName, this.options);
471
+ async toOp(lowerer?: ExecuteRequestLowerer): Promise<Op> {
472
+ if (lowerer === undefined) {
473
+ throw new Error(
474
+ `AlterColumnTypeCall.toOp: a lowerer is required on the Postgres planner path (column "${this.columnName}" on table "${this.tableName}"). Pass the control adapter to createPostgresMigrationPlanner.`,
475
+ );
476
+ }
477
+ return alterColumnType(this.schemaName, this.tableName, this.columnName, this.options, lowerer);
460
478
  }
461
479
 
462
480
  renderTypeScript(): string {
463
- return `alterColumnType(${jsonToTsSource(this.schemaName)}, ${jsonToTsSource(this.tableName)}, ${jsonToTsSource(this.columnName)}, ${jsonToTsSource(this.options)})`;
481
+ const opts: string[] = [];
482
+ if (this.schemaName !== UNBOUND_NAMESPACE_ID) {
483
+ opts.push(`schema: ${jsonToTsSource(this.schemaName)}`);
484
+ }
485
+ opts.push(`table: ${jsonToTsSource(this.tableName)}`);
486
+ opts.push(`column: ${jsonToTsSource(this.columnName)}`);
487
+ opts.push(`options: ${jsonToTsSource(this.options)}`);
488
+ return `this.alterColumnType({ ${opts.join(', ')} })`;
489
+ }
490
+
491
+ override importRequirements(): readonly ImportRequirement[] {
492
+ return [];
464
493
  }
465
494
  }
466
495
 
@@ -481,12 +510,27 @@ export class SetNotNullCall extends PostgresOpFactoryCallNode {
481
510
  this.freeze();
482
511
  }
483
512
 
484
- toOp(): Op {
485
- return setNotNull(this.schemaName, this.tableName, this.columnName);
513
+ async toOp(lowerer?: ExecuteRequestLowerer): Promise<Op> {
514
+ if (lowerer === undefined) {
515
+ throw new Error(
516
+ `SetNotNullCall.toOp: a lowerer is required on the Postgres planner path (column "${this.columnName}" on table "${this.tableName}"). Pass the control adapter to createPostgresMigrationPlanner.`,
517
+ );
518
+ }
519
+ return setNotNull(this.schemaName, this.tableName, this.columnName, lowerer);
486
520
  }
487
521
 
488
522
  renderTypeScript(): string {
489
- return `setNotNull(${jsonToTsSource(this.schemaName)}, ${jsonToTsSource(this.tableName)}, ${jsonToTsSource(this.columnName)})`;
523
+ const opts: string[] = [];
524
+ if (this.schemaName !== UNBOUND_NAMESPACE_ID) {
525
+ opts.push(`schema: ${jsonToTsSource(this.schemaName)}`);
526
+ }
527
+ opts.push(`table: ${jsonToTsSource(this.tableName)}`);
528
+ opts.push(`column: ${jsonToTsSource(this.columnName)}`);
529
+ return `this.setNotNull({ ${opts.join(', ')} })`;
530
+ }
531
+
532
+ override importRequirements(): readonly ImportRequirement[] {
533
+ return [];
490
534
  }
491
535
  }
492
536
 
@@ -507,12 +551,27 @@ export class DropNotNullCall extends PostgresOpFactoryCallNode {
507
551
  this.freeze();
508
552
  }
509
553
 
510
- toOp(): Op {
511
- return dropNotNull(this.schemaName, this.tableName, this.columnName);
554
+ async toOp(lowerer?: ExecuteRequestLowerer): Promise<Op> {
555
+ if (lowerer === undefined) {
556
+ throw new Error(
557
+ `DropNotNullCall.toOp: a lowerer is required on the Postgres planner path (column "${this.columnName}" on table "${this.tableName}"). Pass the control adapter to createPostgresMigrationPlanner.`,
558
+ );
559
+ }
560
+ return dropNotNull(this.schemaName, this.tableName, this.columnName, lowerer);
512
561
  }
513
562
 
514
563
  renderTypeScript(): string {
515
- return `dropNotNull(${jsonToTsSource(this.schemaName)}, ${jsonToTsSource(this.tableName)}, ${jsonToTsSource(this.columnName)})`;
564
+ const opts: string[] = [];
565
+ if (this.schemaName !== UNBOUND_NAMESPACE_ID) {
566
+ opts.push(`schema: ${jsonToTsSource(this.schemaName)}`);
567
+ }
568
+ opts.push(`table: ${jsonToTsSource(this.tableName)}`);
569
+ opts.push(`column: ${jsonToTsSource(this.columnName)}`);
570
+ return `this.dropNotNull({ ${opts.join(', ')} })`;
571
+ }
572
+
573
+ override importRequirements(): readonly ImportRequirement[] {
574
+ return [];
516
575
  }
517
576
  }
518
577
 
@@ -542,27 +601,38 @@ export class SetDefaultCall extends PostgresOpFactoryCallNode {
542
601
  this.freeze();
543
602
  }
544
603
 
545
- toOp(): Op {
604
+ async toOp(lowerer?: ExecuteRequestLowerer): Promise<Op> {
605
+ if (lowerer === undefined) {
606
+ throw new Error(
607
+ `SetDefaultCall.toOp: a lowerer is required on the Postgres planner path (column "${this.columnName}" on table "${this.tableName}"). Pass the control adapter to createPostgresMigrationPlanner.`,
608
+ );
609
+ }
546
610
  return setDefault(
547
611
  this.schemaName,
548
612
  this.tableName,
549
613
  this.columnName,
550
614
  this.defaultSql,
615
+ lowerer,
551
616
  this.operationClass,
552
617
  );
553
618
  }
554
619
 
555
620
  renderTypeScript(): string {
556
- const args = [
557
- jsonToTsSource(this.schemaName),
558
- jsonToTsSource(this.tableName),
559
- jsonToTsSource(this.columnName),
560
- jsonToTsSource(this.defaultSql),
561
- ];
621
+ const opts: string[] = [];
622
+ if (this.schemaName !== UNBOUND_NAMESPACE_ID) {
623
+ opts.push(`schema: ${jsonToTsSource(this.schemaName)}`);
624
+ }
625
+ opts.push(`table: ${jsonToTsSource(this.tableName)}`);
626
+ opts.push(`column: ${jsonToTsSource(this.columnName)}`);
627
+ opts.push(`defaultSql: ${jsonToTsSource(this.defaultSql)}`);
562
628
  if (this.operationClass !== 'additive') {
563
- args.push(jsonToTsSource(this.operationClass));
629
+ opts.push(`operationClass: ${jsonToTsSource(this.operationClass)}`);
564
630
  }
565
- return `setDefault(${args.join(', ')})`;
631
+ return `this.setDefault({ ${opts.join(', ')} })`;
632
+ }
633
+
634
+ override importRequirements(): readonly ImportRequirement[] {
635
+ return [];
566
636
  }
567
637
  }
568
638
 
@@ -583,12 +653,154 @@ export class DropDefaultCall extends PostgresOpFactoryCallNode {
583
653
  this.freeze();
584
654
  }
585
655
 
586
- toOp(): Op {
587
- return dropDefault(this.schemaName, this.tableName, this.columnName);
656
+ async toOp(lowerer?: ExecuteRequestLowerer): Promise<Op> {
657
+ if (lowerer === undefined) {
658
+ throw new Error(
659
+ `DropDefaultCall.toOp: a lowerer is required on the Postgres planner path (column "${this.columnName}" on table "${this.tableName}"). Pass the control adapter to createPostgresMigrationPlanner.`,
660
+ );
661
+ }
662
+ return dropDefault(this.schemaName, this.tableName, this.columnName, lowerer);
588
663
  }
589
664
 
590
665
  renderTypeScript(): string {
591
- return `dropDefault(${jsonToTsSource(this.schemaName)}, ${jsonToTsSource(this.tableName)}, ${jsonToTsSource(this.columnName)})`;
666
+ const opts: string[] = [];
667
+ if (this.schemaName !== UNBOUND_NAMESPACE_ID) {
668
+ opts.push(`schema: ${jsonToTsSource(this.schemaName)}`);
669
+ }
670
+ opts.push(`table: ${jsonToTsSource(this.tableName)}`);
671
+ opts.push(`column: ${jsonToTsSource(this.columnName)}`);
672
+ return `this.dropDefault({ ${opts.join(', ')} })`;
673
+ }
674
+
675
+ override importRequirements(): readonly ImportRequirement[] {
676
+ return [];
677
+ }
678
+ }
679
+
680
+ // ============================================================================
681
+ // NOT NULL column additions (planner-internal; no authored surface)
682
+ // ============================================================================
683
+
684
+ /**
685
+ * Planner-internal call for adding a NOT NULL column (no contract default) to
686
+ * a table that must be empty at migration time. Carries the raw ADD COLUMN SQL
687
+ * (produced by `buildAddColumnSql` at plan time — deferred from slice-7 typed
688
+ * DDL) plus the parameters needed to lower the typed pre/postchecks at render
689
+ * time.
690
+ *
691
+ * No authored `PostgresMigration` method: this call is only emitted by the
692
+ * planner, never hand-written by migration authors.
693
+ */
694
+ export class AddNotNullColumnDirectCall extends PostgresOpFactoryCallNode {
695
+ readonly factoryName = 'rawSql' as const;
696
+ readonly operationClass = 'additive' as const;
697
+ readonly schemaName: string;
698
+ readonly tableName: string;
699
+ readonly columnName: string;
700
+ readonly executeStepSql: string;
701
+ readonly label: string;
702
+
703
+ constructor(schemaName: string, tableName: string, columnName: string, executeStepSql: string) {
704
+ super();
705
+ this.schemaName = schemaName;
706
+ this.tableName = tableName;
707
+ this.columnName = columnName;
708
+ this.executeStepSql = executeStepSql;
709
+ this.label = `Add column ${columnName} to ${tableName}`;
710
+ this.freeze();
711
+ }
712
+
713
+ async toOp(lowerer?: ExecuteRequestLowerer): Promise<Op> {
714
+ if (lowerer === undefined) {
715
+ throw new Error(
716
+ `AddNotNullColumnDirectCall.toOp: a lowerer is required on the Postgres planner path (column "${this.columnName}" on table "${this.tableName}"). Pass the control adapter to createPostgresMigrationPlanner.`,
717
+ );
718
+ }
719
+ return addNotNullColumnDirect(
720
+ this.schemaName,
721
+ this.tableName,
722
+ this.columnName,
723
+ this.executeStepSql,
724
+ lowerer,
725
+ );
726
+ }
727
+
728
+ renderTypeScript(): string {
729
+ return `rawSql(${jsonToTsSource({ id: `column.${this.tableName}.${this.columnName}`, label: this.label, operationClass: 'additive' })})`;
730
+ }
731
+
732
+ override importRequirements(): readonly ImportRequirement[] {
733
+ return [];
734
+ }
735
+ }
736
+
737
+ /**
738
+ * Planner-internal call for adding a NOT NULL column (no contract default)
739
+ * using a temporary default value for non-empty tables. Carries all parameters
740
+ * needed for `buildAddNotNullColumnWithTemporaryDefaultOperation`; the typed
741
+ * pre/postchecks are lowered at render time via `toOp(lowerer)`. The execute
742
+ * SQL (`buildAddColumnSql`) is still raw per slice-7 deferral.
743
+ *
744
+ * No authored `PostgresMigration` method: this call is only emitted by the
745
+ * planner, never hand-written by migration authors.
746
+ */
747
+ export class AddNotNullColumnWithTempDefaultCall extends PostgresOpFactoryCallNode {
748
+ readonly factoryName = 'rawSql' as const;
749
+ readonly operationClass = 'additive' as const;
750
+ readonly schemaName: string;
751
+ readonly tableName: string;
752
+ readonly columnName: string;
753
+ readonly column: StorageColumn;
754
+ readonly codecHooks: Map<string, CodecControlHooks>;
755
+ readonly storageTypes: Record<string, StorageTypeInstance>;
756
+ readonly temporaryDefault: string;
757
+ readonly label: string;
758
+
759
+ constructor(options: {
760
+ readonly schemaName: string;
761
+ readonly tableName: string;
762
+ readonly columnName: string;
763
+ readonly column: StorageColumn;
764
+ readonly codecHooks: Map<string, CodecControlHooks>;
765
+ readonly storageTypes: Record<string, StorageTypeInstance>;
766
+ readonly temporaryDefault: string;
767
+ }) {
768
+ super();
769
+ this.schemaName = options.schemaName;
770
+ this.tableName = options.tableName;
771
+ this.columnName = options.columnName;
772
+ this.column = options.column;
773
+ this.codecHooks = options.codecHooks;
774
+ this.storageTypes = options.storageTypes;
775
+ this.temporaryDefault = options.temporaryDefault;
776
+ this.label = `Add column ${options.columnName} to ${options.tableName}`;
777
+ this.freeze();
778
+ }
779
+
780
+ async toOp(lowerer?: ExecuteRequestLowerer): Promise<Op> {
781
+ if (lowerer === undefined) {
782
+ throw new Error(
783
+ `AddNotNullColumnWithTempDefaultCall.toOp: a lowerer is required on the Postgres planner path (column "${this.columnName}" on table "${this.tableName}"). Pass the control adapter to createPostgresMigrationPlanner.`,
784
+ );
785
+ }
786
+ return buildAddNotNullColumnWithTemporaryDefaultOperation({
787
+ schema: this.schemaName,
788
+ tableName: this.tableName,
789
+ columnName: this.columnName,
790
+ column: this.column,
791
+ codecHooks: this.codecHooks,
792
+ storageTypes: this.storageTypes,
793
+ temporaryDefault: this.temporaryDefault,
794
+ lowerer,
795
+ });
796
+ }
797
+
798
+ renderTypeScript(): string {
799
+ return `rawSql(${jsonToTsSource({ id: `column.${this.tableName}.${this.columnName}`, label: this.label, operationClass: 'additive' })})`;
800
+ }
801
+
802
+ override importRequirements(): readonly ImportRequirement[] {
803
+ return [];
592
804
  }
593
805
  }
594
806
 
@@ -596,6 +808,20 @@ export class DropDefaultCall extends PostgresOpFactoryCallNode {
596
808
  // Constraints
597
809
  // ============================================================================
598
810
 
811
+ function constraintCallOptions(
812
+ schemaName: string,
813
+ tableName: string,
814
+ constraintName: string,
815
+ ): string {
816
+ const opts: string[] = [];
817
+ if (schemaName !== UNBOUND_NAMESPACE_ID) {
818
+ opts.push(`schema: ${jsonToTsSource(schemaName)}`);
819
+ }
820
+ opts.push(`table: ${jsonToTsSource(tableName)}`);
821
+ opts.push(`constraint: ${jsonToTsSource(constraintName)}`);
822
+ return opts.join(', ');
823
+ }
824
+
599
825
  export class AddPrimaryKeyCall extends PostgresOpFactoryCallNode {
600
826
  readonly factoryName = 'addPrimaryKey' as const;
601
827
  readonly operationClass = 'additive' as const;
@@ -620,12 +846,27 @@ export class AddPrimaryKeyCall extends PostgresOpFactoryCallNode {
620
846
  this.freeze();
621
847
  }
622
848
 
623
- toOp(): Op {
624
- return addPrimaryKey(this.schemaName, this.tableName, this.constraintName, this.columns);
849
+ async toOp(lowerer?: ExecuteRequestLowerer): Promise<Op> {
850
+ if (lowerer === undefined) {
851
+ throw new Error(
852
+ `AddPrimaryKeyCall.toOp: a lowerer is required on the Postgres planner path (constraint "${this.constraintName}" on table "${this.tableName}"). Pass the control adapter to createPostgresMigrationPlanner.`,
853
+ );
854
+ }
855
+ return addPrimaryKey(
856
+ this.schemaName,
857
+ this.tableName,
858
+ this.constraintName,
859
+ this.columns,
860
+ lowerer,
861
+ );
625
862
  }
626
863
 
627
864
  renderTypeScript(): string {
628
- return `addPrimaryKey(${jsonToTsSource(this.schemaName)}, ${jsonToTsSource(this.tableName)}, ${jsonToTsSource(this.constraintName)}, ${jsonToTsSource(this.columns)})`;
865
+ return `this.addPrimaryKey({ ${constraintCallOptions(this.schemaName, this.tableName, this.constraintName)}, columns: ${jsonToTsSource(this.columns)} })`;
866
+ }
867
+
868
+ override importRequirements(): readonly ImportRequirement[] {
869
+ return [];
629
870
  }
630
871
  }
631
872
 
@@ -653,12 +894,21 @@ export class AddUniqueCall extends PostgresOpFactoryCallNode {
653
894
  this.freeze();
654
895
  }
655
896
 
656
- toOp(): Op {
657
- return addUnique(this.schemaName, this.tableName, this.constraintName, this.columns);
897
+ async toOp(lowerer?: ExecuteRequestLowerer): Promise<Op> {
898
+ if (lowerer === undefined) {
899
+ throw new Error(
900
+ `AddUniqueCall.toOp: a lowerer is required on the Postgres planner path (constraint "${this.constraintName}" on table "${this.tableName}"). Pass the control adapter to createPostgresMigrationPlanner.`,
901
+ );
902
+ }
903
+ return addUnique(this.schemaName, this.tableName, this.constraintName, this.columns, lowerer);
658
904
  }
659
905
 
660
906
  renderTypeScript(): string {
661
- return `addUnique(${jsonToTsSource(this.schemaName)}, ${jsonToTsSource(this.tableName)}, ${jsonToTsSource(this.constraintName)}, ${jsonToTsSource(this.columns)})`;
907
+ return `this.addUnique({ ${constraintCallOptions(this.schemaName, this.tableName, this.constraintName)}, columns: ${jsonToTsSource(this.columns)} })`;
908
+ }
909
+
910
+ override importRequirements(): readonly ImportRequirement[] {
911
+ return [];
662
912
  }
663
913
  }
664
914
 
@@ -679,12 +929,27 @@ export class AddForeignKeyCall extends PostgresOpFactoryCallNode {
679
929
  this.freeze();
680
930
  }
681
931
 
682
- toOp(): Op {
683
- return addForeignKey(this.schemaName, this.tableName, this.fk);
932
+ async toOp(lowerer?: ExecuteRequestLowerer): Promise<Op> {
933
+ if (lowerer === undefined) {
934
+ throw new Error(
935
+ `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.`,
936
+ );
937
+ }
938
+ return addForeignKey(this.schemaName, this.tableName, this.fk, lowerer);
684
939
  }
685
940
 
686
941
  renderTypeScript(): string {
687
- return `addForeignKey(${jsonToTsSource(this.schemaName)}, ${jsonToTsSource(this.tableName)}, ${jsonToTsSource(this.fk)})`;
942
+ const opts: string[] = [];
943
+ if (this.schemaName !== UNBOUND_NAMESPACE_ID) {
944
+ opts.push(`schema: ${jsonToTsSource(this.schemaName)}`);
945
+ }
946
+ opts.push(`table: ${jsonToTsSource(this.tableName)}`);
947
+ opts.push(`foreignKey: ${jsonToTsSource(this.fk)}`);
948
+ return `this.addForeignKey({ ${opts.join(', ')} })`;
949
+ }
950
+
951
+ override importRequirements(): readonly ImportRequirement[] {
952
+ return [];
688
953
  }
689
954
  }
690
955
 
@@ -712,20 +977,25 @@ export class DropConstraintCall extends PostgresOpFactoryCallNode {
712
977
  this.freeze();
713
978
  }
714
979
 
715
- toOp(): Op {
716
- return dropConstraint(this.schemaName, this.tableName, this.constraintName, this.kind);
980
+ async toOp(lowerer?: ExecuteRequestLowerer): Promise<Op> {
981
+ if (lowerer === undefined) {
982
+ throw new Error(
983
+ `DropConstraintCall.toOp: a lowerer is required on the Postgres planner path (constraint "${this.constraintName}" on table "${this.tableName}"). Pass the control adapter to createPostgresMigrationPlanner.`,
984
+ );
985
+ }
986
+ return dropConstraint(this.schemaName, this.tableName, this.constraintName, lowerer, this.kind);
717
987
  }
718
988
 
719
989
  renderTypeScript(): string {
720
- const args = [
721
- jsonToTsSource(this.schemaName),
722
- jsonToTsSource(this.tableName),
723
- jsonToTsSource(this.constraintName),
724
- ];
990
+ const opts = [constraintCallOptions(this.schemaName, this.tableName, this.constraintName)];
725
991
  if (this.kind !== 'unique') {
726
- args.push(jsonToTsSource(this.kind));
992
+ opts.push(`kind: ${jsonToTsSource(this.kind)}`);
727
993
  }
728
- return `dropConstraint(${args.join(', ')})`;
994
+ return `this.dropConstraint({ ${opts.join(', ')} })`;
995
+ }
996
+
997
+ override importRequirements(): readonly ImportRequirement[] {
998
+ return [];
729
999
  }
730
1000
  }
731
1001
 
@@ -756,18 +1026,28 @@ export class AddCheckConstraintCall extends PostgresOpFactoryCallNode {
756
1026
  this.freeze();
757
1027
  }
758
1028
 
759
- toOp(): Op {
1029
+ async toOp(lowerer?: ExecuteRequestLowerer): Promise<Op> {
1030
+ if (lowerer === undefined) {
1031
+ throw new Error(
1032
+ `AddCheckConstraintCall.toOp: a lowerer is required on the Postgres planner path (constraint "${this.constraintName}" on table "${this.tableName}"). Pass the control adapter to createPostgresMigrationPlanner.`,
1033
+ );
1034
+ }
760
1035
  return addCheckConstraint(
761
1036
  this.schemaName,
762
1037
  this.tableName,
763
1038
  this.constraintName,
764
1039
  this.column,
765
1040
  this.values,
1041
+ lowerer,
766
1042
  );
767
1043
  }
768
1044
 
769
1045
  renderTypeScript(): string {
770
- return `addCheckConstraint(${jsonToTsSource(this.schemaName)}, ${jsonToTsSource(this.tableName)}, ${jsonToTsSource(this.constraintName)}, ${jsonToTsSource(this.column)}, ${jsonToTsSource(this.values)})`;
1046
+ return `this.addCheckConstraint({ ${constraintCallOptions(this.schemaName, this.tableName, this.constraintName)}, column: ${jsonToTsSource(this.column)}, values: ${jsonToTsSource(this.values)} })`;
1047
+ }
1048
+
1049
+ override importRequirements(): readonly ImportRequirement[] {
1050
+ return [];
771
1051
  }
772
1052
  }
773
1053
 
@@ -788,12 +1068,21 @@ export class DropCheckConstraintCall extends PostgresOpFactoryCallNode {
788
1068
  this.freeze();
789
1069
  }
790
1070
 
791
- toOp(): Op {
792
- return dropCheckConstraint(this.schemaName, this.tableName, this.constraintName);
1071
+ async toOp(lowerer?: ExecuteRequestLowerer): Promise<Op> {
1072
+ if (lowerer === undefined) {
1073
+ throw new Error(
1074
+ `DropCheckConstraintCall.toOp: a lowerer is required on the Postgres planner path (constraint "${this.constraintName}" on table "${this.tableName}"). Pass the control adapter to createPostgresMigrationPlanner.`,
1075
+ );
1076
+ }
1077
+ return dropCheckConstraint(this.schemaName, this.tableName, this.constraintName, lowerer);
793
1078
  }
794
1079
 
795
1080
  renderTypeScript(): string {
796
- return `dropCheckConstraint(${jsonToTsSource(this.schemaName)}, ${jsonToTsSource(this.tableName)}, ${jsonToTsSource(this.constraintName)})`;
1081
+ return `this.dropCheckConstraint({ ${constraintCallOptions(this.schemaName, this.tableName, this.constraintName)} })`;
1082
+ }
1083
+
1084
+ override importRequirements(): readonly ImportRequirement[] {
1085
+ return [];
797
1086
  }
798
1087
  }
799
1088
 
@@ -832,27 +1121,44 @@ export class CreateIndexCall extends PostgresOpFactoryCallNode {
832
1121
  this.freeze();
833
1122
  }
834
1123
 
835
- toOp(): Op {
1124
+ async toOp(lowerer?: ExecuteRequestLowerer): Promise<Op> {
1125
+ if (lowerer === undefined) {
1126
+ throw new Error(
1127
+ `CreateIndexCall.toOp: a lowerer is required on the Postgres planner path (index "${this.indexName}" on table "${this.tableName}"). Pass the control adapter to createPostgresMigrationPlanner.`,
1128
+ );
1129
+ }
836
1130
  const extras: { type?: string; options?: Record<string, unknown> } = {};
837
1131
  if (this.indexType !== undefined) extras.type = this.indexType;
838
1132
  if (this.options !== undefined) extras.options = this.options;
839
- return createIndex(this.schemaName, this.tableName, this.indexName, this.columns, extras);
1133
+ return createIndex(
1134
+ this.schemaName,
1135
+ this.tableName,
1136
+ this.indexName,
1137
+ this.columns,
1138
+ lowerer,
1139
+ extras,
1140
+ );
840
1141
  }
841
1142
 
842
1143
  renderTypeScript(): string {
843
- const args = [
844
- jsonToTsSource(this.schemaName),
845
- jsonToTsSource(this.tableName),
846
- jsonToTsSource(this.indexName),
847
- jsonToTsSource(this.columns),
848
- ];
1144
+ const opts: string[] = [];
1145
+ if (this.schemaName !== UNBOUND_NAMESPACE_ID) {
1146
+ opts.push(`schema: ${jsonToTsSource(this.schemaName)}`);
1147
+ }
1148
+ opts.push(`table: ${jsonToTsSource(this.tableName)}`);
1149
+ opts.push(`index: ${jsonToTsSource(this.indexName)}`);
1150
+ opts.push(`columns: ${jsonToTsSource(this.columns)}`);
849
1151
  if (this.indexType !== undefined || this.options !== undefined) {
850
1152
  const extrasParts: string[] = [];
851
1153
  if (this.indexType !== undefined) extrasParts.push(`type: ${jsonToTsSource(this.indexType)}`);
852
1154
  if (this.options !== undefined) extrasParts.push(`options: ${jsonToTsSource(this.options)}`);
853
- args.push(`{ ${extrasParts.join(', ')} }`);
1155
+ opts.push(`extras: { ${extrasParts.join(', ')} }`);
854
1156
  }
855
- return `createIndex(${args.join(', ')})`;
1157
+ return `this.createIndex({ ${opts.join(', ')} })`;
1158
+ }
1159
+
1160
+ override importRequirements(): readonly ImportRequirement[] {
1161
+ return [];
856
1162
  }
857
1163
  }
858
1164
 
@@ -873,12 +1179,27 @@ export class DropIndexCall extends PostgresOpFactoryCallNode {
873
1179
  this.freeze();
874
1180
  }
875
1181
 
876
- toOp(): Op {
877
- return dropIndex(this.schemaName, this.tableName, this.indexName);
1182
+ async toOp(lowerer?: ExecuteRequestLowerer): Promise<Op> {
1183
+ if (lowerer === undefined) {
1184
+ throw new Error(
1185
+ `DropIndexCall.toOp: a lowerer is required on the Postgres planner path (index "${this.indexName}" on table "${this.tableName}"). Pass the control adapter to createPostgresMigrationPlanner.`,
1186
+ );
1187
+ }
1188
+ return dropIndex(this.schemaName, this.tableName, this.indexName, lowerer);
878
1189
  }
879
1190
 
880
1191
  renderTypeScript(): string {
881
- return `dropIndex(${jsonToTsSource(this.schemaName)}, ${jsonToTsSource(this.tableName)}, ${jsonToTsSource(this.indexName)})`;
1192
+ const opts: string[] = [];
1193
+ if (this.schemaName !== UNBOUND_NAMESPACE_ID) {
1194
+ opts.push(`schema: ${jsonToTsSource(this.schemaName)}`);
1195
+ }
1196
+ opts.push(`table: ${jsonToTsSource(this.tableName)}`);
1197
+ opts.push(`index: ${jsonToTsSource(this.indexName)}`);
1198
+ return `this.dropIndex({ ${opts.join(', ')} })`;
1199
+ }
1200
+
1201
+ override importRequirements(): readonly ImportRequirement[] {
1202
+ return [];
882
1203
  }
883
1204
  }
884
1205
 
@@ -1064,6 +1385,8 @@ export type PostgresOpFactoryCall =
1064
1385
  | DropNotNullCall
1065
1386
  | SetDefaultCall
1066
1387
  | DropDefaultCall
1388
+ | AddNotNullColumnDirectCall
1389
+ | AddNotNullColumnWithTempDefaultCall
1067
1390
  | AddPrimaryKeyCall
1068
1391
  | AddForeignKeyCall
1069
1392
  | AddUniqueCall