@prisma-next/target-postgres 0.13.0 → 0.14.0-dev.2

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 (190) hide show
  1. package/dist/{codec-ids-CTikp1if.mjs → codec-ids-BvytN2P8.mjs} +3 -3
  2. package/dist/codec-ids-BvytN2P8.mjs.map +1 -0
  3. package/dist/{codec-ids-B1vOchLE.d.mts → codec-ids-CnXu9Qy3.d.mts} +3 -3
  4. package/dist/codec-ids-CnXu9Qy3.d.mts.map +1 -0
  5. package/dist/codec-ids.d.mts +2 -2
  6. package/dist/codec-ids.mjs +2 -2
  7. package/dist/{codec-types-CnFiNML4.d.mts → codec-types-DHCkwPKE.d.mts} +3 -3
  8. package/dist/{codec-types-CnFiNML4.d.mts.map → codec-types-DHCkwPKE.d.mts.map} +1 -1
  9. package/dist/codec-types.d.mts +1 -1
  10. package/dist/{codecs-CBpEv4s5.d.mts → codecs--0A5_4Bq.d.mts} +26 -23
  11. package/dist/codecs--0A5_4Bq.d.mts.map +1 -0
  12. package/dist/codecs.d.mts +2 -2
  13. package/dist/codecs.mjs +28 -35
  14. package/dist/codecs.mjs.map +1 -1
  15. package/dist/contract-free.d.mts +163 -15
  16. package/dist/contract-free.d.mts.map +1 -1
  17. package/dist/contract-free.mjs +4 -17
  18. package/dist/contract-free.mjs.map +1 -1
  19. package/dist/control.d.mts.map +1 -1
  20. package/dist/control.mjs +21 -27
  21. package/dist/control.mjs.map +1 -1
  22. package/dist/{data-transform-D25tLeYU.mjs → data-transform-BOWpliq8.mjs} +9 -17
  23. package/dist/data-transform-BOWpliq8.mjs.map +1 -0
  24. package/dist/{data-transform-DGOqcLrf.d.mts → data-transform-DDgWdB5o.d.mts} +2 -2
  25. package/dist/data-transform-DDgWdB5o.d.mts.map +1 -0
  26. package/dist/data-transform.d.mts +1 -1
  27. package/dist/data-transform.mjs +1 -1
  28. package/dist/ddl-QDyOSeLc.mjs +251 -0
  29. package/dist/ddl-QDyOSeLc.mjs.map +1 -0
  30. package/dist/ddl.d.mts +2 -2
  31. package/dist/ddl.mjs +2 -2
  32. package/dist/descriptor-meta-CpGygXpI.mjs +140 -0
  33. package/dist/descriptor-meta-CpGygXpI.mjs.map +1 -0
  34. package/dist/{issue-planner-Br0pt1Ea.mjs → issue-planner-DL6g3CmE.mjs} +52 -366
  35. package/dist/issue-planner-DL6g3CmE.mjs.map +1 -0
  36. package/dist/issue-planner.d.mts +8 -11
  37. package/dist/issue-planner.d.mts.map +1 -1
  38. package/dist/issue-planner.mjs +1 -1
  39. package/dist/migration.d.mts +5 -92
  40. package/dist/migration.d.mts.map +1 -1
  41. package/dist/migration.mjs +4 -4
  42. package/dist/{nodes-DZk2JZG3.mjs → nodes-Bbhs2rwj.mjs} +31 -2
  43. package/dist/nodes-Bbhs2rwj.mjs.map +1 -0
  44. package/dist/{nodes-779hmCfL.d.mts → nodes-pLeLgdis.d.mts} +30 -3
  45. package/dist/nodes-pLeLgdis.d.mts.map +1 -0
  46. package/dist/{op-factory-call-D2aAUhmS.mjs → op-factory-call-D_p5vxwt.mjs} +601 -418
  47. package/dist/op-factory-call-D_p5vxwt.mjs.map +1 -0
  48. package/dist/{op-factory-call-DMA86_2D.d.mts → op-factory-call-DmQEc3XV.d.mts} +119 -72
  49. package/dist/op-factory-call-DmQEc3XV.d.mts.map +1 -0
  50. package/dist/op-factory-call.d.mts +2 -2
  51. package/dist/op-factory-call.mjs +2 -2
  52. package/dist/pack.d.mts +36 -15
  53. package/dist/pack.d.mts.map +1 -1
  54. package/dist/pack.mjs +1 -1
  55. package/dist/{planner-CAYPJObw.mjs → planner-Bs_baQax.mjs} +25 -45
  56. package/dist/planner-Bs_baQax.mjs.map +1 -0
  57. package/dist/{planner-ddl-builders-Cw2n2llW.mjs → planner-ddl-builders-B2wOwLqI.mjs} +2 -2
  58. package/dist/planner-ddl-builders-B2wOwLqI.mjs.map +1 -0
  59. package/dist/planner-ddl-builders.d.mts +4 -4
  60. package/dist/planner-ddl-builders.d.mts.map +1 -1
  61. package/dist/planner-ddl-builders.mjs +1 -1
  62. package/dist/{planner-identity-values-BIpa5p2I.mjs → planner-identity-values-CJPha2Sz.mjs} +3 -9
  63. package/dist/planner-identity-values-CJPha2Sz.mjs.map +1 -0
  64. package/dist/planner-identity-values.d.mts +1 -1
  65. package/dist/planner-identity-values.d.mts.map +1 -1
  66. package/dist/planner-identity-values.mjs +1 -1
  67. package/dist/{planner-produced-postgres-migration-NSEhWL0L.mjs → planner-produced-postgres-migration-Cji5vxUf.mjs} +6 -4
  68. package/dist/planner-produced-postgres-migration-Cji5vxUf.mjs.map +1 -0
  69. package/dist/{planner-produced-postgres-migration-B4EDvLdz.d.mts → planner-produced-postgres-migration-QqHa2C2l.d.mts} +5 -6
  70. package/dist/planner-produced-postgres-migration-QqHa2C2l.d.mts.map +1 -0
  71. package/dist/planner-produced-postgres-migration.d.mts +1 -1
  72. package/dist/planner-produced-postgres-migration.mjs +1 -1
  73. package/dist/planner-sql-checks-jqUUGyQR.mjs +152 -0
  74. package/dist/planner-sql-checks-jqUUGyQR.mjs.map +1 -0
  75. package/dist/planner-sql-checks.d.mts +3 -49
  76. package/dist/planner-sql-checks.d.mts.map +1 -1
  77. package/dist/planner-sql-checks.mjs +2 -2
  78. package/dist/{planner-type-resolution-836DExFN.mjs → planner-type-resolution-Bt2f_q-F.mjs} +1 -6
  79. package/dist/planner-type-resolution-Bt2f_q-F.mjs.map +1 -0
  80. package/dist/planner.d.mts +4 -4
  81. package/dist/planner.d.mts.map +1 -1
  82. package/dist/planner.mjs +1 -1
  83. package/dist/{postgres-contract-serializer-DYTyXjPf.mjs → postgres-contract-serializer-k3TAcPMY.mjs} +30 -37
  84. package/dist/postgres-contract-serializer-k3TAcPMY.mjs.map +1 -0
  85. package/dist/postgres-migration-B5jKrXv3.mjs +145 -0
  86. package/dist/postgres-migration-B5jKrXv3.mjs.map +1 -0
  87. package/dist/postgres-migration-Y4YBJqkS.d.mts +181 -0
  88. package/dist/postgres-migration-Y4YBJqkS.d.mts.map +1 -0
  89. package/dist/{postgres-schema-BuxCxbvB.mjs → postgres-schema-COGZ1ark.mjs} +82 -23
  90. package/dist/postgres-schema-COGZ1ark.mjs.map +1 -0
  91. package/dist/{render-ops-BpjstrKQ.mjs → render-ops-BREh1kHe.mjs} +10 -5
  92. package/dist/render-ops-BREh1kHe.mjs.map +1 -0
  93. package/dist/render-ops.d.mts +2 -2
  94. package/dist/render-ops.d.mts.map +1 -1
  95. package/dist/render-ops.mjs +1 -1
  96. package/dist/runtime.d.mts +1 -0
  97. package/dist/runtime.d.mts.map +1 -1
  98. package/dist/runtime.mjs +2 -2
  99. package/dist/table-source-BvFo7gVs.d.mts +15 -0
  100. package/dist/table-source-BvFo7gVs.d.mts.map +1 -0
  101. package/dist/types.d.mts +34 -19
  102. package/dist/types.d.mts.map +1 -1
  103. package/dist/types.mjs +2 -3
  104. package/package.json +17 -18
  105. package/src/contract-free/checks.ts +363 -0
  106. package/src/contract-free/ddl.ts +28 -1
  107. package/src/core/authoring.ts +43 -44
  108. package/src/core/codec-helpers.ts +0 -17
  109. package/src/core/codec-ids.ts +1 -1
  110. package/src/core/codec-type-map.ts +2 -2
  111. package/src/core/codecs.ts +43 -48
  112. package/src/core/ddl/nodes.ts +59 -1
  113. package/src/core/migrations/control-policy.ts +17 -47
  114. package/src/core/migrations/issue-planner.ts +34 -70
  115. package/src/core/migrations/op-factory-call.ts +486 -215
  116. package/src/core/migrations/operations/columns.ts +175 -140
  117. package/src/core/migrations/operations/constraints.ts +79 -108
  118. package/src/core/migrations/operations/data-transform.ts +15 -18
  119. package/src/core/migrations/operations/dependencies.ts +16 -14
  120. package/src/core/migrations/operations/indexes.ts +31 -28
  121. package/src/core/migrations/operations/shared.ts +2 -2
  122. package/src/core/migrations/operations/tables.ts +13 -14
  123. package/src/core/migrations/planner-ddl-builders.ts +3 -4
  124. package/src/core/migrations/planner-identity-values.ts +4 -28
  125. package/src/core/migrations/planner-produced-postgres-migration.ts +15 -7
  126. package/src/core/migrations/planner-recipes.ts +44 -39
  127. package/src/core/migrations/planner-sql-checks.ts +3 -178
  128. package/src/core/migrations/planner-strategies.ts +76 -449
  129. package/src/core/migrations/planner-type-resolution.ts +2 -20
  130. package/src/core/migrations/planner.ts +6 -6
  131. package/src/core/migrations/postgres-migration.ts +287 -7
  132. package/src/core/migrations/render-ops.ts +26 -13
  133. package/src/core/migrations/runner.ts +26 -20
  134. package/src/core/postgres-contract-serializer.ts +37 -54
  135. package/src/core/postgres-enum-type-schema.ts +17 -0
  136. package/src/core/postgres-schema.ts +86 -46
  137. package/src/exports/codecs.ts +2 -2
  138. package/src/exports/contract-free.ts +22 -1
  139. package/src/exports/control.ts +0 -22
  140. package/src/exports/ddl.ts +4 -0
  141. package/src/exports/migration.ts +1 -29
  142. package/src/exports/op-factory-call.ts +0 -4
  143. package/src/exports/planner-sql-checks.ts +0 -7
  144. package/src/exports/types.ts +0 -1
  145. package/dist/codec-ids-B1vOchLE.d.mts.map +0 -1
  146. package/dist/codec-ids-CTikp1if.mjs.map +0 -1
  147. package/dist/codecs-CBpEv4s5.d.mts.map +0 -1
  148. package/dist/data-transform-D25tLeYU.mjs.map +0 -1
  149. package/dist/data-transform-DGOqcLrf.d.mts.map +0 -1
  150. package/dist/ddl-77SyXgFt.mjs +0 -30
  151. package/dist/ddl-77SyXgFt.mjs.map +0 -1
  152. package/dist/descriptor-meta-DKmj-IMN.mjs +0 -14
  153. package/dist/descriptor-meta-DKmj-IMN.mjs.map +0 -1
  154. package/dist/descriptor-meta-runtime-My8_s4cs.mjs +0 -130
  155. package/dist/descriptor-meta-runtime-My8_s4cs.mjs.map +0 -1
  156. package/dist/enum-planning-BCyvlFHk.mjs +0 -0
  157. package/dist/enum-planning-BCyvlFHk.mjs.map +0 -1
  158. package/dist/enum-planning.d.mts +0 -86
  159. package/dist/enum-planning.d.mts.map +0 -1
  160. package/dist/enum-planning.mjs +0 -2
  161. package/dist/issue-planner-Br0pt1Ea.mjs.map +0 -1
  162. package/dist/nodes-779hmCfL.d.mts.map +0 -1
  163. package/dist/nodes-DZk2JZG3.mjs.map +0 -1
  164. package/dist/op-factory-call-D2aAUhmS.mjs.map +0 -1
  165. package/dist/op-factory-call-DMA86_2D.d.mts.map +0 -1
  166. package/dist/planner-CAYPJObw.mjs.map +0 -1
  167. package/dist/planner-ddl-builders-Cw2n2llW.mjs.map +0 -1
  168. package/dist/planner-identity-values-BIpa5p2I.mjs.map +0 -1
  169. package/dist/planner-produced-postgres-migration-B4EDvLdz.d.mts.map +0 -1
  170. package/dist/planner-produced-postgres-migration-NSEhWL0L.mjs.map +0 -1
  171. package/dist/planner-sql-checks-DAdhnI2c.mjs +0 -272
  172. package/dist/planner-sql-checks-DAdhnI2c.mjs.map +0 -1
  173. package/dist/planner-type-resolution-836DExFN.mjs.map +0 -1
  174. package/dist/postgres-contract-serializer-DYTyXjPf.mjs.map +0 -1
  175. package/dist/postgres-enum-type-BVn63a89.d.mts +0 -72
  176. package/dist/postgres-enum-type-BVn63a89.d.mts.map +0 -1
  177. package/dist/postgres-enum-type-DPKqCBem.mjs +0 -62
  178. package/dist/postgres-enum-type-DPKqCBem.mjs.map +0 -1
  179. package/dist/postgres-migration-COore9Mz.mjs +0 -71
  180. package/dist/postgres-migration-COore9Mz.mjs.map +0 -1
  181. package/dist/postgres-migration-DZ_gLUOW.d.mts +0 -72
  182. package/dist/postgres-migration-DZ_gLUOW.d.mts.map +0 -1
  183. package/dist/postgres-schema-BuxCxbvB.mjs.map +0 -1
  184. package/dist/render-ops-BpjstrKQ.mjs.map +0 -1
  185. package/dist/shared-DarONYBZ.d.mts +0 -43
  186. package/dist/shared-DarONYBZ.d.mts.map +0 -1
  187. package/src/core/migrations/enum-planning.ts +0 -213
  188. package/src/core/migrations/operations/enums.ts +0 -114
  189. package/src/core/postgres-enum-type.ts +0 -89
  190. package/src/exports/enum-planning.ts +0 -11
@@ -1,12 +1,6 @@
1
1
  import type { CodecControlHooks } from '@prisma-next/family-sql/control';
2
- import {
3
- isPostgresEnumStorageEntry,
4
- type PostgresEnumStorageEntry,
5
- type StorageColumn,
6
- type StorageTypeInstance,
7
- } from '@prisma-next/sql-contract/types';
2
+ import type { StorageColumn, StorageTypeInstance } from '@prisma-next/sql-contract/types';
8
3
  import { ifDefined } from '@prisma-next/utils/defined';
9
- import type { PostgresEnumType } from '../postgres-enum-type';
10
4
 
11
5
  /**
12
6
  * Resolves the identity value (monoid neutral element) as a SQL literal for a column's type.
@@ -16,30 +10,12 @@ import type { PostgresEnumType } from '../postgres-enum-type';
16
10
  export function resolveIdentityValue(
17
11
  column: StorageColumn,
18
12
  codecHooks: Map<string, CodecControlHooks>,
19
- storageTypes: Record<string, StorageTypeInstance | PostgresEnumStorageEntry> = {},
13
+ storageTypes: Record<string, StorageTypeInstance> = {},
20
14
  ): string | null {
21
15
  const referencedType = column.typeRef ? storageTypes[column.typeRef] : undefined;
22
- const referencedIsEnum =
23
- referencedType !== undefined && isPostgresEnumStorageEntry(referencedType);
24
- const referencedBinding = referencedIsEnum
25
- ? ((referencedType as PostgresEnumType).codecBinding ?? {
26
- codecId: (referencedType as PostgresEnumStorageEntry).codecId,
27
- typeParams: { values: (referencedType as PostgresEnumStorageEntry).values },
28
- })
29
- : undefined;
30
- const codecId =
31
- referencedBinding?.codecId ??
32
- (referencedType && !referencedIsEnum
33
- ? (referencedType as StorageTypeInstance).codecId
34
- : undefined) ??
35
- column.codecId;
16
+ const codecId = referencedType?.codecId ?? column.codecId;
36
17
  const nativeType = referencedType?.nativeType ?? column.nativeType;
37
- const typeParams =
38
- (referencedBinding?.typeParams as Record<string, unknown> | undefined) ??
39
- (referencedType && !referencedIsEnum
40
- ? (referencedType as StorageTypeInstance).typeParams
41
- : undefined) ??
42
- column.typeParams;
18
+ const typeParams = referencedType?.typeParams ?? column.typeParams;
43
19
 
44
20
  if (codecId) {
45
21
  const hookDefault = codecHooks.get(codecId)?.resolveIdentityValue?.({
@@ -24,7 +24,7 @@
24
24
  */
25
25
 
26
26
  import type { SqlMigrationPlanOperation } from '@prisma-next/family-sql/control';
27
- import type { Lowerer } from '@prisma-next/family-sql/control-adapter';
27
+ import type { ExecuteRequestLowerer } from '@prisma-next/family-sql/control-adapter';
28
28
  import type {
29
29
  MigrationPlanWithAuthoringSurface,
30
30
  OpFactoryCall,
@@ -35,8 +35,6 @@ import { PostgresMigration } from './postgres-migration';
35
35
  import { renderOps } from './render-ops';
36
36
  import { renderCallsToTypeScript } from './render-typescript';
37
37
 
38
- type Op = SqlMigrationPlanOperation<PostgresPlanTargetDetails>;
39
-
40
38
  export class TypeScriptRenderablePostgresMigration
41
39
  extends PostgresMigration
42
40
  implements MigrationPlanWithAuthoringSurface
@@ -44,13 +42,19 @@ export class TypeScriptRenderablePostgresMigration
44
42
  readonly #calls: readonly OpFactoryCall[];
45
43
  readonly #meta: MigrationMeta;
46
44
  readonly #spaceId: string;
47
- readonly #lowerer: Lowerer | undefined;
45
+ readonly #lowerer: ExecuteRequestLowerer | undefined;
46
+ #operationsCache:
47
+ | readonly (
48
+ | SqlMigrationPlanOperation<PostgresPlanTargetDetails>
49
+ | Promise<SqlMigrationPlanOperation<PostgresPlanTargetDetails>>
50
+ )[]
51
+ | undefined;
48
52
 
49
53
  constructor(
50
54
  calls: readonly OpFactoryCall[],
51
55
  meta: MigrationMeta,
52
56
  spaceId: string,
53
- lowerer?: Lowerer,
57
+ lowerer?: ExecuteRequestLowerer,
54
58
  ) {
55
59
  super();
56
60
  this.#calls = calls;
@@ -59,8 +63,12 @@ export class TypeScriptRenderablePostgresMigration
59
63
  this.#lowerer = lowerer;
60
64
  }
61
65
 
62
- override get operations(): readonly Op[] {
63
- return renderOps(this.#calls, this.#lowerer);
66
+ override get operations(): readonly (
67
+ | SqlMigrationPlanOperation<PostgresPlanTargetDetails>
68
+ | Promise<SqlMigrationPlanOperation<PostgresPlanTargetDetails>>
69
+ )[] {
70
+ this.#operationsCache ??= renderOps(this.#calls, this.#lowerer);
71
+ return this.#operationsCache;
64
72
  }
65
73
 
66
74
  override describe(): MigrationMeta {
@@ -1,17 +1,15 @@
1
1
  import type { CodecControlHooks, SqlMigrationPlanOperation } from '@prisma-next/family-sql/control';
2
- import type {
3
- PostgresEnumStorageEntry,
4
- StorageColumn,
5
- StorageTypeInstance,
6
- } from '@prisma-next/sql-contract/types';
2
+ import type { ExecuteRequestLowerer } from '@prisma-next/family-sql/control-adapter';
3
+ import type { StorageColumn, StorageTypeInstance } from '@prisma-next/sql-contract/types';
4
+ import {
5
+ columnDefaultAst,
6
+ columnExistsAst,
7
+ columnNullabilityAst,
8
+ } from '../../contract-free/checks';
7
9
  import { quoteIdentifier } from '../sql-utils';
10
+ import { step } from './operations/shared';
8
11
  import { buildAddColumnSql } from './planner-ddl-builders';
9
- import {
10
- columnExistsCheck,
11
- columnHasNoDefaultCheck,
12
- columnNullabilityCheck,
13
- qualifyTableName,
14
- } from './planner-sql-checks';
12
+ import { qualifyTableName } from './planner-sql-checks';
15
13
  import { buildTargetDetails, type PostgresPlanTargetDetails } from './planner-target-details';
16
14
 
17
15
  export function buildAddColumnOperationIdentity(
@@ -33,28 +31,45 @@ export function buildAddColumnOperationIdentity(
33
31
  };
34
32
  }
35
33
 
36
- export function buildAddNotNullColumnWithTemporaryDefaultOperation(options: {
34
+ export async function buildAddNotNullColumnWithTemporaryDefaultOperation(options: {
37
35
  readonly schema: string;
38
36
  readonly tableName: string;
39
37
  readonly columnName: string;
40
38
  readonly column: StorageColumn;
41
39
  readonly codecHooks: Map<string, CodecControlHooks>;
42
- readonly storageTypes: Record<string, StorageTypeInstance | PostgresEnumStorageEntry>;
40
+ readonly storageTypes: Record<string, StorageTypeInstance>;
43
41
  readonly temporaryDefault: string;
44
- }): SqlMigrationPlanOperation<PostgresPlanTargetDetails> {
45
- const { schema, tableName, columnName, column, codecHooks, storageTypes, temporaryDefault } =
46
- options;
42
+ readonly lowerer: ExecuteRequestLowerer;
43
+ }): Promise<SqlMigrationPlanOperation<PostgresPlanTargetDetails>> {
44
+ const {
45
+ schema,
46
+ tableName,
47
+ columnName,
48
+ column,
49
+ codecHooks,
50
+ storageTypes,
51
+ temporaryDefault,
52
+ lowerer,
53
+ } = options;
47
54
  const qualified = qualifyTableName(schema, tableName);
48
55
 
56
+ const absent = await lowerer.lowerToExecuteRequest(
57
+ columnExistsAst({ schema, table: tableName, column: columnName }).columnAbsent(),
58
+ );
59
+ const present = await lowerer.lowerToExecuteRequest(
60
+ columnExistsAst({ schema, table: tableName, column: columnName }).columnPresent(),
61
+ );
62
+ const notNullable = await lowerer.lowerToExecuteRequest(
63
+ columnNullabilityAst({ schema, table: tableName, column: columnName, nullable: false }),
64
+ );
65
+ const noDefault = await lowerer.lowerToExecuteRequest(
66
+ columnDefaultAst({ schema, table: tableName, column: columnName }).noDefault(),
67
+ );
68
+
49
69
  return {
50
70
  ...buildAddColumnOperationIdentity(schema, tableName, columnName),
51
71
  operationClass: 'additive',
52
- precheck: [
53
- {
54
- description: `ensure column "${columnName}" is missing`,
55
- sql: columnExistsCheck({ schema, table: tableName, column: columnName, exists: false }),
56
- },
57
- ],
72
+ precheck: [step(`ensure column "${columnName}" is missing`, absent.sql, absent.params)],
58
73
  execute: [
59
74
  {
60
75
  description: `add column "${columnName}"`,
@@ -73,23 +88,13 @@ export function buildAddNotNullColumnWithTemporaryDefaultOperation(options: {
73
88
  },
74
89
  ],
75
90
  postcheck: [
76
- {
77
- description: `verify column "${columnName}" exists`,
78
- sql: columnExistsCheck({ schema, table: tableName, column: columnName }),
79
- },
80
- {
81
- description: `verify column "${columnName}" is NOT NULL`,
82
- sql: columnNullabilityCheck({
83
- schema,
84
- table: tableName,
85
- column: columnName,
86
- nullable: false,
87
- }),
88
- },
89
- {
90
- description: `verify column "${columnName}" has no default after temporary default removal`,
91
- sql: columnHasNoDefaultCheck({ schema, table: tableName, column: columnName }),
92
- },
91
+ step(`verify column "${columnName}" exists`, present.sql, present.params),
92
+ step(`verify column "${columnName}" is NOT NULL`, notNullable.sql, notNullable.params),
93
+ step(
94
+ `verify column "${columnName}" has no default after temporary default removal`,
95
+ noDefault.sql,
96
+ noDefault.params,
97
+ ),
93
98
  ],
94
99
  };
95
100
  }
@@ -1,11 +1,7 @@
1
1
  import type { CodecControlHooks } from '@prisma-next/family-sql/control';
2
- import type {
3
- PostgresEnumStorageEntry,
4
- StorageColumn,
5
- StorageTypeInstance,
6
- } from '@prisma-next/sql-contract/types';
2
+ import type { StorageColumn, StorageTypeInstance } from '@prisma-next/sql-contract/types';
7
3
  import { postgresCreateNamespace } from '../postgres-schema';
8
- import { escapeLiteral, quoteIdentifier } from '../sql-utils';
4
+ import { quoteIdentifier } from '../sql-utils';
9
5
  import { resolveColumnTypeMetadata } from './planner-type-resolution';
10
6
 
11
7
  /**
@@ -23,105 +19,6 @@ export function qualifyTableName(schema: string, table: string): string {
23
19
  return postgresCreateNamespace({ id: schema, entries: { table: {} } }).qualifyTable(table);
24
20
  }
25
21
 
26
- export function toRegclassLiteral(schema: string, name: string): string {
27
- return postgresCreateNamespace({ id: schema, entries: { table: {} } }).regclassLiteral(name);
28
- }
29
-
30
- /**
31
- * When `table` is omitted the check matches by name + schema across all tables.
32
- * Pass `table` to scope the check to a single table (prevents false matches on
33
- * identically-named constraints in different tables).
34
- */
35
- export function constraintExistsCheck({
36
- constraintName,
37
- schema,
38
- table,
39
- exists = true,
40
- }: {
41
- constraintName: string;
42
- schema: string;
43
- table?: string;
44
- exists?: boolean;
45
- }): string {
46
- const namespace = postgresCreateNamespace({ id: schema, entries: { table: {} } });
47
- const existsClause = exists ? 'EXISTS' : 'NOT EXISTS';
48
- const tableFilter = table
49
- ? `AND c.conrelid = to_regclass(${namespace.regclassLiteral(table)})`
50
- : '';
51
- return `SELECT ${existsClause} (
52
- SELECT 1 FROM pg_constraint c
53
- JOIN pg_namespace n ON c.connamespace = n.oid
54
- WHERE c.conname = '${escapeLiteral(constraintName)}'
55
- AND n.nspname = ${namespace.schemaSqlExpression()}
56
- ${tableFilter}
57
- )`;
58
- }
59
-
60
- export function columnExistsCheck({
61
- schema,
62
- table,
63
- column,
64
- exists = true,
65
- }: {
66
- schema: string;
67
- table: string;
68
- column: string;
69
- exists?: boolean;
70
- }): string {
71
- const namespace = postgresCreateNamespace({ id: schema, entries: { table: {} } });
72
- const existsClause = exists ? '' : 'NOT ';
73
- return `SELECT ${existsClause}EXISTS (
74
- SELECT 1
75
- FROM information_schema.columns
76
- WHERE table_schema = ${namespace.schemaSqlExpression()}
77
- AND table_name = '${escapeLiteral(table)}'
78
- AND column_name = '${escapeLiteral(column)}'
79
- )`;
80
- }
81
-
82
- export function columnNullabilityCheck({
83
- schema,
84
- table,
85
- column,
86
- nullable,
87
- }: {
88
- schema: string;
89
- table: string;
90
- column: string;
91
- nullable: boolean;
92
- }): string {
93
- const namespace = postgresCreateNamespace({ id: schema, entries: { table: {} } });
94
- const expected = nullable ? 'YES' : 'NO';
95
- return `SELECT EXISTS (
96
- SELECT 1
97
- FROM information_schema.columns
98
- WHERE table_schema = ${namespace.schemaSqlExpression()}
99
- AND table_name = '${escapeLiteral(table)}'
100
- AND column_name = '${escapeLiteral(column)}'
101
- AND is_nullable = '${expected}'
102
- )`;
103
- }
104
-
105
- export function tableIsEmptyCheck(qualifiedTableName: string): string {
106
- return `SELECT NOT EXISTS (SELECT 1 FROM ${qualifiedTableName} LIMIT 1)`;
107
- }
108
-
109
- export function columnHasNoDefaultCheck(opts: {
110
- schema: string;
111
- table: string;
112
- column: string;
113
- }): string {
114
- const namespace = postgresCreateNamespace({ id: opts.schema, entries: { table: {} } });
115
- return `SELECT NOT EXISTS (
116
- SELECT 1
117
- FROM information_schema.columns
118
- WHERE table_schema = ${namespace.schemaSqlExpression()}
119
- AND table_name = '${escapeLiteral(opts.table)}'
120
- AND column_name = '${escapeLiteral(opts.column)}'
121
- AND column_default IS NOT NULL
122
- )`;
123
- }
124
-
125
22
  const FORMAT_TYPE_DISPLAY: ReadonlyMap<string, string> = new Map([
126
23
  ['int2', 'smallint'],
127
24
  ['int4', 'integer'],
@@ -249,7 +146,7 @@ function formatUserDefinedTypeName(identifier: string): string {
249
146
  export function buildExpectedFormatType(
250
147
  column: StorageColumn,
251
148
  codecHooks: Map<string, CodecControlHooks>,
252
- storageTypes: Record<string, StorageTypeInstance | PostgresEnumStorageEntry> = {},
149
+ storageTypes: Record<string, StorageTypeInstance> = {},
253
150
  ): string {
254
151
  const resolved = resolveColumnTypeMetadata(column, storageTypes);
255
152
 
@@ -270,75 +167,3 @@ export function buildExpectedFormatType(
270
167
 
271
168
  return FORMAT_TYPE_DISPLAY.get(resolved.nativeType) ?? resolved.nativeType;
272
169
  }
273
-
274
- export function columnTypeCheck({
275
- schema,
276
- table,
277
- column,
278
- expectedType,
279
- }: {
280
- schema: string;
281
- table: string;
282
- column: string;
283
- expectedType: string;
284
- }): string {
285
- const namespace = postgresCreateNamespace({ id: schema, entries: { table: {} } });
286
- return `SELECT EXISTS (
287
- SELECT 1
288
- FROM pg_attribute a
289
- JOIN pg_class c ON c.oid = a.attrelid
290
- JOIN pg_namespace n ON n.oid = c.relnamespace
291
- WHERE n.nspname = ${namespace.schemaSqlExpression()}
292
- AND c.relname = '${escapeLiteral(table)}'
293
- AND a.attname = '${escapeLiteral(column)}'
294
- AND format_type(a.atttypid, a.atttypmod) = '${escapeLiteral(expectedType)}'
295
- AND NOT a.attisdropped
296
- )`;
297
- }
298
-
299
- export function columnDefaultExistsCheck({
300
- schema,
301
- table,
302
- column,
303
- exists = true,
304
- }: {
305
- schema: string;
306
- table: string;
307
- column: string;
308
- exists?: boolean;
309
- }): string {
310
- const namespace = postgresCreateNamespace({ id: schema, entries: { table: {} } });
311
- const nullCheck = exists ? 'IS NOT NULL' : 'IS NULL';
312
- return `SELECT EXISTS (
313
- SELECT 1
314
- FROM information_schema.columns
315
- WHERE table_schema = ${namespace.schemaSqlExpression()}
316
- AND table_name = '${escapeLiteral(table)}'
317
- AND column_name = '${escapeLiteral(column)}'
318
- AND column_default ${nullCheck}
319
- )`;
320
- }
321
-
322
- export function tableHasPrimaryKeyCheck(
323
- schema: string,
324
- table: string,
325
- exists: boolean,
326
- constraintName?: string,
327
- ): string {
328
- const namespace = postgresCreateNamespace({ id: schema, entries: { table: {} } });
329
- const comparison = exists ? '' : 'NOT ';
330
- const constraintFilter = constraintName
331
- ? `AND c2.relname = '${escapeLiteral(constraintName)}'`
332
- : '';
333
- return `SELECT ${comparison}EXISTS (
334
- SELECT 1
335
- FROM pg_index i
336
- JOIN pg_class c ON c.oid = i.indrelid
337
- JOIN pg_namespace n ON n.oid = c.relnamespace
338
- LEFT JOIN pg_class c2 ON c2.oid = i.indexrelid
339
- WHERE n.nspname = ${namespace.schemaSqlExpression()}
340
- AND c.relname = '${escapeLiteral(table)}'
341
- AND i.indisprimary
342
- ${constraintFilter}
343
- )`;
344
- }