@prisma-next/target-postgres 0.14.0-dev.7 → 0.14.0-dev.71
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/authoring-Bi9aa8zG.mjs +574 -0
- package/dist/authoring-Bi9aa8zG.mjs.map +1 -0
- package/dist/canonicalize-CAbXtVtB.d.mts +37 -0
- package/dist/canonicalize-CAbXtVtB.d.mts.map +1 -0
- package/dist/{codec-ids-CnXu9Qy3.d.mts → codec-ids-BzrFF-I4.d.mts} +3 -2
- package/dist/codec-ids-BzrFF-I4.d.mts.map +1 -0
- package/dist/{codec-ids-BvytN2P8.mjs → codec-ids-C_-Hj6bL.mjs} +3 -2
- package/dist/codec-ids-C_-Hj6bL.mjs.map +1 -0
- package/dist/codec-ids.d.mts +2 -2
- package/dist/codec-ids.mjs +2 -2
- package/dist/{codec-types-DHCkwPKE.d.mts → codec-types-BiIWziRO.d.mts} +3 -2
- package/dist/codec-types-BiIWziRO.d.mts.map +1 -0
- package/dist/codec-types.d.mts +1 -1
- package/dist/codecs-Cl_hQHg-.mjs +913 -0
- package/dist/codecs-Cl_hQHg-.mjs.map +1 -0
- package/dist/{codecs--0A5_4Bq.d.mts → codecs-Cm-nS4mQ.d.mts} +111 -4
- package/dist/codecs-Cm-nS4mQ.d.mts.map +1 -0
- package/dist/codecs.d.mts +2 -2
- package/dist/codecs.mjs +3 -757
- package/dist/codecs.mjs.map +1 -1
- package/dist/contract-free.d.mts +33 -3
- package/dist/contract-free.d.mts.map +1 -1
- package/dist/contract-free.mjs +23 -7
- package/dist/contract-free.mjs.map +1 -1
- package/dist/control-policy-CuUhjWnn.mjs +1258 -0
- package/dist/control-policy-CuUhjWnn.mjs.map +1 -0
- package/dist/control.d.mts +2 -2
- package/dist/control.d.mts.map +1 -1
- package/dist/control.mjs +866 -36
- package/dist/control.mjs.map +1 -1
- package/dist/data-transform-BOWpliq8.mjs.map +1 -1
- package/dist/{data-transform-DDgWdB5o.d.mts → data-transform-DPzwBMhW.d.mts} +3 -3
- package/dist/{data-transform-DDgWdB5o.d.mts.map → data-transform-DPzwBMhW.d.mts.map} +1 -1
- package/dist/data-transform.d.mts +1 -1
- package/dist/{ddl-QDyOSeLc.mjs → ddl-Dqgs-bDc.mjs} +93 -6
- package/dist/ddl-Dqgs-bDc.mjs.map +1 -0
- package/dist/ddl.d.mts +3 -2
- package/dist/ddl.mjs +2 -2
- package/dist/default-normalizer.d.mts +1 -1
- package/dist/default-normalizer.d.mts.map +1 -1
- package/dist/default-normalizer.mjs +247 -1
- package/dist/default-normalizer.mjs.map +1 -0
- package/dist/descriptor-meta-UugzVM-U.mjs +22 -0
- package/dist/descriptor-meta-UugzVM-U.mjs.map +1 -0
- package/dist/descriptor-meta-runtime-UwYdV8fD.mjs +12 -0
- package/dist/descriptor-meta-runtime-UwYdV8fD.mjs.map +1 -0
- package/dist/diff-database-schema-ClN3bkRS.mjs +305 -0
- package/dist/diff-database-schema-ClN3bkRS.mjs.map +1 -0
- package/dist/diff-database-schema.d.mts +46 -0
- package/dist/diff-database-schema.d.mts.map +1 -0
- package/dist/diff-database-schema.mjs +2 -0
- package/dist/errors-DO-w0EUS.mjs +35 -0
- package/dist/errors-DO-w0EUS.mjs.map +1 -0
- package/dist/errors.d.mts +11 -9
- package/dist/errors.d.mts.map +1 -1
- package/dist/errors.mjs +1 -1
- package/dist/issue-planner.d.mts +35 -11
- package/dist/issue-planner.d.mts.map +1 -1
- package/dist/issue-planner.mjs +2 -2
- package/dist/migration.d.mts +5 -5
- package/dist/migration.d.mts.map +1 -1
- package/dist/migration.mjs +4 -4
- package/dist/namespace-ids-xtp_ZY86.mjs +7 -0
- package/dist/namespace-ids-xtp_ZY86.mjs.map +1 -0
- package/dist/native-type-normalizer.mjs +37 -1
- package/dist/native-type-normalizer.mjs.map +1 -0
- package/dist/nodes-Bc2N3tMy.d.mts +170 -0
- package/dist/nodes-Bc2N3tMy.d.mts.map +1 -0
- package/dist/nodes-DJC5B8Id.mjs +192 -0
- package/dist/nodes-DJC5B8Id.mjs.map +1 -0
- package/dist/{op-factory-call-DmQEc3XV.d.mts → op-factory-call-CSIg5XDu.d.mts} +91 -15
- package/dist/op-factory-call-CSIg5XDu.d.mts.map +1 -0
- package/dist/{op-factory-call-D_p5vxwt.mjs → op-factory-call-DtVSP_7Y.mjs} +400 -32
- package/dist/op-factory-call-DtVSP_7Y.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 +300 -3
- package/dist/pack.d.mts.map +1 -1
- package/dist/pack.mjs +1 -1
- package/dist/planner-ChVasl04.mjs +390 -0
- package/dist/planner-ChVasl04.mjs.map +1 -0
- package/dist/{planner-ddl-builders-B2wOwLqI.mjs → planner-ddl-builders-BKlmGDJl.mjs} +17 -28
- package/dist/planner-ddl-builders-BKlmGDJl.mjs.map +1 -0
- package/dist/planner-ddl-builders.d.mts +4 -6
- package/dist/planner-ddl-builders.d.mts.map +1 -1
- package/dist/planner-ddl-builders.mjs +2 -2
- package/dist/planner-identity-values-CJPha2Sz.mjs.map +1 -1
- package/dist/planner-identity-values.d.mts +8 -2
- package/dist/planner-identity-values.d.mts.map +1 -1
- package/dist/planner-identity-values.mjs +2 -2
- package/dist/{planner-produced-postgres-migration-QqHa2C2l.d.mts → planner-produced-postgres-migration-CXue-6M9.d.mts} +4 -4
- package/dist/{planner-produced-postgres-migration-QqHa2C2l.d.mts.map → planner-produced-postgres-migration-CXue-6M9.d.mts.map} +1 -1
- package/dist/{planner-produced-postgres-migration-Cji5vxUf.mjs → planner-produced-postgres-migration-qpU05c__.mjs} +3 -3
- package/dist/{planner-produced-postgres-migration-Cji5vxUf.mjs.map → planner-produced-postgres-migration-qpU05c__.mjs.map} +1 -1
- package/dist/planner-produced-postgres-migration.d.mts +1 -1
- package/dist/planner-produced-postgres-migration.mjs +1 -1
- package/dist/{planner-sql-checks-jqUUGyQR.mjs → planner-sql-checks-CDXn2uaS.mjs} +5 -5
- package/dist/{planner-sql-checks-jqUUGyQR.mjs.map → planner-sql-checks-CDXn2uaS.mjs.map} +1 -1
- 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-target-details-CIY6tLeo.d.mts → planner-target-details-HkP4RrRO.d.mts} +2 -2
- package/dist/planner-target-details-HkP4RrRO.d.mts.map +1 -0
- package/dist/planner-target-details.d.mts +1 -1
- package/dist/planner.d.mts +72 -17
- package/dist/planner.d.mts.map +1 -1
- package/dist/planner.mjs +3 -2
- package/dist/{postgres-contract-serializer-k3TAcPMY.mjs → postgres-contract-view-C3LPCLP_.mjs} +45 -41
- package/dist/postgres-contract-view-C3LPCLP_.mjs.map +1 -0
- package/dist/postgres-contract-view-C9j5cqP0.d.mts +34 -0
- package/dist/postgres-contract-view-C9j5cqP0.d.mts.map +1 -0
- package/dist/postgres-database-schema-node-CJv5bfbs.d.mts +262 -0
- package/dist/postgres-database-schema-node-CJv5bfbs.d.mts.map +1 -0
- package/dist/{postgres-migration-Y4YBJqkS.d.mts → postgres-migration-DkmgGNcv.d.mts} +47 -9
- package/dist/postgres-migration-DkmgGNcv.d.mts.map +1 -0
- package/dist/{postgres-migration-B5jKrXv3.mjs → postgres-migration-fndp3Mbm.mjs} +69 -45
- package/dist/postgres-migration-fndp3Mbm.mjs.map +1 -0
- package/dist/postgres-native-enum-BwVNf0Ku.mjs +45 -0
- package/dist/postgres-native-enum-BwVNf0Ku.mjs.map +1 -0
- package/dist/postgres-rls-policy--CSddvMR.d.mts +52 -0
- package/dist/postgres-rls-policy--CSddvMR.d.mts.map +1 -0
- package/dist/postgres-role-schema-node-Cm-j0ZGM.mjs +190 -0
- package/dist/postgres-role-schema-node-Cm-j0ZGM.mjs.map +1 -0
- package/dist/postgres-schema-DKq6s1P3.d.mts +269 -0
- package/dist/postgres-schema-DKq6s1P3.d.mts.map +1 -0
- package/dist/{postgres-schema-COGZ1ark.mjs → postgres-schema-DYATroNx.mjs} +200 -11
- package/dist/postgres-schema-DYATroNx.mjs.map +1 -0
- package/dist/postgres-table-schema-node-D6LvInCe.mjs +216 -0
- package/dist/postgres-table-schema-node-D6LvInCe.mjs.map +1 -0
- package/dist/render-ops.d.mts +1 -1
- package/dist/{render-typescript-KMgosran.mjs → render-typescript-7yqILcwr.mjs} +45 -16
- package/dist/render-typescript-7yqILcwr.mjs.map +1 -0
- package/dist/render-typescript.mjs +1 -1
- package/dist/resolve-ddl-schema-DpGte50u.mjs +22 -0
- package/dist/resolve-ddl-schema-DpGte50u.mjs.map +1 -0
- package/dist/rls-canonicalize.d.mts +20 -0
- package/dist/rls-canonicalize.d.mts.map +1 -0
- package/dist/rls-canonicalize.mjs +2 -0
- package/dist/runtime.d.mts +6 -8
- package/dist/runtime.d.mts.map +1 -1
- package/dist/runtime.mjs +3 -3
- package/dist/runtime.mjs.map +1 -1
- package/dist/schema-ir-annotations.d.mts +15 -0
- package/dist/schema-ir-annotations.d.mts.map +1 -0
- package/dist/schema-ir-annotations.mjs +2 -0
- package/dist/{sql-utils-DcfMz4MQ.mjs → sql-utils-SU4FDvIV.mjs} +12 -3
- package/dist/{sql-utils-DcfMz4MQ.mjs.map → sql-utils-SU4FDvIV.mjs.map} +1 -1
- package/dist/sql-utils.d.mts +8 -1
- package/dist/sql-utils.d.mts.map +1 -1
- package/dist/sql-utils.mjs +2 -2
- package/dist/types.d.mts +4 -140
- package/dist/types.mjs +5 -2
- package/dist/wire-name-rHHtr1h0.mjs +75 -0
- package/dist/wire-name-rHHtr1h0.mjs.map +1 -0
- package/package.json +26 -20
- package/src/contract-free/checks.ts +73 -0
- package/src/contract-free/control-bootstrap.ts +20 -3
- package/src/contract-free/ddl.ts +98 -1
- package/src/core/authoring.ts +509 -2
- package/src/core/codec-ids.ts +1 -0
- package/src/core/codec-type-map.ts +2 -0
- package/src/core/codecs.ts +180 -1
- package/src/core/ddl/nodes.ts +185 -2
- package/src/core/default-normalizer.ts +122 -2
- package/src/core/descriptor-meta.ts +10 -1
- package/src/core/entity-kinds.ts +41 -0
- package/src/core/errors.ts +14 -12
- package/src/core/migrations/bound-schema.ts +10 -0
- package/src/core/migrations/column-ddl-rendering.ts +117 -0
- package/src/core/migrations/contract-to-postgres-database-schema-node.ts +189 -0
- package/src/core/migrations/control-policy.ts +217 -65
- package/src/core/migrations/diff-database-schema.ts +252 -0
- package/src/core/migrations/issue-planner.ts +769 -656
- package/src/core/migrations/op-factory-call.ts +273 -21
- package/src/core/migrations/operations/columns.ts +24 -12
- package/src/core/migrations/operations/constraints.ts +1 -1
- package/src/core/migrations/operations/data-transform.ts +6 -0
- package/src/core/migrations/operations/dependencies.ts +2 -1
- package/src/core/migrations/operations/native-enum-types.ts +62 -0
- package/src/core/migrations/operations/rls.ts +187 -0
- package/src/core/migrations/operations/shared.ts +0 -30
- package/src/core/migrations/planner-ddl-builders.ts +31 -59
- package/src/core/migrations/planner-identity-values.ts +1 -1
- package/src/core/migrations/planner-recipes.ts +31 -13
- package/src/core/migrations/planner-sql-checks.ts +1 -1
- package/src/core/migrations/planner-strategies.ts +248 -216
- package/src/core/migrations/planner-target-details.ts +3 -1
- package/src/core/migrations/planner.ts +357 -67
- package/src/core/migrations/postgres-migration.ts +101 -86
- package/src/core/migrations/render-typescript.ts +42 -15
- package/src/core/migrations/resolve-ddl-schema.ts +26 -0
- package/src/core/migrations/runner.ts +11 -16
- package/src/core/migrations/verify-postgres-namespaces.ts +46 -31
- package/src/core/namespace-ids.ts +3 -0
- package/src/core/postgres-contract-serializer.ts +46 -71
- package/src/core/postgres-contract-view.ts +48 -0
- package/src/core/postgres-native-enum.ts +61 -0
- package/src/core/postgres-rls-enablement.ts +34 -0
- package/src/core/postgres-rls-policy.ts +64 -0
- package/src/core/postgres-role.ts +59 -0
- package/src/core/postgres-schema-verifier.ts +10 -7
- package/src/core/postgres-schema.ts +85 -15
- package/src/core/postgres-validators.ts +34 -0
- package/src/core/psl-infer/infer-psl-contract.ts +1273 -0
- package/src/core/psl-infer/postgres-default-mapping.ts +16 -0
- package/src/core/psl-infer/postgres-type-map.ts +128 -0
- package/src/core/rls/canonicalize.ts +48 -0
- package/src/core/rls/wire-name.ts +33 -0
- package/src/core/schema-ir/node-storage-coordinate.ts +26 -0
- package/src/core/schema-ir/postgres-database-schema-node.ts +61 -0
- package/src/core/schema-ir/postgres-namespace-schema-node.ts +70 -0
- package/src/core/schema-ir/postgres-native-enum-schema-node.ts +83 -0
- package/src/core/schema-ir/postgres-policy-schema-node.ts +90 -0
- package/src/core/schema-ir/postgres-role-schema-node.ts +65 -0
- package/src/core/schema-ir/postgres-table-schema-node.ts +140 -0
- package/src/core/schema-ir/schema-node-kinds.ts +122 -0
- package/src/core/sql-utils.ts +15 -2
- package/src/exports/codecs.ts +3 -0
- package/src/exports/contract-free.ts +11 -1
- package/src/exports/control.ts +27 -33
- package/src/exports/ddl.ts +8 -0
- package/src/exports/diff-database-schema.ts +7 -0
- package/src/exports/issue-planner.ts +1 -1
- package/src/exports/migration.ts +1 -0
- package/src/exports/op-factory-call.ts +3 -0
- package/src/exports/planner-ddl-builders.ts +0 -2
- package/src/exports/planner-identity-values.ts +4 -1
- package/src/exports/planner.ts +1 -0
- package/src/exports/rls-canonicalize.ts +7 -0
- package/src/exports/runtime.ts +1 -0
- package/src/exports/schema-ir-annotations.ts +1 -0
- package/src/exports/sql-utils.ts +1 -0
- package/src/exports/types.ts +37 -0
- package/dist/codec-ids-BvytN2P8.mjs.map +0 -1
- package/dist/codec-ids-CnXu9Qy3.d.mts.map +0 -1
- package/dist/codec-types-DHCkwPKE.d.mts.map +0 -1
- package/dist/codecs--0A5_4Bq.d.mts.map +0 -1
- package/dist/ddl-QDyOSeLc.mjs.map +0 -1
- package/dist/default-normalizer-DyyCHQWs.mjs +0 -131
- package/dist/default-normalizer-DyyCHQWs.mjs.map +0 -1
- package/dist/descriptor-meta-CpGygXpI.mjs +0 -140
- package/dist/descriptor-meta-CpGygXpI.mjs.map +0 -1
- package/dist/errors-CUk87ByX.mjs +0 -33
- package/dist/errors-CUk87ByX.mjs.map +0 -1
- package/dist/issue-planner-DL6g3CmE.mjs +0 -824
- package/dist/issue-planner-DL6g3CmE.mjs.map +0 -1
- package/dist/native-type-normalizer-Bc9XJzWC.mjs +0 -38
- package/dist/native-type-normalizer-Bc9XJzWC.mjs.map +0 -1
- package/dist/nodes-Bbhs2rwj.mjs +0 -76
- package/dist/nodes-Bbhs2rwj.mjs.map +0 -1
- package/dist/nodes-pLeLgdis.d.mts +0 -67
- package/dist/nodes-pLeLgdis.d.mts.map +0 -1
- package/dist/op-factory-call-D_p5vxwt.mjs.map +0 -1
- package/dist/op-factory-call-DmQEc3XV.d.mts.map +0 -1
- package/dist/planner-Bs_baQax.mjs +0 -324
- package/dist/planner-Bs_baQax.mjs.map +0 -1
- package/dist/planner-ddl-builders-B2wOwLqI.mjs.map +0 -1
- package/dist/planner-target-details-CIY6tLeo.d.mts.map +0 -1
- package/dist/postgres-contract-serializer-k3TAcPMY.mjs.map +0 -1
- package/dist/postgres-migration-B5jKrXv3.mjs.map +0 -1
- package/dist/postgres-migration-Y4YBJqkS.d.mts.map +0 -1
- package/dist/postgres-schema-COGZ1ark.mjs.map +0 -1
- package/dist/render-typescript-KMgosran.mjs.map +0 -1
- package/dist/types.d.mts.map +0 -1
- package/src/core/postgres-enum-type-schema.ts +0 -17
|
@@ -3,9 +3,11 @@ import type { SqlMigrationPlanOperation } from '@prisma-next/family-sql/control'
|
|
|
3
3
|
import type { SqlControlAdapter } from '@prisma-next/family-sql/control-adapter';
|
|
4
4
|
import { Migration as SqlMigration } from '@prisma-next/family-sql/migration';
|
|
5
5
|
import type { ControlStack } from '@prisma-next/framework-components/control';
|
|
6
|
+
import { MigrationContractViews } from '@prisma-next/migration-tools/migration';
|
|
6
7
|
import type { SqlStorage } from '@prisma-next/sql-contract/types';
|
|
7
8
|
import type { DdlColumn, DdlTableConstraint } from '@prisma-next/sql-relational-core/ast';
|
|
8
9
|
import { errorPostgresMigrationStackMissing } from '../errors';
|
|
10
|
+
import { PostgresContractView } from '../postgres-contract-view';
|
|
9
11
|
import {
|
|
10
12
|
AddCheckConstraintCall,
|
|
11
13
|
AddColumnCall,
|
|
@@ -15,6 +17,7 @@ import {
|
|
|
15
17
|
AlterColumnTypeCall,
|
|
16
18
|
type AlterColumnTypeOptions,
|
|
17
19
|
CreateIndexCall,
|
|
20
|
+
CreateNativeEnumTypeCall,
|
|
18
21
|
CreateSchemaCall,
|
|
19
22
|
CreateTableCall,
|
|
20
23
|
DropCheckConstraintCall,
|
|
@@ -22,6 +25,7 @@ import {
|
|
|
22
25
|
DropConstraintCall,
|
|
23
26
|
DropDefaultCall,
|
|
24
27
|
DropIndexCall,
|
|
28
|
+
DropNativeEnumTypeCall,
|
|
25
29
|
DropNotNullCall,
|
|
26
30
|
DropTableCall,
|
|
27
31
|
SetDefaultCall,
|
|
@@ -60,20 +64,31 @@ import type { PostgresPlanTargetDetails } from './planner-target-details';
|
|
|
60
64
|
* is an antipattern in a migration. (The unbound/unspecified namespace concept
|
|
61
65
|
* remains for SQLite, which has no schemas, and for Mongo's connection `db`.)
|
|
62
66
|
*/
|
|
63
|
-
export abstract class PostgresMigration
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
> {
|
|
67
|
+
export abstract class PostgresMigration<
|
|
68
|
+
Start extends Contract<SqlStorage> = Contract<SqlStorage>,
|
|
69
|
+
End extends Contract<SqlStorage> = Contract<SqlStorage>,
|
|
70
|
+
> extends SqlMigration<PostgresPlanTargetDetails, 'postgres', Start, End> {
|
|
67
71
|
readonly targetId = 'postgres' as const;
|
|
68
72
|
|
|
69
73
|
/**
|
|
70
74
|
* Materialized Postgres control adapter, created once per migration
|
|
71
75
|
* instance from the injected stack. `undefined` only when the migration
|
|
72
|
-
* was instantiated without a stack (test fixtures); `
|
|
73
|
-
* throws in that case to surface the misuse.
|
|
76
|
+
* was instantiated without a stack (test fixtures); `controlAdapterFor`
|
|
77
|
+
* throws a PN-MIG-2007 in that case to surface the misuse.
|
|
74
78
|
*/
|
|
75
79
|
protected readonly controlAdapter: SqlControlAdapter<'postgres'> | undefined;
|
|
76
80
|
|
|
81
|
+
#endView = new MigrationContractViews<PostgresContractView<End>>(
|
|
82
|
+
this,
|
|
83
|
+
'PostgresMigration',
|
|
84
|
+
(json) => PostgresContractView.fromJson<End>(json),
|
|
85
|
+
);
|
|
86
|
+
#startView = new MigrationContractViews<PostgresContractView<Start>>(
|
|
87
|
+
this,
|
|
88
|
+
'PostgresMigration',
|
|
89
|
+
(json) => PostgresContractView.fromJson<Start>(json),
|
|
90
|
+
);
|
|
91
|
+
|
|
77
92
|
constructor(stack?: ControlStack<'sql', 'postgres'>) {
|
|
78
93
|
super(stack);
|
|
79
94
|
// The descriptor `create()` is typed as the wider `ControlAdapterInstance`;
|
|
@@ -84,6 +99,35 @@ export abstract class PostgresMigration extends SqlMigration<
|
|
|
84
99
|
: undefined;
|
|
85
100
|
}
|
|
86
101
|
|
|
102
|
+
/**
|
|
103
|
+
* Returns the materialized control adapter, or throws a PN-MIG-2007 naming
|
|
104
|
+
* `operation` when the migration was constructed without a `ControlStack`.
|
|
105
|
+
* Single home for the null-check that every DDL/DML method shares.
|
|
106
|
+
*/
|
|
107
|
+
private controlAdapterFor(operation: string): SqlControlAdapter<'postgres'> {
|
|
108
|
+
if (!this.controlAdapter) {
|
|
109
|
+
throw errorPostgresMigrationStackMissing(operation);
|
|
110
|
+
}
|
|
111
|
+
return this.controlAdapter;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* The typed, schema-qualified Postgres view over this migration's end-state
|
|
116
|
+
* contract — `this.endContract.namespace.<schema>.table.<name>`, etc. Throws
|
|
117
|
+
* if no `endContractJson` was provided.
|
|
118
|
+
*/
|
|
119
|
+
get endContract(): PostgresContractView<End> {
|
|
120
|
+
return this.#endView.endContract;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* The typed Postgres view over this migration's start-state contract, or
|
|
125
|
+
* `null` for a baseline migration (no `startContractJson`).
|
|
126
|
+
*/
|
|
127
|
+
get startContract(): PostgresContractView<Start> | null {
|
|
128
|
+
return this.#startView.startContract;
|
|
129
|
+
}
|
|
130
|
+
|
|
87
131
|
/**
|
|
88
132
|
* Instance-method wrapper around the free `dataTransform` factory that
|
|
89
133
|
* supplies the stored control adapter. Authors call this from inside
|
|
@@ -94,10 +138,7 @@ export abstract class PostgresMigration extends SqlMigration<
|
|
|
94
138
|
name: string,
|
|
95
139
|
options: DataTransformOptions,
|
|
96
140
|
): Promise<SqlMigrationPlanOperation<PostgresPlanTargetDetails>> {
|
|
97
|
-
|
|
98
|
-
throw errorPostgresMigrationStackMissing();
|
|
99
|
-
}
|
|
100
|
-
return dataTransform(contract, name, options, this.controlAdapter);
|
|
141
|
+
return dataTransform(contract, name, options, this.controlAdapterFor('dataTransform'));
|
|
101
142
|
}
|
|
102
143
|
|
|
103
144
|
/**
|
|
@@ -112,15 +153,12 @@ export abstract class PostgresMigration extends SqlMigration<
|
|
|
112
153
|
readonly columns: readonly DdlColumn[];
|
|
113
154
|
readonly constraints?: readonly DdlTableConstraint[];
|
|
114
155
|
}): Promise<SqlMigrationPlanOperation<PostgresPlanTargetDetails>> {
|
|
115
|
-
if (!this.controlAdapter) {
|
|
116
|
-
throw errorPostgresMigrationStackMissing();
|
|
117
|
-
}
|
|
118
156
|
return new CreateTableCall(
|
|
119
157
|
options.schema,
|
|
120
158
|
options.table,
|
|
121
159
|
options.columns,
|
|
122
160
|
options.constraints,
|
|
123
|
-
).toOp(this.
|
|
161
|
+
).toOp(this.controlAdapterFor('createTable'));
|
|
124
162
|
}
|
|
125
163
|
|
|
126
164
|
/**
|
|
@@ -132,10 +170,36 @@ export abstract class PostgresMigration extends SqlMigration<
|
|
|
132
170
|
readonly schema: string;
|
|
133
171
|
readonly ifNotExists?: boolean;
|
|
134
172
|
}): Promise<SqlMigrationPlanOperation<PostgresPlanTargetDetails>> {
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
173
|
+
return new CreateSchemaCall(options.schema).toOp(this.controlAdapterFor('createSchema'));
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
/**
|
|
177
|
+
* Emit a `CREATE TYPE ... AS ENUM (...)` migration operation for a managed
|
|
178
|
+
* native enum. Builds a typed DDL node and lowers it through the stored
|
|
179
|
+
* control adapter (members render in declaration order). Throws if no adapter
|
|
180
|
+
* is present.
|
|
181
|
+
*/
|
|
182
|
+
protected createNativeEnumType(options: {
|
|
183
|
+
readonly schema: string;
|
|
184
|
+
readonly typeName: string;
|
|
185
|
+
readonly members: readonly string[];
|
|
186
|
+
}): Promise<SqlMigrationPlanOperation<PostgresPlanTargetDetails>> {
|
|
187
|
+
return new CreateNativeEnumTypeCall(options.schema, options.typeName, options.members).toOp(
|
|
188
|
+
this.controlAdapterFor('createNativeEnumType'),
|
|
189
|
+
);
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
/**
|
|
193
|
+
* Emit a `DROP TYPE` migration operation for a managed native enum, lowered
|
|
194
|
+
* through the stored control adapter. Throws if no adapter is present.
|
|
195
|
+
*/
|
|
196
|
+
protected dropNativeEnumType(options: {
|
|
197
|
+
readonly schema: string;
|
|
198
|
+
readonly typeName: string;
|
|
199
|
+
}): Promise<SqlMigrationPlanOperation<PostgresPlanTargetDetails>> {
|
|
200
|
+
return new DropNativeEnumTypeCall(options.schema, options.typeName).toOp(
|
|
201
|
+
this.controlAdapterFor('dropNativeEnumType'),
|
|
202
|
+
);
|
|
139
203
|
}
|
|
140
204
|
|
|
141
205
|
protected addColumn(options: {
|
|
@@ -143,11 +207,8 @@ export abstract class PostgresMigration extends SqlMigration<
|
|
|
143
207
|
readonly table: string;
|
|
144
208
|
readonly column: DdlColumn;
|
|
145
209
|
}): Promise<SqlMigrationPlanOperation<PostgresPlanTargetDetails>> {
|
|
146
|
-
if (!this.controlAdapter) {
|
|
147
|
-
throw errorPostgresMigrationStackMissing();
|
|
148
|
-
}
|
|
149
210
|
return new AddColumnCall(options.schema, options.table, options.column).toOp(
|
|
150
|
-
this.
|
|
211
|
+
this.controlAdapterFor('addColumn'),
|
|
151
212
|
);
|
|
152
213
|
}
|
|
153
214
|
|
|
@@ -157,15 +218,12 @@ export abstract class PostgresMigration extends SqlMigration<
|
|
|
157
218
|
readonly constraint: string;
|
|
158
219
|
readonly columns: readonly string[];
|
|
159
220
|
}): Promise<SqlMigrationPlanOperation<PostgresPlanTargetDetails>> {
|
|
160
|
-
if (!this.controlAdapter) {
|
|
161
|
-
throw errorPostgresMigrationStackMissing();
|
|
162
|
-
}
|
|
163
221
|
return new AddPrimaryKeyCall(
|
|
164
222
|
options.schema,
|
|
165
223
|
options.table,
|
|
166
224
|
options.constraint,
|
|
167
225
|
options.columns,
|
|
168
|
-
).toOp(this.
|
|
226
|
+
).toOp(this.controlAdapterFor('addPrimaryKey'));
|
|
169
227
|
}
|
|
170
228
|
|
|
171
229
|
protected addUnique(options: {
|
|
@@ -174,15 +232,12 @@ export abstract class PostgresMigration extends SqlMigration<
|
|
|
174
232
|
readonly constraint: string;
|
|
175
233
|
readonly columns: readonly string[];
|
|
176
234
|
}): Promise<SqlMigrationPlanOperation<PostgresPlanTargetDetails>> {
|
|
177
|
-
if (!this.controlAdapter) {
|
|
178
|
-
throw errorPostgresMigrationStackMissing();
|
|
179
|
-
}
|
|
180
235
|
return new AddUniqueCall(
|
|
181
236
|
options.schema,
|
|
182
237
|
options.table,
|
|
183
238
|
options.constraint,
|
|
184
239
|
options.columns,
|
|
185
|
-
).toOp(this.
|
|
240
|
+
).toOp(this.controlAdapterFor('addUnique'));
|
|
186
241
|
}
|
|
187
242
|
|
|
188
243
|
protected addForeignKey(options: {
|
|
@@ -190,11 +245,8 @@ export abstract class PostgresMigration extends SqlMigration<
|
|
|
190
245
|
readonly table: string;
|
|
191
246
|
readonly foreignKey: ForeignKeySpec;
|
|
192
247
|
}): Promise<SqlMigrationPlanOperation<PostgresPlanTargetDetails>> {
|
|
193
|
-
if (!this.controlAdapter) {
|
|
194
|
-
throw errorPostgresMigrationStackMissing();
|
|
195
|
-
}
|
|
196
248
|
return new AddForeignKeyCall(options.schema, options.table, options.foreignKey).toOp(
|
|
197
|
-
this.
|
|
249
|
+
this.controlAdapterFor('addForeignKey'),
|
|
198
250
|
);
|
|
199
251
|
}
|
|
200
252
|
|
|
@@ -205,16 +257,13 @@ export abstract class PostgresMigration extends SqlMigration<
|
|
|
205
257
|
readonly column: string;
|
|
206
258
|
readonly values: readonly string[];
|
|
207
259
|
}): Promise<SqlMigrationPlanOperation<PostgresPlanTargetDetails>> {
|
|
208
|
-
if (!this.controlAdapter) {
|
|
209
|
-
throw errorPostgresMigrationStackMissing();
|
|
210
|
-
}
|
|
211
260
|
return new AddCheckConstraintCall(
|
|
212
261
|
options.schema,
|
|
213
262
|
options.table,
|
|
214
263
|
options.constraint,
|
|
215
264
|
options.column,
|
|
216
265
|
options.values,
|
|
217
|
-
).toOp(this.
|
|
266
|
+
).toOp(this.controlAdapterFor('addCheckConstraint'));
|
|
218
267
|
}
|
|
219
268
|
|
|
220
269
|
protected dropCheckConstraint(options: {
|
|
@@ -222,11 +271,8 @@ export abstract class PostgresMigration extends SqlMigration<
|
|
|
222
271
|
readonly table: string;
|
|
223
272
|
readonly constraint: string;
|
|
224
273
|
}): Promise<SqlMigrationPlanOperation<PostgresPlanTargetDetails>> {
|
|
225
|
-
if (!this.controlAdapter) {
|
|
226
|
-
throw errorPostgresMigrationStackMissing();
|
|
227
|
-
}
|
|
228
274
|
return new DropCheckConstraintCall(options.schema, options.table, options.constraint).toOp(
|
|
229
|
-
this.
|
|
275
|
+
this.controlAdapterFor('dropCheckConstraint'),
|
|
230
276
|
);
|
|
231
277
|
}
|
|
232
278
|
|
|
@@ -236,25 +282,21 @@ export abstract class PostgresMigration extends SqlMigration<
|
|
|
236
282
|
readonly constraint: string;
|
|
237
283
|
readonly kind?: 'foreignKey' | 'unique' | 'primaryKey';
|
|
238
284
|
}): Promise<SqlMigrationPlanOperation<PostgresPlanTargetDetails>> {
|
|
239
|
-
if (!this.controlAdapter) {
|
|
240
|
-
throw errorPostgresMigrationStackMissing();
|
|
241
|
-
}
|
|
242
285
|
return new DropConstraintCall(
|
|
243
286
|
options.schema,
|
|
244
287
|
options.table,
|
|
245
288
|
options.constraint,
|
|
246
289
|
options.kind ?? 'unique',
|
|
247
|
-
).toOp(this.
|
|
290
|
+
).toOp(this.controlAdapterFor('dropConstraint'));
|
|
248
291
|
}
|
|
249
292
|
|
|
250
293
|
protected dropTable(options: {
|
|
251
294
|
readonly schema: string;
|
|
252
295
|
readonly table: string;
|
|
253
296
|
}): Promise<SqlMigrationPlanOperation<PostgresPlanTargetDetails>> {
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
return new DropTableCall(options.schema, options.table).toOp(this.controlAdapter);
|
|
297
|
+
return new DropTableCall(options.schema, options.table).toOp(
|
|
298
|
+
this.controlAdapterFor('dropTable'),
|
|
299
|
+
);
|
|
258
300
|
}
|
|
259
301
|
|
|
260
302
|
protected dropColumn(options: {
|
|
@@ -262,11 +304,8 @@ export abstract class PostgresMigration extends SqlMigration<
|
|
|
262
304
|
readonly table: string;
|
|
263
305
|
readonly column: string;
|
|
264
306
|
}): Promise<SqlMigrationPlanOperation<PostgresPlanTargetDetails>> {
|
|
265
|
-
if (!this.controlAdapter) {
|
|
266
|
-
throw errorPostgresMigrationStackMissing();
|
|
267
|
-
}
|
|
268
307
|
return new DropColumnCall(options.schema, options.table, options.column).toOp(
|
|
269
|
-
this.
|
|
308
|
+
this.controlAdapterFor('dropColumn'),
|
|
270
309
|
);
|
|
271
310
|
}
|
|
272
311
|
|
|
@@ -276,15 +315,12 @@ export abstract class PostgresMigration extends SqlMigration<
|
|
|
276
315
|
readonly column: string;
|
|
277
316
|
readonly options: AlterColumnTypeOptions;
|
|
278
317
|
}): Promise<SqlMigrationPlanOperation<PostgresPlanTargetDetails>> {
|
|
279
|
-
if (!this.controlAdapter) {
|
|
280
|
-
throw errorPostgresMigrationStackMissing();
|
|
281
|
-
}
|
|
282
318
|
return new AlterColumnTypeCall(
|
|
283
319
|
options.schema,
|
|
284
320
|
options.table,
|
|
285
321
|
options.column,
|
|
286
322
|
options.options,
|
|
287
|
-
).toOp(this.
|
|
323
|
+
).toOp(this.controlAdapterFor('alterColumnType'));
|
|
288
324
|
}
|
|
289
325
|
|
|
290
326
|
protected setNotNull(options: {
|
|
@@ -292,11 +328,8 @@ export abstract class PostgresMigration extends SqlMigration<
|
|
|
292
328
|
readonly table: string;
|
|
293
329
|
readonly column: string;
|
|
294
330
|
}): Promise<SqlMigrationPlanOperation<PostgresPlanTargetDetails>> {
|
|
295
|
-
if (!this.controlAdapter) {
|
|
296
|
-
throw errorPostgresMigrationStackMissing();
|
|
297
|
-
}
|
|
298
331
|
return new SetNotNullCall(options.schema, options.table, options.column).toOp(
|
|
299
|
-
this.
|
|
332
|
+
this.controlAdapterFor('setNotNull'),
|
|
300
333
|
);
|
|
301
334
|
}
|
|
302
335
|
|
|
@@ -305,11 +338,8 @@ export abstract class PostgresMigration extends SqlMigration<
|
|
|
305
338
|
readonly table: string;
|
|
306
339
|
readonly column: string;
|
|
307
340
|
}): Promise<SqlMigrationPlanOperation<PostgresPlanTargetDetails>> {
|
|
308
|
-
if (!this.controlAdapter) {
|
|
309
|
-
throw errorPostgresMigrationStackMissing();
|
|
310
|
-
}
|
|
311
341
|
return new DropNotNullCall(options.schema, options.table, options.column).toOp(
|
|
312
|
-
this.
|
|
342
|
+
this.controlAdapterFor('dropNotNull'),
|
|
313
343
|
);
|
|
314
344
|
}
|
|
315
345
|
|
|
@@ -320,16 +350,13 @@ export abstract class PostgresMigration extends SqlMigration<
|
|
|
320
350
|
readonly defaultSql: string;
|
|
321
351
|
readonly operationClass?: 'additive' | 'widening';
|
|
322
352
|
}): Promise<SqlMigrationPlanOperation<PostgresPlanTargetDetails>> {
|
|
323
|
-
if (!this.controlAdapter) {
|
|
324
|
-
throw errorPostgresMigrationStackMissing();
|
|
325
|
-
}
|
|
326
353
|
return new SetDefaultCall(
|
|
327
354
|
options.schema,
|
|
328
355
|
options.table,
|
|
329
356
|
options.column,
|
|
330
357
|
options.defaultSql,
|
|
331
358
|
options.operationClass,
|
|
332
|
-
).toOp(this.
|
|
359
|
+
).toOp(this.controlAdapterFor('setDefault'));
|
|
333
360
|
}
|
|
334
361
|
|
|
335
362
|
protected dropDefault(options: {
|
|
@@ -337,11 +364,8 @@ export abstract class PostgresMigration extends SqlMigration<
|
|
|
337
364
|
readonly table: string;
|
|
338
365
|
readonly column: string;
|
|
339
366
|
}): Promise<SqlMigrationPlanOperation<PostgresPlanTargetDetails>> {
|
|
340
|
-
if (!this.controlAdapter) {
|
|
341
|
-
throw errorPostgresMigrationStackMissing();
|
|
342
|
-
}
|
|
343
367
|
return new DropDefaultCall(options.schema, options.table, options.column).toOp(
|
|
344
|
-
this.
|
|
368
|
+
this.controlAdapterFor('dropDefault'),
|
|
345
369
|
);
|
|
346
370
|
}
|
|
347
371
|
|
|
@@ -352,16 +376,13 @@ export abstract class PostgresMigration extends SqlMigration<
|
|
|
352
376
|
readonly columns: readonly string[];
|
|
353
377
|
readonly extras?: CreateIndexExtras;
|
|
354
378
|
}): Promise<SqlMigrationPlanOperation<PostgresPlanTargetDetails>> {
|
|
355
|
-
if (!this.controlAdapter) {
|
|
356
|
-
throw errorPostgresMigrationStackMissing();
|
|
357
|
-
}
|
|
358
379
|
return new CreateIndexCall(
|
|
359
380
|
options.schema,
|
|
360
381
|
options.table,
|
|
361
382
|
options.index,
|
|
362
383
|
options.columns,
|
|
363
384
|
options.extras,
|
|
364
|
-
).toOp(this.
|
|
385
|
+
).toOp(this.controlAdapterFor('createIndex'));
|
|
365
386
|
}
|
|
366
387
|
|
|
367
388
|
protected dropIndex(options: {
|
|
@@ -369,11 +390,8 @@ export abstract class PostgresMigration extends SqlMigration<
|
|
|
369
390
|
readonly table: string;
|
|
370
391
|
readonly index: string;
|
|
371
392
|
}): Promise<SqlMigrationPlanOperation<PostgresPlanTargetDetails>> {
|
|
372
|
-
if (!this.controlAdapter) {
|
|
373
|
-
throw errorPostgresMigrationStackMissing();
|
|
374
|
-
}
|
|
375
393
|
return new DropIndexCall(options.schema, options.table, options.index).toOp(
|
|
376
|
-
this.
|
|
394
|
+
this.controlAdapterFor('dropIndex'),
|
|
377
395
|
);
|
|
378
396
|
}
|
|
379
397
|
|
|
@@ -383,9 +401,6 @@ export abstract class PostgresMigration extends SqlMigration<
|
|
|
383
401
|
readonly id: string;
|
|
384
402
|
readonly label?: string;
|
|
385
403
|
}): Promise<SqlMigrationPlanOperation<PostgresPlanTargetDetails>> {
|
|
386
|
-
|
|
387
|
-
throw errorPostgresMigrationStackMissing();
|
|
388
|
-
}
|
|
389
|
-
return installExtension(options, this.controlAdapter);
|
|
404
|
+
return installExtension(options, this.controlAdapterFor('installExtension'));
|
|
390
405
|
}
|
|
391
406
|
}
|
|
@@ -45,15 +45,19 @@ export function renderCallsToTypeScript(
|
|
|
45
45
|
calls: ReadonlyArray<OpFactoryCall>,
|
|
46
46
|
meta: RenderMigrationMeta,
|
|
47
47
|
): string {
|
|
48
|
-
const imports = buildImports(calls);
|
|
48
|
+
const imports = buildImports(calls, meta);
|
|
49
49
|
const operationsBody = calls.map((c) => renderCall(c)).join(',\n');
|
|
50
|
+
const hasStart = meta.from !== null;
|
|
51
|
+
const startField = hasStart ? [' override readonly startContractJson = startContract;'] : [];
|
|
50
52
|
|
|
51
53
|
return [
|
|
52
54
|
shebangLineFor(detectScaffoldRuntime()),
|
|
53
55
|
imports,
|
|
54
56
|
'',
|
|
55
|
-
|
|
56
|
-
|
|
57
|
+
`export default class M extends Migration<${hasStart ? 'Start' : 'never'}, End> {`,
|
|
58
|
+
...startField,
|
|
59
|
+
' override readonly endContractJson = endContract;',
|
|
60
|
+
'',
|
|
57
61
|
' override get operations() {',
|
|
58
62
|
' return [',
|
|
59
63
|
indent(operationsBody, 6),
|
|
@@ -70,8 +74,8 @@ function renderCall(call: OpFactoryCall): string {
|
|
|
70
74
|
return call.renderTypeScript();
|
|
71
75
|
}
|
|
72
76
|
|
|
73
|
-
function buildImports(calls: ReadonlyArray<OpFactoryCall
|
|
74
|
-
const requirements: ImportRequirement[] = [...BASE_IMPORTS];
|
|
77
|
+
function buildImports(calls: ReadonlyArray<OpFactoryCall>, meta: RenderMigrationMeta): string {
|
|
78
|
+
const requirements: ImportRequirement[] = [...BASE_IMPORTS, ...contractImports(meta)];
|
|
75
79
|
for (const call of calls) {
|
|
76
80
|
for (const req of call.importRequirements()) {
|
|
77
81
|
requirements.push(req);
|
|
@@ -80,16 +84,39 @@ function buildImports(calls: ReadonlyArray<OpFactoryCall>): string {
|
|
|
80
84
|
return renderImports(requirements);
|
|
81
85
|
}
|
|
82
86
|
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
87
|
+
/**
|
|
88
|
+
* The committed contract-JSON imports the scaffold reads its from/to identity
|
|
89
|
+
* from. `end-contract.json` is always present; `start-contract.json` is added
|
|
90
|
+
* only for a non-baseline migration (`meta.from !== null`). The matching
|
|
91
|
+
* `Contract` type imports (aliased `Start`/`End`) feed the
|
|
92
|
+
* `Migration<Start, End>` generics. Baseline emits `Migration<never, End>` with
|
|
93
|
+
* no start imports — `never` is the honest "no prior contract" Start.
|
|
94
|
+
*/
|
|
95
|
+
function contractImports(meta: RenderMigrationMeta): readonly ImportRequirement[] {
|
|
96
|
+
const reqs: ImportRequirement[] = [
|
|
97
|
+
{
|
|
98
|
+
moduleSpecifier: './end-contract.json',
|
|
99
|
+
symbol: 'endContract',
|
|
100
|
+
kind: 'default',
|
|
101
|
+
attributes: { type: 'json' },
|
|
102
|
+
},
|
|
103
|
+
{ moduleSpecifier: './end-contract', symbol: 'Contract', alias: 'End', typeOnly: true },
|
|
104
|
+
];
|
|
105
|
+
if (meta.from !== null) {
|
|
106
|
+
reqs.push({
|
|
107
|
+
moduleSpecifier: './start-contract.json',
|
|
108
|
+
symbol: 'startContract',
|
|
109
|
+
kind: 'default',
|
|
110
|
+
attributes: { type: 'json' },
|
|
111
|
+
});
|
|
112
|
+
reqs.push({
|
|
113
|
+
moduleSpecifier: './start-contract',
|
|
114
|
+
symbol: 'Contract',
|
|
115
|
+
alias: 'Start',
|
|
116
|
+
typeOnly: true,
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
return reqs;
|
|
93
120
|
}
|
|
94
121
|
|
|
95
122
|
function indent(text: string, spaces: number): string {
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { UNBOUND_NAMESPACE_ID } from '@prisma-next/framework-components/ir';
|
|
2
|
+
import type { SqlStorage } from '@prisma-next/sql-contract/types';
|
|
3
|
+
import { DEFAULT_NAMESPACE_ID } from '../namespace-ids';
|
|
4
|
+
import { isPostgresSchema } from '../postgres-schema';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Given the contract's storage and a namespace id, returns the live Postgres
|
|
8
|
+
* DDL schema name that namespace maps to. A named Postgres namespace dispatches
|
|
9
|
+
* to its `ddlSchemaName(storage)`; the unbound sentinel resolves to
|
|
10
|
+
* `DEFAULT_NAMESPACE_ID` (the search-path default for offline planning); a
|
|
11
|
+
* bare object payload (used by some tests) falls back to the namespace id
|
|
12
|
+
* itself.
|
|
13
|
+
*/
|
|
14
|
+
export function resolveDdlSchemaForNamespaceStorage(
|
|
15
|
+
storage: SqlStorage,
|
|
16
|
+
namespaceId: string,
|
|
17
|
+
): string {
|
|
18
|
+
if (namespaceId === UNBOUND_NAMESPACE_ID) {
|
|
19
|
+
return DEFAULT_NAMESPACE_ID;
|
|
20
|
+
}
|
|
21
|
+
const namespace = storage.namespaces[namespaceId];
|
|
22
|
+
if (namespace && isPostgresSchema(namespace)) {
|
|
23
|
+
return namespace.ddlSchemaName(storage);
|
|
24
|
+
}
|
|
25
|
+
return namespaceId;
|
|
26
|
+
}
|
|
@@ -12,7 +12,6 @@ import type {
|
|
|
12
12
|
SqlMigrationRunnerSuccessValue,
|
|
13
13
|
} from '@prisma-next/family-sql/control';
|
|
14
14
|
import { runnerFailure, runnerSuccess } from '@prisma-next/family-sql/control';
|
|
15
|
-
import { verifySqlSchema } from '@prisma-next/family-sql/schema-verify';
|
|
16
15
|
import type { MigrationRunnerResult } from '@prisma-next/framework-components/control';
|
|
17
16
|
import { APP_SPACE_ID } from '@prisma-next/framework-components/control';
|
|
18
17
|
import { UNBOUND_NAMESPACE_ID } from '@prisma-next/framework-components/ir';
|
|
@@ -23,8 +22,6 @@ import { blindCast } from '@prisma-next/utils/casts';
|
|
|
23
22
|
import { ifDefined } from '@prisma-next/utils/defined';
|
|
24
23
|
import type { Result } from '@prisma-next/utils/result';
|
|
25
24
|
import { notOk, ok, okVoid } from '@prisma-next/utils/result';
|
|
26
|
-
import { parsePostgresDefault } from '../default-normalizer';
|
|
27
|
-
import { normalizeSchemaNativeType } from '../native-type-normalizer';
|
|
28
25
|
import type { PostgresPlanTargetDetails } from './planner-target-details';
|
|
29
26
|
|
|
30
27
|
interface ApplyPlanSuccessValue {
|
|
@@ -124,30 +121,27 @@ class PostgresMigrationRunner implements SqlMigrationRunner<PostgresPlanTargetDe
|
|
|
124
121
|
applyValue = applyResult.value;
|
|
125
122
|
}
|
|
126
123
|
|
|
127
|
-
//
|
|
128
|
-
//
|
|
129
|
-
//
|
|
130
|
-
//
|
|
131
|
-
// an extension contract.
|
|
124
|
+
// Verify the schema on app-space only: extension spaces don't own
|
|
125
|
+
// user-facing tables, so verifying the destination contract against the
|
|
126
|
+
// database would flag every app-space table as "extra". Delegates to the
|
|
127
|
+
// family `verifySchema` — the same comparison the CLI verify runs.
|
|
132
128
|
if (space === APP_SPACE_ID) {
|
|
133
|
-
const
|
|
129
|
+
const schemaNode = await this.family.introspect({
|
|
134
130
|
driver,
|
|
135
131
|
contract: options.destinationContract,
|
|
136
132
|
});
|
|
137
|
-
const schemaVerifyResult =
|
|
133
|
+
const schemaVerifyResult = this.family.verifySchema({
|
|
138
134
|
contract: options.destinationContract,
|
|
139
|
-
schema:
|
|
135
|
+
schema: schemaNode,
|
|
140
136
|
strict: options.strictVerification ?? true,
|
|
141
|
-
context: options.context ?? {},
|
|
142
|
-
typeMetadataRegistry: this.family.typeMetadataRegistry,
|
|
143
137
|
frameworkComponents: options.frameworkComponents,
|
|
144
|
-
normalizeDefault: parsePostgresDefault,
|
|
145
|
-
normalizeNativeType: normalizeSchemaNativeType,
|
|
146
138
|
});
|
|
147
139
|
if (!schemaVerifyResult.ok) {
|
|
148
140
|
return runnerFailure('SCHEMA_VERIFY_FAILED', schemaVerifyResult.summary, {
|
|
149
141
|
why: 'The resulting database schema does not satisfy the destination contract.',
|
|
150
|
-
meta: {
|
|
142
|
+
meta: {
|
|
143
|
+
issues: schemaVerifyResult.schema.issues,
|
|
144
|
+
},
|
|
151
145
|
});
|
|
152
146
|
}
|
|
153
147
|
}
|
|
@@ -666,6 +660,7 @@ class PostgresMigrationRunner implements SqlMigrationRunner<PostgresPlanTargetDe
|
|
|
666
660
|
migrationName: edge.dirName,
|
|
667
661
|
migrationHash: edge.migrationHash,
|
|
668
662
|
operations: edgeOps,
|
|
663
|
+
...ifDefined('destinationContractJson', edge.destinationContractJson),
|
|
669
664
|
},
|
|
670
665
|
});
|
|
671
666
|
}
|