@prisma-next/target-postgres 0.13.0-dev.27 → 0.13.0-dev.29
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.
- package/dist/{codec-ids-C_-Hj6bL.mjs → codec-ids-BvytN2P8.mjs} +2 -3
- package/dist/codec-ids-BvytN2P8.mjs.map +1 -0
- package/dist/{codec-ids-BzrFF-I4.d.mts → codec-ids-CnXu9Qy3.d.mts} +2 -3
- package/dist/codec-ids-CnXu9Qy3.d.mts.map +1 -0
- package/dist/codec-ids.d.mts +2 -2
- package/dist/codec-ids.mjs +2 -2
- package/dist/{codec-types-B0WT0obB.d.mts → codec-types-DHCkwPKE.d.mts} +2 -3
- package/dist/codec-types-DHCkwPKE.d.mts.map +1 -0
- package/dist/codec-types.d.mts +1 -1
- package/dist/{codecs-CX56Smsj.d.mts → codecs--0A5_4Bq.d.mts} +3 -23
- package/dist/codecs--0A5_4Bq.d.mts.map +1 -0
- package/dist/codecs.d.mts +2 -2
- package/dist/codecs.mjs +2 -38
- package/dist/codecs.mjs.map +1 -1
- package/dist/contract-free.mjs +1 -1
- package/dist/control.d.mts.map +1 -1
- package/dist/control.mjs +7 -10
- package/dist/control.mjs.map +1 -1
- package/dist/{descriptor-meta-C7O6XHfh.mjs → descriptor-meta-BKma_hQ5.mjs} +2 -2
- package/dist/{descriptor-meta-C7O6XHfh.mjs.map → descriptor-meta-BKma_hQ5.mjs.map} +1 -1
- package/dist/{descriptor-meta-runtime-BToWdas9.mjs → descriptor-meta-runtime-e5f2tscJ.mjs} +2 -39
- package/dist/descriptor-meta-runtime-e5f2tscJ.mjs.map +1 -0
- package/dist/{issue-planner-CK-XWGB0.mjs → issue-planner-DsjB7xDj.mjs} +17 -227
- package/dist/issue-planner-DsjB7xDj.mjs.map +1 -0
- package/dist/issue-planner.d.mts +8 -11
- package/dist/issue-planner.d.mts.map +1 -1
- package/dist/issue-planner.mjs +1 -1
- package/dist/migration.d.mts +1 -11
- package/dist/migration.d.mts.map +1 -1
- package/dist/migration.mjs +3 -3
- package/dist/{op-factory-call-DxjpXw-A.d.mts → op-factory-call-CdtMyrlU.d.mts} +3 -48
- package/dist/{op-factory-call-DxjpXw-A.d.mts.map → op-factory-call-CdtMyrlU.d.mts.map} +1 -1
- package/dist/{op-factory-call-CHvtj70z.mjs → op-factory-call-CjR846f7.mjs} +4 -159
- package/dist/op-factory-call-CjR846f7.mjs.map +1 -0
- package/dist/op-factory-call.d.mts +2 -2
- package/dist/op-factory-call.mjs +2 -2
- package/dist/pack.d.mts +2 -18
- package/dist/pack.d.mts.map +1 -1
- package/dist/pack.mjs +1 -1
- package/dist/{planner-4FbY_95H.mjs → planner-_FOL4I21.mjs} +9 -41
- package/dist/planner-_FOL4I21.mjs.map +1 -0
- package/dist/{planner-ddl-builders-Cw2n2llW.mjs → planner-ddl-builders-B2wOwLqI.mjs} +2 -2
- package/dist/planner-ddl-builders-B2wOwLqI.mjs.map +1 -0
- package/dist/planner-ddl-builders.d.mts +4 -4
- package/dist/planner-ddl-builders.d.mts.map +1 -1
- package/dist/planner-ddl-builders.mjs +1 -1
- package/dist/{planner-identity-values-BIpa5p2I.mjs → planner-identity-values-CJPha2Sz.mjs} +3 -9
- package/dist/planner-identity-values-CJPha2Sz.mjs.map +1 -0
- package/dist/planner-identity-values.d.mts +1 -1
- package/dist/planner-identity-values.d.mts.map +1 -1
- package/dist/planner-identity-values.mjs +1 -1
- package/dist/{planner-produced-postgres-migration-qfkCkGVe.mjs → planner-produced-postgres-migration-BmCpyWLJ.mjs} +2 -2
- package/dist/{planner-produced-postgres-migration-qfkCkGVe.mjs.map → planner-produced-postgres-migration-BmCpyWLJ.mjs.map} +1 -1
- package/dist/planner-produced-postgres-migration.mjs +1 -1
- package/dist/{planner-sql-checks-BLgdXLsA.mjs → planner-sql-checks-CJJtPfDH.mjs} +3 -3
- package/dist/planner-sql-checks-CJJtPfDH.mjs.map +1 -0
- package/dist/planner-sql-checks.d.mts +2 -2
- package/dist/planner-sql-checks.d.mts.map +1 -1
- package/dist/planner-sql-checks.mjs +1 -1
- package/dist/{planner-type-resolution-836DExFN.mjs → planner-type-resolution-Bt2f_q-F.mjs} +1 -6
- package/dist/planner-type-resolution-Bt2f_q-F.mjs.map +1 -0
- package/dist/planner.d.mts.map +1 -1
- package/dist/planner.mjs +1 -1
- package/dist/{postgres-contract-serializer-CTxVcCVW.mjs → postgres-contract-serializer-CyAe8ZFv.mjs} +12 -29
- package/dist/postgres-contract-serializer-CyAe8ZFv.mjs.map +1 -0
- package/dist/{postgres-migration-DF5ApLqQ.mjs → postgres-migration-dG-J0aI8.mjs} +2 -2
- package/dist/{postgres-migration-DF5ApLqQ.mjs.map → postgres-migration-dG-J0aI8.mjs.map} +1 -1
- package/dist/{postgres-schema-C7c9rhGk.mjs → postgres-schema-CTKYiTHu.mjs} +7 -21
- package/dist/postgres-schema-CTKYiTHu.mjs.map +1 -0
- package/dist/runtime.d.mts +0 -2
- package/dist/runtime.d.mts.map +1 -1
- package/dist/runtime.mjs +2 -2
- package/dist/types.d.mts +5 -25
- package/dist/types.d.mts.map +1 -1
- package/dist/types.mjs +2 -4
- package/package.json +17 -18
- package/src/core/authoring.ts +1 -44
- package/src/core/codec-helpers.ts +0 -17
- package/src/core/codec-ids.ts +0 -1
- package/src/core/codec-type-map.ts +0 -2
- package/src/core/codecs.ts +0 -49
- package/src/core/migrations/control-policy.ts +3 -45
- package/src/core/migrations/issue-planner.ts +9 -52
- package/src/core/migrations/op-factory-call.ts +2 -124
- package/src/core/migrations/planner-ddl-builders.ts +3 -4
- package/src/core/migrations/planner-identity-values.ts +4 -28
- package/src/core/migrations/planner-recipes.ts +2 -6
- package/src/core/migrations/planner-sql-checks.ts +2 -6
- package/src/core/migrations/planner-strategies.ts +13 -353
- package/src/core/migrations/planner-type-resolution.ts +2 -20
- package/src/core/migrations/planner.ts +0 -2
- package/src/core/migrations/runner.ts +0 -4
- package/src/core/postgres-contract-serializer.ts +9 -67
- package/src/core/postgres-schema.ts +6 -37
- package/src/exports/codecs.ts +0 -2
- package/src/exports/control.ts +0 -15
- package/src/exports/migration.ts +0 -6
- package/src/exports/op-factory-call.ts +0 -4
- package/src/exports/types.ts +0 -2
- package/dist/codec-ids-BzrFF-I4.d.mts.map +0 -1
- package/dist/codec-ids-C_-Hj6bL.mjs.map +0 -1
- package/dist/codec-types-B0WT0obB.d.mts.map +0 -1
- package/dist/codecs-CX56Smsj.d.mts.map +0 -1
- package/dist/descriptor-meta-runtime-BToWdas9.mjs.map +0 -1
- package/dist/enum-planning-D8z4FH7y.mjs +0 -129
- package/dist/enum-planning-D8z4FH7y.mjs.map +0 -1
- package/dist/enum-planning.d.mts +0 -92
- package/dist/enum-planning.d.mts.map +0 -1
- package/dist/enum-planning.mjs +0 -2
- package/dist/issue-planner-CK-XWGB0.mjs.map +0 -1
- package/dist/op-factory-call-CHvtj70z.mjs.map +0 -1
- package/dist/planner-4FbY_95H.mjs.map +0 -1
- package/dist/planner-ddl-builders-Cw2n2llW.mjs.map +0 -1
- package/dist/planner-identity-values-BIpa5p2I.mjs.map +0 -1
- package/dist/planner-sql-checks-BLgdXLsA.mjs.map +0 -1
- package/dist/planner-type-resolution-836DExFN.mjs.map +0 -1
- package/dist/postgres-contract-serializer-CTxVcCVW.mjs.map +0 -1
- package/dist/postgres-enum-type-BVn63a89.d.mts +0 -72
- package/dist/postgres-enum-type-BVn63a89.d.mts.map +0 -1
- package/dist/postgres-enum-type-DPKqCBem.mjs +0 -62
- package/dist/postgres-enum-type-DPKqCBem.mjs.map +0 -1
- package/dist/postgres-enum-type-schema-DZBTtvBF.mjs +0 -20
- package/dist/postgres-enum-type-schema-DZBTtvBF.mjs.map +0 -1
- package/dist/postgres-schema-C7c9rhGk.mjs.map +0 -1
- package/src/core/migrations/enum-planning.ts +0 -217
- package/src/core/migrations/operations/enums.ts +0 -114
- package/src/core/postgres-enum-type.ts +0 -89
- package/src/exports/enum-planning.ts +0 -10
|
@@ -19,7 +19,6 @@ import { arraysEqual } from '@prisma-next/family-sql/schema-verify';
|
|
|
19
19
|
import type { TargetBoundComponentDescriptor } from '@prisma-next/framework-components/components';
|
|
20
20
|
import type { SchemaIssue } from '@prisma-next/framework-components/control';
|
|
21
21
|
import type {
|
|
22
|
-
PostgresEnumStorageEntry,
|
|
23
22
|
SqlStorage,
|
|
24
23
|
StorageColumn,
|
|
25
24
|
StorageTable,
|
|
@@ -32,15 +31,12 @@ import { blindCast } from '@prisma-next/utils/casts';
|
|
|
32
31
|
import { ifDefined } from '@prisma-next/utils/defined';
|
|
33
32
|
import type { Result } from '@prisma-next/utils/result';
|
|
34
33
|
import { notOk, ok } from '@prisma-next/utils/result';
|
|
35
|
-
import { PostgresEnumType } from '../postgres-enum-type';
|
|
36
|
-
import { isPostgresSchema } from '../postgres-schema';
|
|
37
34
|
import {
|
|
38
35
|
AddColumnCall,
|
|
39
36
|
AddForeignKeyCall,
|
|
40
37
|
AddPrimaryKeyCall,
|
|
41
38
|
AddUniqueCall,
|
|
42
39
|
AlterColumnTypeCall,
|
|
43
|
-
CreateEnumTypeCall,
|
|
44
40
|
CreateIndexCall,
|
|
45
41
|
CreateSchemaCall,
|
|
46
42
|
CreateTableCall,
|
|
@@ -71,19 +67,6 @@ import { resolveColumnTypeMetadata } from './planner-type-resolution';
|
|
|
71
67
|
|
|
72
68
|
export type { CallMigrationStrategy, StrategyContext };
|
|
73
69
|
|
|
74
|
-
/**
|
|
75
|
-
* Finds a type entry by explicit namespace coordinate. Reads the named
|
|
76
|
-
* namespace's `enum` slot directly — never scans other namespaces.
|
|
77
|
-
*/
|
|
78
|
-
function locateNamespaceTypeInStorage(
|
|
79
|
-
storage: SqlStorage,
|
|
80
|
-
namespaceId: string,
|
|
81
|
-
typeName: string,
|
|
82
|
-
): unknown {
|
|
83
|
-
const ns = storage.namespaces[namespaceId];
|
|
84
|
-
return isPostgresSchema(ns) ? ns.type[typeName] : undefined;
|
|
85
|
-
}
|
|
86
|
-
|
|
87
70
|
// ============================================================================
|
|
88
71
|
// Issue kind ordering (dependency order)
|
|
89
72
|
// ============================================================================
|
|
@@ -168,7 +151,7 @@ export interface IssuePlannerOptions {
|
|
|
168
151
|
readonly fromContract: Contract<SqlStorage> | null;
|
|
169
152
|
readonly schemaName: string;
|
|
170
153
|
readonly codecHooks: ReadonlyMap<string, CodecControlHooks>;
|
|
171
|
-
readonly storageTypes: Readonly<Record<string, StorageTypeInstance
|
|
154
|
+
readonly storageTypes: Readonly<Record<string, StorageTypeInstance>>;
|
|
172
155
|
/**
|
|
173
156
|
* Current database schema IR. Strategies read this to detect whether a
|
|
174
157
|
* structure already exists (e.g. `buildSchemaLookupMap` for shared-temp-
|
|
@@ -199,13 +182,13 @@ function toDdlColumn(
|
|
|
199
182
|
name: string,
|
|
200
183
|
column: StorageColumn,
|
|
201
184
|
codecHooks: ReadonlyMap<string, CodecControlHooks>,
|
|
202
|
-
storageTypes: Readonly<Record<string, StorageTypeInstance
|
|
185
|
+
storageTypes: Readonly<Record<string, StorageTypeInstance>>,
|
|
203
186
|
): DdlColumn {
|
|
204
187
|
const typeSql = buildColumnTypeSql(column, codecHooks, storageTypes);
|
|
205
188
|
const ddlDefault = postgresDefaultToDdlColumnDefault(column.default);
|
|
206
189
|
const resolved = resolveColumnTypeMetadata(
|
|
207
190
|
column,
|
|
208
|
-
storageTypes as Record<string, StorageTypeInstance
|
|
191
|
+
storageTypes as Record<string, StorageTypeInstance>,
|
|
209
192
|
);
|
|
210
193
|
const codecRef: CodecRef | undefined = resolved.codecId
|
|
211
194
|
? {
|
|
@@ -482,10 +465,7 @@ function mapIssueToCall(
|
|
|
482
465
|
),
|
|
483
466
|
);
|
|
484
467
|
const hooksMap = codecHooks as Map<string, CodecControlHooks>;
|
|
485
|
-
const typesMap = storageTypes as Record<
|
|
486
|
-
string,
|
|
487
|
-
StorageTypeInstance | PostgresEnumStorageEntry
|
|
488
|
-
>;
|
|
468
|
+
const typesMap = storageTypes as Record<string, StorageTypeInstance>;
|
|
489
469
|
const qualifiedTargetType = buildColumnTypeSql(column, hooksMap, typesMap, false);
|
|
490
470
|
const formatTypeExpected = buildExpectedFormatType(column, hooksMap, typesMap);
|
|
491
471
|
return ok([
|
|
@@ -673,14 +653,7 @@ function mapIssueToCall(
|
|
|
673
653
|
case 'type_missing': {
|
|
674
654
|
if (!issue.typeName)
|
|
675
655
|
return notOk(issueConflict('unsupportedOperation', 'Type missing issue has no typeName'));
|
|
676
|
-
|
|
677
|
-
// Check types first; fall back to the namespace-keyed enum slot using the
|
|
678
|
-
// issue's namespace coordinate (populated by the verifier for enum-related
|
|
679
|
-
// issues per the BaseSchemaIssue.namespaceId contract).
|
|
680
|
-
const namespaceId = resolveNamespaceIdForIssue(issue);
|
|
681
|
-
const typeInstance: unknown =
|
|
682
|
-
ctx.toContract.storage.types?.[issue.typeName] ??
|
|
683
|
-
locateNamespaceTypeInStorage(ctx.toContract.storage, namespaceId, issue.typeName);
|
|
656
|
+
const typeInstance = ctx.toContract.storage.types?.[issue.typeName];
|
|
684
657
|
if (!typeInstance) {
|
|
685
658
|
return notOk(
|
|
686
659
|
issueConflict(
|
|
@@ -689,22 +662,10 @@ function mapIssueToCall(
|
|
|
689
662
|
),
|
|
690
663
|
);
|
|
691
664
|
}
|
|
692
|
-
if (typeInstance instanceof PostgresEnumType) {
|
|
693
|
-
const ddlSchema = resolveDdlSchemaForNamespace(ctx, namespaceId);
|
|
694
|
-
return ok([
|
|
695
|
-
new CreateEnumTypeCall(
|
|
696
|
-
ddlSchema,
|
|
697
|
-
issue.typeName,
|
|
698
|
-
typeInstance.values,
|
|
699
|
-
typeInstance.nativeType,
|
|
700
|
-
),
|
|
701
|
-
]);
|
|
702
|
-
}
|
|
703
|
-
const codecInstance = typeInstance as StorageTypeInstance;
|
|
704
665
|
return notOk(
|
|
705
666
|
issueConflict(
|
|
706
667
|
'unsupportedOperation',
|
|
707
|
-
`Type "${issue.typeName}" uses codec "${
|
|
668
|
+
`Type "${issue.typeName}" uses codec "${typeInstance.codecId}" — only value-set types are supported`,
|
|
708
669
|
),
|
|
709
670
|
);
|
|
710
671
|
}
|
|
@@ -751,10 +712,6 @@ function classifyCall(call: PostgresOpFactoryCall): CallCategory {
|
|
|
751
712
|
switch (call.factoryName) {
|
|
752
713
|
case 'createExtension':
|
|
753
714
|
case 'createSchema':
|
|
754
|
-
case 'createEnumType':
|
|
755
|
-
case 'addEnumValues':
|
|
756
|
-
case 'dropEnumType':
|
|
757
|
-
case 'renameType':
|
|
758
715
|
return 'dep';
|
|
759
716
|
case 'dropTable':
|
|
760
717
|
case 'dropColumn':
|
|
@@ -978,10 +935,10 @@ export function planIssues(
|
|
|
978
935
|
return notOk(conflicts);
|
|
979
936
|
}
|
|
980
937
|
|
|
981
|
-
// Recipe strategies (`
|
|
982
|
-
// `
|
|
938
|
+
// Recipe strategies (`notNullBackfillCallStrategy`,
|
|
939
|
+
// `nullableTighteningCallStrategy`, etc.) emit a cohesive sequence that must
|
|
983
940
|
// stay contiguous. They are inserted at a single pattern slot. Non-recipe
|
|
984
|
-
// pattern strategies (`
|
|
941
|
+
// pattern strategies (`checkConstraintPlanCallStrategy`,
|
|
985
942
|
// `storageTypePlanCallStrategy`, `notNullAddColumnCallStrategy`) produce
|
|
986
943
|
// individually classifiable calls that slot into DDL buckets alongside
|
|
987
944
|
// default-mapped calls.
|
|
@@ -57,7 +57,6 @@ import {
|
|
|
57
57
|
dropConstraint,
|
|
58
58
|
} from './operations/constraints';
|
|
59
59
|
import { createExtension } from './operations/dependencies';
|
|
60
|
-
import { addEnumValues, createEnumType, dropEnumType, renameType } from './operations/enums';
|
|
61
60
|
import { createIndex, dropIndex } from './operations/indexes';
|
|
62
61
|
import type { ForeignKeySpec } from './operations/shared';
|
|
63
62
|
import { step, targetDetails } from './operations/shared';
|
|
@@ -809,8 +808,8 @@ export class CreateIndexCall extends PostgresOpFactoryCallNode {
|
|
|
809
808
|
readonly tableName: string;
|
|
810
809
|
readonly indexName: string;
|
|
811
810
|
readonly columns: readonly string[];
|
|
812
|
-
// Named indexType (not typeName)
|
|
813
|
-
//
|
|
811
|
+
// Named indexType (not typeName): `locationForCall` in issue-planner.ts reads
|
|
812
|
+
// a call's `typeName` as a CREATE TYPE target location, which an index is not.
|
|
814
813
|
readonly indexType: string | undefined;
|
|
815
814
|
readonly options: Record<string, unknown> | undefined;
|
|
816
815
|
readonly label: string;
|
|
@@ -883,123 +882,6 @@ export class DropIndexCall extends PostgresOpFactoryCallNode {
|
|
|
883
882
|
}
|
|
884
883
|
}
|
|
885
884
|
|
|
886
|
-
// ============================================================================
|
|
887
|
-
// Enum types
|
|
888
|
-
// ============================================================================
|
|
889
|
-
|
|
890
|
-
export class CreateEnumTypeCall extends PostgresOpFactoryCallNode {
|
|
891
|
-
readonly factoryName = 'createEnumType' as const;
|
|
892
|
-
readonly operationClass = 'additive' as const;
|
|
893
|
-
readonly schemaName: string;
|
|
894
|
-
readonly typeName: string;
|
|
895
|
-
readonly nativeType: string;
|
|
896
|
-
readonly values: readonly string[];
|
|
897
|
-
readonly label: string;
|
|
898
|
-
|
|
899
|
-
constructor(
|
|
900
|
-
schemaName: string,
|
|
901
|
-
typeName: string,
|
|
902
|
-
values: readonly string[],
|
|
903
|
-
nativeType: string = typeName,
|
|
904
|
-
) {
|
|
905
|
-
super();
|
|
906
|
-
this.schemaName = schemaName;
|
|
907
|
-
this.typeName = typeName;
|
|
908
|
-
this.nativeType = nativeType;
|
|
909
|
-
this.values = values;
|
|
910
|
-
this.label = `Create enum type "${typeName}"`;
|
|
911
|
-
this.freeze();
|
|
912
|
-
}
|
|
913
|
-
|
|
914
|
-
toOp(): Op {
|
|
915
|
-
return createEnumType(this.schemaName, this.typeName, this.values, this.nativeType);
|
|
916
|
-
}
|
|
917
|
-
|
|
918
|
-
renderTypeScript(): string {
|
|
919
|
-
const nativeArg =
|
|
920
|
-
this.nativeType === this.typeName ? '' : `, ${jsonToTsSource(this.nativeType)}`;
|
|
921
|
-
return `createEnumType(${jsonToTsSource(this.schemaName)}, ${jsonToTsSource(this.typeName)}, ${jsonToTsSource(this.values)}${nativeArg})`;
|
|
922
|
-
}
|
|
923
|
-
}
|
|
924
|
-
|
|
925
|
-
export class AddEnumValuesCall extends PostgresOpFactoryCallNode {
|
|
926
|
-
readonly factoryName = 'addEnumValues' as const;
|
|
927
|
-
readonly operationClass = 'additive' as const;
|
|
928
|
-
readonly schemaName: string;
|
|
929
|
-
readonly typeName: string;
|
|
930
|
-
readonly nativeType: string;
|
|
931
|
-
readonly values: readonly string[];
|
|
932
|
-
readonly label: string;
|
|
933
|
-
|
|
934
|
-
constructor(schemaName: string, typeName: string, nativeType: string, values: readonly string[]) {
|
|
935
|
-
super();
|
|
936
|
-
this.schemaName = schemaName;
|
|
937
|
-
this.typeName = typeName;
|
|
938
|
-
this.nativeType = nativeType;
|
|
939
|
-
this.values = values;
|
|
940
|
-
this.label = `Add values to enum type "${typeName}": ${values.join(', ')}`;
|
|
941
|
-
this.freeze();
|
|
942
|
-
}
|
|
943
|
-
|
|
944
|
-
toOp(): Op {
|
|
945
|
-
return addEnumValues(this.schemaName, this.typeName, this.nativeType, this.values);
|
|
946
|
-
}
|
|
947
|
-
|
|
948
|
-
renderTypeScript(): string {
|
|
949
|
-
return `addEnumValues(${jsonToTsSource(this.schemaName)}, ${jsonToTsSource(this.typeName)}, ${jsonToTsSource(this.nativeType)}, ${jsonToTsSource(this.values)})`;
|
|
950
|
-
}
|
|
951
|
-
}
|
|
952
|
-
|
|
953
|
-
export class DropEnumTypeCall extends PostgresOpFactoryCallNode {
|
|
954
|
-
readonly factoryName = 'dropEnumType' as const;
|
|
955
|
-
readonly operationClass = 'destructive' as const;
|
|
956
|
-
readonly schemaName: string;
|
|
957
|
-
readonly typeName: string;
|
|
958
|
-
readonly label: string;
|
|
959
|
-
|
|
960
|
-
constructor(schemaName: string, typeName: string) {
|
|
961
|
-
super();
|
|
962
|
-
this.schemaName = schemaName;
|
|
963
|
-
this.typeName = typeName;
|
|
964
|
-
this.label = `Drop enum type "${typeName}"`;
|
|
965
|
-
this.freeze();
|
|
966
|
-
}
|
|
967
|
-
|
|
968
|
-
toOp(): Op {
|
|
969
|
-
return dropEnumType(this.schemaName, this.typeName);
|
|
970
|
-
}
|
|
971
|
-
|
|
972
|
-
renderTypeScript(): string {
|
|
973
|
-
return `dropEnumType(${jsonToTsSource(this.schemaName)}, ${jsonToTsSource(this.typeName)})`;
|
|
974
|
-
}
|
|
975
|
-
}
|
|
976
|
-
|
|
977
|
-
export class RenameTypeCall extends PostgresOpFactoryCallNode {
|
|
978
|
-
readonly factoryName = 'renameType' as const;
|
|
979
|
-
readonly operationClass = 'destructive' as const;
|
|
980
|
-
readonly schemaName: string;
|
|
981
|
-
readonly fromName: string;
|
|
982
|
-
readonly toName: string;
|
|
983
|
-
readonly label: string;
|
|
984
|
-
|
|
985
|
-
constructor(schemaName: string, fromName: string, toName: string) {
|
|
986
|
-
super();
|
|
987
|
-
this.schemaName = schemaName;
|
|
988
|
-
this.fromName = fromName;
|
|
989
|
-
this.toName = toName;
|
|
990
|
-
this.label = `Rename type "${fromName}" to "${toName}"`;
|
|
991
|
-
this.freeze();
|
|
992
|
-
}
|
|
993
|
-
|
|
994
|
-
toOp(): Op {
|
|
995
|
-
return renameType(this.schemaName, this.fromName, this.toName);
|
|
996
|
-
}
|
|
997
|
-
|
|
998
|
-
renderTypeScript(): string {
|
|
999
|
-
return `renameType(${jsonToTsSource(this.schemaName)}, ${jsonToTsSource(this.fromName)}, ${jsonToTsSource(this.toName)})`;
|
|
1000
|
-
}
|
|
1001
|
-
}
|
|
1002
|
-
|
|
1003
885
|
// ============================================================================
|
|
1004
886
|
// Raw SQL
|
|
1005
887
|
// ============================================================================
|
|
@@ -1190,10 +1072,6 @@ export type PostgresOpFactoryCall =
|
|
|
1190
1072
|
| CreateIndexCall
|
|
1191
1073
|
| DropIndexCall
|
|
1192
1074
|
| DropConstraintCall
|
|
1193
|
-
| CreateEnumTypeCall
|
|
1194
|
-
| AddEnumValuesCall
|
|
1195
|
-
| DropEnumTypeCall
|
|
1196
|
-
| RenameTypeCall
|
|
1197
1075
|
| RawSqlCall
|
|
1198
1076
|
| CreateExtensionCall
|
|
1199
1077
|
| CreateSchemaCall
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import type { CodecControlHooks } from '@prisma-next/family-sql/control';
|
|
2
2
|
import type {
|
|
3
|
-
PostgresEnumStorageEntry,
|
|
4
3
|
StorageColumn,
|
|
5
4
|
StorageTable,
|
|
6
5
|
StorageTypeInstance,
|
|
@@ -14,7 +13,7 @@ export function buildCreateTableSql(
|
|
|
14
13
|
qualifiedTableName: string,
|
|
15
14
|
table: StorageTable,
|
|
16
15
|
codecHooks: ReadonlyMap<string, CodecControlHooks>,
|
|
17
|
-
storageTypes: Record<string, StorageTypeInstance
|
|
16
|
+
storageTypes: Record<string, StorageTypeInstance> = {},
|
|
18
17
|
): string {
|
|
19
18
|
const columnDefinitions = Object.entries(table.columns).map(
|
|
20
19
|
([columnName, column]: [string, StorageColumn]) => {
|
|
@@ -79,7 +78,7 @@ function assertSafeDefaultExpression(expression: string): void {
|
|
|
79
78
|
export function buildColumnTypeSql(
|
|
80
79
|
column: StorageColumn,
|
|
81
80
|
codecHooks: ReadonlyMap<string, CodecControlHooks>,
|
|
82
|
-
storageTypes: Record<string, StorageTypeInstance
|
|
81
|
+
storageTypes: Record<string, StorageTypeInstance> = {},
|
|
83
82
|
allowPseudoTypes = true,
|
|
84
83
|
): string {
|
|
85
84
|
const resolved = resolveColumnTypeMetadata(column, storageTypes);
|
|
@@ -200,7 +199,7 @@ export function buildAddColumnSql(
|
|
|
200
199
|
column: StorageColumn,
|
|
201
200
|
codecHooks: ReadonlyMap<string, CodecControlHooks>,
|
|
202
201
|
temporaryDefault?: string | null,
|
|
203
|
-
storageTypes: Record<string, StorageTypeInstance
|
|
202
|
+
storageTypes: Record<string, StorageTypeInstance> = {},
|
|
204
203
|
): string {
|
|
205
204
|
const typeSql = buildColumnTypeSql(column, codecHooks, storageTypes);
|
|
206
205
|
const defaultSql =
|
|
@@ -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
|
|
13
|
+
storageTypes: Record<string, StorageTypeInstance> = {},
|
|
20
14
|
): string | null {
|
|
21
15
|
const referencedType = column.typeRef ? storageTypes[column.typeRef] : undefined;
|
|
22
|
-
const
|
|
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?.({
|
|
@@ -1,9 +1,5 @@
|
|
|
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 { StorageColumn, StorageTypeInstance } from '@prisma-next/sql-contract/types';
|
|
7
3
|
import { quoteIdentifier } from '../sql-utils';
|
|
8
4
|
import { buildAddColumnSql } from './planner-ddl-builders';
|
|
9
5
|
import {
|
|
@@ -39,7 +35,7 @@ export function buildAddNotNullColumnWithTemporaryDefaultOperation(options: {
|
|
|
39
35
|
readonly columnName: string;
|
|
40
36
|
readonly column: StorageColumn;
|
|
41
37
|
readonly codecHooks: Map<string, CodecControlHooks>;
|
|
42
|
-
readonly storageTypes: Record<string, StorageTypeInstance
|
|
38
|
+
readonly storageTypes: Record<string, StorageTypeInstance>;
|
|
43
39
|
readonly temporaryDefault: string;
|
|
44
40
|
}): SqlMigrationPlanOperation<PostgresPlanTargetDetails> {
|
|
45
41
|
const { schema, tableName, columnName, column, codecHooks, storageTypes, temporaryDefault } =
|
|
@@ -1,9 +1,5 @@
|
|
|
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
4
|
import { escapeLiteral, quoteIdentifier } from '../sql-utils';
|
|
9
5
|
import { resolveColumnTypeMetadata } from './planner-type-resolution';
|
|
@@ -249,7 +245,7 @@ function formatUserDefinedTypeName(identifier: string): string {
|
|
|
249
245
|
export function buildExpectedFormatType(
|
|
250
246
|
column: StorageColumn,
|
|
251
247
|
codecHooks: Map<string, CodecControlHooks>,
|
|
252
|
-
storageTypes: Record<string, StorageTypeInstance
|
|
248
|
+
storageTypes: Record<string, StorageTypeInstance> = {},
|
|
253
249
|
): string {
|
|
254
250
|
const resolved = resolveColumnTypeMetadata(column, storageTypes);
|
|
255
251
|
|