@prisma-next/target-postgres 0.14.0 → 0.15.0-dev.10
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-BtsOWgI3.mjs +674 -0
- package/dist/authoring-BtsOWgI3.mjs.map +1 -0
- package/dist/canonicalize-D1F4vUnP.d.mts +48 -0
- package/dist/canonicalize-D1F4vUnP.d.mts.map +1 -0
- package/dist/{codec-ids-BvytN2P8.mjs → codec-ids-B10ZZHzw.mjs} +4 -2
- package/dist/codec-ids-B10ZZHzw.mjs.map +1 -0
- package/dist/{codec-ids-CnXu9Qy3.d.mts → codec-ids-CI144z7g.d.mts} +4 -2
- package/dist/codec-ids-CI144z7g.d.mts.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-CTfT4U4O.d.mts} +4 -2
- package/dist/codec-types-CTfT4U4O.d.mts.map +1 -0
- package/dist/codec-types.d.mts +1 -1
- package/dist/{codecs--0A5_4Bq.d.mts → codecs-D7W9O0Xx.d.mts} +134 -4
- package/dist/codecs-D7W9O0Xx.d.mts.map +1 -0
- package/dist/codecs-DRbb26Or.mjs +955 -0
- package/dist/codecs-DRbb26Or.mjs.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-DaLdbcYE.mjs +1254 -0
- package/dist/control-policy-DaLdbcYE.mjs.map +1 -0
- package/dist/control.d.mts +2 -2
- package/dist/control.d.mts.map +1 -1
- package/dist/control.mjs +880 -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-GTTOvjx_.mjs} +128 -6
- package/dist/ddl-GTTOvjx_.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-CFQKLXl_.mjs +23 -0
- package/dist/descriptor-meta-CFQKLXl_.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-oY3brcLj.mjs +368 -0
- package/dist/diff-database-schema-oY3brcLj.mjs.map +1 -0
- package/dist/diff-database-schema.d.mts +37 -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-DJC5B8Id.mjs +192 -0
- package/dist/nodes-DJC5B8Id.mjs.map +1 -0
- package/dist/nodes-Dv5eCSq9.d.mts +170 -0
- package/dist/nodes-Dv5eCSq9.d.mts.map +1 -0
- package/dist/{op-factory-call-DmQEc3XV.d.mts → op-factory-call-CvH0JeBW.d.mts} +119 -17
- package/dist/op-factory-call-CvH0JeBW.d.mts.map +1 -0
- package/dist/{op-factory-call-D_p5vxwt.mjs → op-factory-call-tBcLo_B8.mjs} +496 -38
- package/dist/op-factory-call-tBcLo_B8.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 +321 -3
- package/dist/pack.d.mts.map +1 -1
- package/dist/pack.mjs +1 -1
- 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-ootbxGty.mjs +390 -0
- package/dist/planner-ootbxGty.mjs.map +1 -0
- package/dist/{planner-produced-postgres-migration-Cji5vxUf.mjs → planner-produced-postgres-migration-DVsaobdV.mjs} +3 -3
- package/dist/{planner-produced-postgres-migration-Cji5vxUf.mjs.map → planner-produced-postgres-migration-DVsaobdV.mjs.map} +1 -1
- package/dist/{planner-produced-postgres-migration-QqHa2C2l.d.mts → planner-produced-postgres-migration-k33bb9Sm.d.mts} +4 -4
- package/dist/{planner-produced-postgres-migration-QqHa2C2l.d.mts.map → planner-produced-postgres-migration-k33bb9Sm.d.mts.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-zqNfs2XZ.mjs} +5 -5
- package/dist/{planner-sql-checks-jqUUGyQR.mjs.map → planner-sql-checks-zqNfs2XZ.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-view-C9j5cqP0.d.mts +34 -0
- package/dist/postgres-contract-view-C9j5cqP0.d.mts.map +1 -0
- package/dist/{postgres-contract-serializer-k3TAcPMY.mjs → postgres-contract-view-DM8sN1Ot.mjs} +45 -41
- package/dist/postgres-contract-view-DM8sN1Ot.mjs.map +1 -0
- package/dist/postgres-database-schema-node-DJOTywwQ.d.mts +271 -0
- package/dist/postgres-database-schema-node-DJOTywwQ.d.mts.map +1 -0
- package/dist/postgres-migration-Bt3sXoID.mjs +194 -0
- package/dist/postgres-migration-Bt3sXoID.mjs.map +1 -0
- package/dist/{postgres-migration-Y4YBJqkS.d.mts → postgres-migration-ulfqRGA1.d.mts} +83 -9
- package/dist/postgres-migration-ulfqRGA1.d.mts.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-bg32e7I-.mjs +191 -0
- package/dist/postgres-role-schema-node-bg32e7I-.mjs.map +1 -0
- package/dist/{postgres-schema-COGZ1ark.mjs → postgres-schema-Cm4DtiGA.mjs} +200 -11
- package/dist/postgres-schema-Cm4DtiGA.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-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-XyBaaenM.mjs +22 -0
- package/dist/resolve-ddl-schema-XyBaaenM.mjs.map +1 -0
- package/dist/rls-canonicalize.d.mts +27 -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/schema-node-kinds-CrYzCR1i.d.mts +30 -0
- package/dist/schema-node-kinds-CrYzCR1i.d.mts.map +1 -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 +5 -140
- package/dist/types.mjs +5 -2
- package/dist/wire-name-DbQ9-2RC.mjs +104 -0
- package/dist/wire-name-DbQ9-2RC.mjs.map +1 -0
- package/package.json +26 -20
- package/src/contract-free/checks.ts +153 -0
- package/src/contract-free/control-bootstrap.ts +20 -3
- package/src/contract-free/ddl.ts +98 -1
- package/src/core/authoring.ts +726 -2
- package/src/core/codec-helpers.ts +33 -7
- package/src/core/codec-ids.ts +2 -0
- package/src/core/codec-type-map.ts +4 -0
- package/src/core/codecs.ts +236 -12
- package/src/core/ddl/nodes.ts +185 -2
- package/src/core/default-normalizer.ts +122 -2
- package/src/core/descriptor-meta.ts +12 -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 +269 -0
- package/src/core/migrations/control-policy.ts +218 -65
- package/src/core/migrations/diff-database-schema.ts +252 -0
- package/src/core/migrations/issue-planner.ts +782 -660
- package/src/core/migrations/op-factory-call.ts +415 -31
- 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 +250 -218
- package/src/core/migrations/planner-target-details.ts +3 -1
- package/src/core/migrations/planner.ts +358 -67
- package/src/core/migrations/postgres-migration.ts +178 -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 +45 -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 +1290 -0
- package/src/core/psl-infer/postgres-default-mapping.ts +16 -0
- package/src/core/psl-infer/postgres-type-map.ts +129 -0
- package/src/core/rls/canonicalize.ts +65 -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 +100 -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 +5 -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 +9 -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 +12 -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 +38 -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 +0 -145
- 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,27 +3,38 @@ 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';
|
|
11
|
+
import { PostgresRlsPolicy, type PostgresRlsPolicyInput } from '../postgres-rls-policy';
|
|
9
12
|
import {
|
|
10
13
|
AddCheckConstraintCall,
|
|
11
14
|
AddColumnCall,
|
|
12
15
|
AddForeignKeyCall,
|
|
16
|
+
AddNativeEnumValueCall,
|
|
13
17
|
AddPrimaryKeyCall,
|
|
14
18
|
AddUniqueCall,
|
|
15
19
|
AlterColumnTypeCall,
|
|
16
20
|
type AlterColumnTypeOptions,
|
|
17
21
|
CreateIndexCall,
|
|
22
|
+
CreateNativeEnumTypeCall,
|
|
23
|
+
CreatePostgresRlsPolicyCall,
|
|
18
24
|
CreateSchemaCall,
|
|
19
25
|
CreateTableCall,
|
|
26
|
+
DisableRowLevelSecurityCall,
|
|
20
27
|
DropCheckConstraintCall,
|
|
21
28
|
DropColumnCall,
|
|
22
29
|
DropConstraintCall,
|
|
23
30
|
DropDefaultCall,
|
|
24
31
|
DropIndexCall,
|
|
32
|
+
DropNativeEnumTypeCall,
|
|
25
33
|
DropNotNullCall,
|
|
34
|
+
DropPostgresRlsPolicyCall,
|
|
26
35
|
DropTableCall,
|
|
36
|
+
EnableRowLevelSecurityCall,
|
|
37
|
+
RenamePostgresRlsPolicyCall,
|
|
27
38
|
SetDefaultCall,
|
|
28
39
|
SetNotNullCall,
|
|
29
40
|
} from './op-factory-call';
|
|
@@ -60,20 +71,31 @@ import type { PostgresPlanTargetDetails } from './planner-target-details';
|
|
|
60
71
|
* is an antipattern in a migration. (The unbound/unspecified namespace concept
|
|
61
72
|
* remains for SQLite, which has no schemas, and for Mongo's connection `db`.)
|
|
62
73
|
*/
|
|
63
|
-
export abstract class PostgresMigration
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
> {
|
|
74
|
+
export abstract class PostgresMigration<
|
|
75
|
+
Start extends Contract<SqlStorage> = Contract<SqlStorage>,
|
|
76
|
+
End extends Contract<SqlStorage> = Contract<SqlStorage>,
|
|
77
|
+
> extends SqlMigration<PostgresPlanTargetDetails, 'postgres', Start, End> {
|
|
67
78
|
readonly targetId = 'postgres' as const;
|
|
68
79
|
|
|
69
80
|
/**
|
|
70
81
|
* Materialized Postgres control adapter, created once per migration
|
|
71
82
|
* 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.
|
|
83
|
+
* was instantiated without a stack (test fixtures); `controlAdapterFor`
|
|
84
|
+
* throws a PN-MIG-2007 in that case to surface the misuse.
|
|
74
85
|
*/
|
|
75
86
|
protected readonly controlAdapter: SqlControlAdapter<'postgres'> | undefined;
|
|
76
87
|
|
|
88
|
+
#endView = new MigrationContractViews<PostgresContractView<End>>(
|
|
89
|
+
this,
|
|
90
|
+
'PostgresMigration',
|
|
91
|
+
(json) => PostgresContractView.fromJson<End>(json),
|
|
92
|
+
);
|
|
93
|
+
#startView = new MigrationContractViews<PostgresContractView<Start>>(
|
|
94
|
+
this,
|
|
95
|
+
'PostgresMigration',
|
|
96
|
+
(json) => PostgresContractView.fromJson<Start>(json),
|
|
97
|
+
);
|
|
98
|
+
|
|
77
99
|
constructor(stack?: ControlStack<'sql', 'postgres'>) {
|
|
78
100
|
super(stack);
|
|
79
101
|
// The descriptor `create()` is typed as the wider `ControlAdapterInstance`;
|
|
@@ -84,6 +106,35 @@ export abstract class PostgresMigration extends SqlMigration<
|
|
|
84
106
|
: undefined;
|
|
85
107
|
}
|
|
86
108
|
|
|
109
|
+
/**
|
|
110
|
+
* Returns the materialized control adapter, or throws a PN-MIG-2007 naming
|
|
111
|
+
* `operation` when the migration was constructed without a `ControlStack`.
|
|
112
|
+
* Single home for the null-check that every DDL/DML method shares.
|
|
113
|
+
*/
|
|
114
|
+
private controlAdapterFor(operation: string): SqlControlAdapter<'postgres'> {
|
|
115
|
+
if (!this.controlAdapter) {
|
|
116
|
+
throw errorPostgresMigrationStackMissing(operation);
|
|
117
|
+
}
|
|
118
|
+
return this.controlAdapter;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* The typed, schema-qualified Postgres view over this migration's end-state
|
|
123
|
+
* contract — `this.endContract.namespace.<schema>.table.<name>`, etc. Throws
|
|
124
|
+
* if no `endContractJson` was provided.
|
|
125
|
+
*/
|
|
126
|
+
get endContract(): PostgresContractView<End> {
|
|
127
|
+
return this.#endView.endContract;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* The typed Postgres view over this migration's start-state contract, or
|
|
132
|
+
* `null` for a baseline migration (no `startContractJson`).
|
|
133
|
+
*/
|
|
134
|
+
get startContract(): PostgresContractView<Start> | null {
|
|
135
|
+
return this.#startView.startContract;
|
|
136
|
+
}
|
|
137
|
+
|
|
87
138
|
/**
|
|
88
139
|
* Instance-method wrapper around the free `dataTransform` factory that
|
|
89
140
|
* supplies the stored control adapter. Authors call this from inside
|
|
@@ -94,10 +145,7 @@ export abstract class PostgresMigration extends SqlMigration<
|
|
|
94
145
|
name: string,
|
|
95
146
|
options: DataTransformOptions,
|
|
96
147
|
): Promise<SqlMigrationPlanOperation<PostgresPlanTargetDetails>> {
|
|
97
|
-
|
|
98
|
-
throw errorPostgresMigrationStackMissing();
|
|
99
|
-
}
|
|
100
|
-
return dataTransform(contract, name, options, this.controlAdapter);
|
|
148
|
+
return dataTransform(contract, name, options, this.controlAdapterFor('dataTransform'));
|
|
101
149
|
}
|
|
102
150
|
|
|
103
151
|
/**
|
|
@@ -112,15 +160,12 @@ export abstract class PostgresMigration extends SqlMigration<
|
|
|
112
160
|
readonly columns: readonly DdlColumn[];
|
|
113
161
|
readonly constraints?: readonly DdlTableConstraint[];
|
|
114
162
|
}): Promise<SqlMigrationPlanOperation<PostgresPlanTargetDetails>> {
|
|
115
|
-
if (!this.controlAdapter) {
|
|
116
|
-
throw errorPostgresMigrationStackMissing();
|
|
117
|
-
}
|
|
118
163
|
return new CreateTableCall(
|
|
119
164
|
options.schema,
|
|
120
165
|
options.table,
|
|
121
166
|
options.columns,
|
|
122
167
|
options.constraints,
|
|
123
|
-
).toOp(this.
|
|
168
|
+
).toOp(this.controlAdapterFor('createTable'));
|
|
124
169
|
}
|
|
125
170
|
|
|
126
171
|
/**
|
|
@@ -132,10 +177,52 @@ export abstract class PostgresMigration extends SqlMigration<
|
|
|
132
177
|
readonly schema: string;
|
|
133
178
|
readonly ifNotExists?: boolean;
|
|
134
179
|
}): Promise<SqlMigrationPlanOperation<PostgresPlanTargetDetails>> {
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
180
|
+
return new CreateSchemaCall(options.schema).toOp(this.controlAdapterFor('createSchema'));
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
/**
|
|
184
|
+
* Emit a `CREATE TYPE ... AS ENUM (...)` migration operation for a managed
|
|
185
|
+
* native enum. Builds a typed DDL node and lowers it through the stored
|
|
186
|
+
* control adapter (members render in declaration order). Throws if no adapter
|
|
187
|
+
* is present.
|
|
188
|
+
*/
|
|
189
|
+
protected createNativeEnumType(options: {
|
|
190
|
+
readonly schema: string;
|
|
191
|
+
readonly typeName: string;
|
|
192
|
+
readonly members: readonly string[];
|
|
193
|
+
}): Promise<SqlMigrationPlanOperation<PostgresPlanTargetDetails>> {
|
|
194
|
+
return new CreateNativeEnumTypeCall(options.schema, options.typeName, options.members).toOp(
|
|
195
|
+
this.controlAdapterFor('createNativeEnumType'),
|
|
196
|
+
);
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
/**
|
|
200
|
+
* Emit a `DROP TYPE` migration operation for a managed native enum, lowered
|
|
201
|
+
* through the stored control adapter. Throws if no adapter is present.
|
|
202
|
+
*/
|
|
203
|
+
protected dropNativeEnumType(options: {
|
|
204
|
+
readonly schema: string;
|
|
205
|
+
readonly typeName: string;
|
|
206
|
+
}): Promise<SqlMigrationPlanOperation<PostgresPlanTargetDetails>> {
|
|
207
|
+
return new DropNativeEnumTypeCall(options.schema, options.typeName).toOp(
|
|
208
|
+
this.controlAdapterFor('dropNativeEnumType'),
|
|
209
|
+
);
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
/**
|
|
213
|
+
* Emit an `ALTER TYPE ... ADD VALUE` migration operation appending one
|
|
214
|
+
* member to a managed native enum, lowered through the stored control
|
|
215
|
+
* adapter. Throws if no adapter is present. Every appended value is its
|
|
216
|
+
* own operation — call this once per value to append more than one.
|
|
217
|
+
*/
|
|
218
|
+
protected addNativeEnumValue(options: {
|
|
219
|
+
readonly schema: string;
|
|
220
|
+
readonly typeName: string;
|
|
221
|
+
readonly value: string;
|
|
222
|
+
}): Promise<SqlMigrationPlanOperation<PostgresPlanTargetDetails>> {
|
|
223
|
+
return new AddNativeEnumValueCall(options.schema, options.typeName, options.value).toOp(
|
|
224
|
+
this.controlAdapterFor('addNativeEnumValue'),
|
|
225
|
+
);
|
|
139
226
|
}
|
|
140
227
|
|
|
141
228
|
protected addColumn(options: {
|
|
@@ -143,11 +230,8 @@ export abstract class PostgresMigration extends SqlMigration<
|
|
|
143
230
|
readonly table: string;
|
|
144
231
|
readonly column: DdlColumn;
|
|
145
232
|
}): Promise<SqlMigrationPlanOperation<PostgresPlanTargetDetails>> {
|
|
146
|
-
if (!this.controlAdapter) {
|
|
147
|
-
throw errorPostgresMigrationStackMissing();
|
|
148
|
-
}
|
|
149
233
|
return new AddColumnCall(options.schema, options.table, options.column).toOp(
|
|
150
|
-
this.
|
|
234
|
+
this.controlAdapterFor('addColumn'),
|
|
151
235
|
);
|
|
152
236
|
}
|
|
153
237
|
|
|
@@ -157,15 +241,12 @@ export abstract class PostgresMigration extends SqlMigration<
|
|
|
157
241
|
readonly constraint: string;
|
|
158
242
|
readonly columns: readonly string[];
|
|
159
243
|
}): Promise<SqlMigrationPlanOperation<PostgresPlanTargetDetails>> {
|
|
160
|
-
if (!this.controlAdapter) {
|
|
161
|
-
throw errorPostgresMigrationStackMissing();
|
|
162
|
-
}
|
|
163
244
|
return new AddPrimaryKeyCall(
|
|
164
245
|
options.schema,
|
|
165
246
|
options.table,
|
|
166
247
|
options.constraint,
|
|
167
248
|
options.columns,
|
|
168
|
-
).toOp(this.
|
|
249
|
+
).toOp(this.controlAdapterFor('addPrimaryKey'));
|
|
169
250
|
}
|
|
170
251
|
|
|
171
252
|
protected addUnique(options: {
|
|
@@ -174,15 +255,12 @@ export abstract class PostgresMigration extends SqlMigration<
|
|
|
174
255
|
readonly constraint: string;
|
|
175
256
|
readonly columns: readonly string[];
|
|
176
257
|
}): Promise<SqlMigrationPlanOperation<PostgresPlanTargetDetails>> {
|
|
177
|
-
if (!this.controlAdapter) {
|
|
178
|
-
throw errorPostgresMigrationStackMissing();
|
|
179
|
-
}
|
|
180
258
|
return new AddUniqueCall(
|
|
181
259
|
options.schema,
|
|
182
260
|
options.table,
|
|
183
261
|
options.constraint,
|
|
184
262
|
options.columns,
|
|
185
|
-
).toOp(this.
|
|
263
|
+
).toOp(this.controlAdapterFor('addUnique'));
|
|
186
264
|
}
|
|
187
265
|
|
|
188
266
|
protected addForeignKey(options: {
|
|
@@ -190,11 +268,8 @@ export abstract class PostgresMigration extends SqlMigration<
|
|
|
190
268
|
readonly table: string;
|
|
191
269
|
readonly foreignKey: ForeignKeySpec;
|
|
192
270
|
}): Promise<SqlMigrationPlanOperation<PostgresPlanTargetDetails>> {
|
|
193
|
-
if (!this.controlAdapter) {
|
|
194
|
-
throw errorPostgresMigrationStackMissing();
|
|
195
|
-
}
|
|
196
271
|
return new AddForeignKeyCall(options.schema, options.table, options.foreignKey).toOp(
|
|
197
|
-
this.
|
|
272
|
+
this.controlAdapterFor('addForeignKey'),
|
|
198
273
|
);
|
|
199
274
|
}
|
|
200
275
|
|
|
@@ -205,16 +280,13 @@ export abstract class PostgresMigration extends SqlMigration<
|
|
|
205
280
|
readonly column: string;
|
|
206
281
|
readonly values: readonly string[];
|
|
207
282
|
}): Promise<SqlMigrationPlanOperation<PostgresPlanTargetDetails>> {
|
|
208
|
-
if (!this.controlAdapter) {
|
|
209
|
-
throw errorPostgresMigrationStackMissing();
|
|
210
|
-
}
|
|
211
283
|
return new AddCheckConstraintCall(
|
|
212
284
|
options.schema,
|
|
213
285
|
options.table,
|
|
214
286
|
options.constraint,
|
|
215
287
|
options.column,
|
|
216
288
|
options.values,
|
|
217
|
-
).toOp(this.
|
|
289
|
+
).toOp(this.controlAdapterFor('addCheckConstraint'));
|
|
218
290
|
}
|
|
219
291
|
|
|
220
292
|
protected dropCheckConstraint(options: {
|
|
@@ -222,11 +294,8 @@ export abstract class PostgresMigration extends SqlMigration<
|
|
|
222
294
|
readonly table: string;
|
|
223
295
|
readonly constraint: string;
|
|
224
296
|
}): Promise<SqlMigrationPlanOperation<PostgresPlanTargetDetails>> {
|
|
225
|
-
if (!this.controlAdapter) {
|
|
226
|
-
throw errorPostgresMigrationStackMissing();
|
|
227
|
-
}
|
|
228
297
|
return new DropCheckConstraintCall(options.schema, options.table, options.constraint).toOp(
|
|
229
|
-
this.
|
|
298
|
+
this.controlAdapterFor('dropCheckConstraint'),
|
|
230
299
|
);
|
|
231
300
|
}
|
|
232
301
|
|
|
@@ -236,25 +305,21 @@ export abstract class PostgresMigration extends SqlMigration<
|
|
|
236
305
|
readonly constraint: string;
|
|
237
306
|
readonly kind?: 'foreignKey' | 'unique' | 'primaryKey';
|
|
238
307
|
}): Promise<SqlMigrationPlanOperation<PostgresPlanTargetDetails>> {
|
|
239
|
-
if (!this.controlAdapter) {
|
|
240
|
-
throw errorPostgresMigrationStackMissing();
|
|
241
|
-
}
|
|
242
308
|
return new DropConstraintCall(
|
|
243
309
|
options.schema,
|
|
244
310
|
options.table,
|
|
245
311
|
options.constraint,
|
|
246
312
|
options.kind ?? 'unique',
|
|
247
|
-
).toOp(this.
|
|
313
|
+
).toOp(this.controlAdapterFor('dropConstraint'));
|
|
248
314
|
}
|
|
249
315
|
|
|
250
316
|
protected dropTable(options: {
|
|
251
317
|
readonly schema: string;
|
|
252
318
|
readonly table: string;
|
|
253
319
|
}): Promise<SqlMigrationPlanOperation<PostgresPlanTargetDetails>> {
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
return new DropTableCall(options.schema, options.table).toOp(this.controlAdapter);
|
|
320
|
+
return new DropTableCall(options.schema, options.table).toOp(
|
|
321
|
+
this.controlAdapterFor('dropTable'),
|
|
322
|
+
);
|
|
258
323
|
}
|
|
259
324
|
|
|
260
325
|
protected dropColumn(options: {
|
|
@@ -262,11 +327,8 @@ export abstract class PostgresMigration extends SqlMigration<
|
|
|
262
327
|
readonly table: string;
|
|
263
328
|
readonly column: string;
|
|
264
329
|
}): Promise<SqlMigrationPlanOperation<PostgresPlanTargetDetails>> {
|
|
265
|
-
if (!this.controlAdapter) {
|
|
266
|
-
throw errorPostgresMigrationStackMissing();
|
|
267
|
-
}
|
|
268
330
|
return new DropColumnCall(options.schema, options.table, options.column).toOp(
|
|
269
|
-
this.
|
|
331
|
+
this.controlAdapterFor('dropColumn'),
|
|
270
332
|
);
|
|
271
333
|
}
|
|
272
334
|
|
|
@@ -276,15 +338,12 @@ export abstract class PostgresMigration extends SqlMigration<
|
|
|
276
338
|
readonly column: string;
|
|
277
339
|
readonly options: AlterColumnTypeOptions;
|
|
278
340
|
}): Promise<SqlMigrationPlanOperation<PostgresPlanTargetDetails>> {
|
|
279
|
-
if (!this.controlAdapter) {
|
|
280
|
-
throw errorPostgresMigrationStackMissing();
|
|
281
|
-
}
|
|
282
341
|
return new AlterColumnTypeCall(
|
|
283
342
|
options.schema,
|
|
284
343
|
options.table,
|
|
285
344
|
options.column,
|
|
286
345
|
options.options,
|
|
287
|
-
).toOp(this.
|
|
346
|
+
).toOp(this.controlAdapterFor('alterColumnType'));
|
|
288
347
|
}
|
|
289
348
|
|
|
290
349
|
protected setNotNull(options: {
|
|
@@ -292,11 +351,8 @@ export abstract class PostgresMigration extends SqlMigration<
|
|
|
292
351
|
readonly table: string;
|
|
293
352
|
readonly column: string;
|
|
294
353
|
}): Promise<SqlMigrationPlanOperation<PostgresPlanTargetDetails>> {
|
|
295
|
-
if (!this.controlAdapter) {
|
|
296
|
-
throw errorPostgresMigrationStackMissing();
|
|
297
|
-
}
|
|
298
354
|
return new SetNotNullCall(options.schema, options.table, options.column).toOp(
|
|
299
|
-
this.
|
|
355
|
+
this.controlAdapterFor('setNotNull'),
|
|
300
356
|
);
|
|
301
357
|
}
|
|
302
358
|
|
|
@@ -305,11 +361,8 @@ export abstract class PostgresMigration extends SqlMigration<
|
|
|
305
361
|
readonly table: string;
|
|
306
362
|
readonly column: string;
|
|
307
363
|
}): Promise<SqlMigrationPlanOperation<PostgresPlanTargetDetails>> {
|
|
308
|
-
if (!this.controlAdapter) {
|
|
309
|
-
throw errorPostgresMigrationStackMissing();
|
|
310
|
-
}
|
|
311
364
|
return new DropNotNullCall(options.schema, options.table, options.column).toOp(
|
|
312
|
-
this.
|
|
365
|
+
this.controlAdapterFor('dropNotNull'),
|
|
313
366
|
);
|
|
314
367
|
}
|
|
315
368
|
|
|
@@ -320,16 +373,13 @@ export abstract class PostgresMigration extends SqlMigration<
|
|
|
320
373
|
readonly defaultSql: string;
|
|
321
374
|
readonly operationClass?: 'additive' | 'widening';
|
|
322
375
|
}): Promise<SqlMigrationPlanOperation<PostgresPlanTargetDetails>> {
|
|
323
|
-
if (!this.controlAdapter) {
|
|
324
|
-
throw errorPostgresMigrationStackMissing();
|
|
325
|
-
}
|
|
326
376
|
return new SetDefaultCall(
|
|
327
377
|
options.schema,
|
|
328
378
|
options.table,
|
|
329
379
|
options.column,
|
|
330
380
|
options.defaultSql,
|
|
331
381
|
options.operationClass,
|
|
332
|
-
).toOp(this.
|
|
382
|
+
).toOp(this.controlAdapterFor('setDefault'));
|
|
333
383
|
}
|
|
334
384
|
|
|
335
385
|
protected dropDefault(options: {
|
|
@@ -337,11 +387,8 @@ export abstract class PostgresMigration extends SqlMigration<
|
|
|
337
387
|
readonly table: string;
|
|
338
388
|
readonly column: string;
|
|
339
389
|
}): Promise<SqlMigrationPlanOperation<PostgresPlanTargetDetails>> {
|
|
340
|
-
if (!this.controlAdapter) {
|
|
341
|
-
throw errorPostgresMigrationStackMissing();
|
|
342
|
-
}
|
|
343
390
|
return new DropDefaultCall(options.schema, options.table, options.column).toOp(
|
|
344
|
-
this.
|
|
391
|
+
this.controlAdapterFor('dropDefault'),
|
|
345
392
|
);
|
|
346
393
|
}
|
|
347
394
|
|
|
@@ -352,16 +399,13 @@ export abstract class PostgresMigration extends SqlMigration<
|
|
|
352
399
|
readonly columns: readonly string[];
|
|
353
400
|
readonly extras?: CreateIndexExtras;
|
|
354
401
|
}): Promise<SqlMigrationPlanOperation<PostgresPlanTargetDetails>> {
|
|
355
|
-
if (!this.controlAdapter) {
|
|
356
|
-
throw errorPostgresMigrationStackMissing();
|
|
357
|
-
}
|
|
358
402
|
return new CreateIndexCall(
|
|
359
403
|
options.schema,
|
|
360
404
|
options.table,
|
|
361
405
|
options.index,
|
|
362
406
|
options.columns,
|
|
363
407
|
options.extras,
|
|
364
|
-
).toOp(this.
|
|
408
|
+
).toOp(this.controlAdapterFor('createIndex'));
|
|
365
409
|
}
|
|
366
410
|
|
|
367
411
|
protected dropIndex(options: {
|
|
@@ -369,11 +413,8 @@ export abstract class PostgresMigration extends SqlMigration<
|
|
|
369
413
|
readonly table: string;
|
|
370
414
|
readonly index: string;
|
|
371
415
|
}): Promise<SqlMigrationPlanOperation<PostgresPlanTargetDetails>> {
|
|
372
|
-
if (!this.controlAdapter) {
|
|
373
|
-
throw errorPostgresMigrationStackMissing();
|
|
374
|
-
}
|
|
375
416
|
return new DropIndexCall(options.schema, options.table, options.index).toOp(
|
|
376
|
-
this.
|
|
417
|
+
this.controlAdapterFor('dropIndex'),
|
|
377
418
|
);
|
|
378
419
|
}
|
|
379
420
|
|
|
@@ -383,9 +424,60 @@ export abstract class PostgresMigration extends SqlMigration<
|
|
|
383
424
|
readonly id: string;
|
|
384
425
|
readonly label?: string;
|
|
385
426
|
}): Promise<SqlMigrationPlanOperation<PostgresPlanTargetDetails>> {
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
427
|
+
return installExtension(options, this.controlAdapterFor('installExtension'));
|
|
428
|
+
}
|
|
429
|
+
|
|
430
|
+
protected enableRowLevelSecurity(options: {
|
|
431
|
+
readonly schema: string;
|
|
432
|
+
readonly table: string;
|
|
433
|
+
}): Promise<SqlMigrationPlanOperation<PostgresPlanTargetDetails>> {
|
|
434
|
+
return new EnableRowLevelSecurityCall(options.schema, options.table).toOp(
|
|
435
|
+
this.controlAdapterFor('enableRowLevelSecurity'),
|
|
436
|
+
);
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
protected disableRowLevelSecurity(options: {
|
|
440
|
+
readonly schema: string;
|
|
441
|
+
readonly table: string;
|
|
442
|
+
}): Promise<SqlMigrationPlanOperation<PostgresPlanTargetDetails>> {
|
|
443
|
+
return new DisableRowLevelSecurityCall(options.schema, options.table).toOp(
|
|
444
|
+
this.controlAdapterFor('disableRowLevelSecurity'),
|
|
445
|
+
);
|
|
446
|
+
}
|
|
447
|
+
|
|
448
|
+
protected createRlsPolicy(options: {
|
|
449
|
+
readonly schema: string;
|
|
450
|
+
readonly table: string;
|
|
451
|
+
readonly policy: PostgresRlsPolicyInput;
|
|
452
|
+
}): Promise<SqlMigrationPlanOperation<PostgresPlanTargetDetails>> {
|
|
453
|
+
return new CreatePostgresRlsPolicyCall(
|
|
454
|
+
options.schema,
|
|
455
|
+
options.table,
|
|
456
|
+
new PostgresRlsPolicy(options.policy),
|
|
457
|
+
).toOp(this.controlAdapterFor('createRlsPolicy'));
|
|
458
|
+
}
|
|
459
|
+
|
|
460
|
+
protected dropRlsPolicy(options: {
|
|
461
|
+
readonly schema: string;
|
|
462
|
+
readonly table: string;
|
|
463
|
+
readonly policy: string;
|
|
464
|
+
}): Promise<SqlMigrationPlanOperation<PostgresPlanTargetDetails>> {
|
|
465
|
+
return new DropPostgresRlsPolicyCall(options.schema, options.table, options.policy).toOp(
|
|
466
|
+
this.controlAdapterFor('dropRlsPolicy'),
|
|
467
|
+
);
|
|
468
|
+
}
|
|
469
|
+
|
|
470
|
+
protected renameRlsPolicy(options: {
|
|
471
|
+
readonly schema: string;
|
|
472
|
+
readonly table: string;
|
|
473
|
+
readonly from: string;
|
|
474
|
+
readonly to: string;
|
|
475
|
+
}): Promise<SqlMigrationPlanOperation<PostgresPlanTargetDetails>> {
|
|
476
|
+
return new RenamePostgresRlsPolicyCall(
|
|
477
|
+
options.schema,
|
|
478
|
+
options.table,
|
|
479
|
+
options.from,
|
|
480
|
+
options.to,
|
|
481
|
+
).toOp(this.controlAdapterFor('renameRlsPolicy'));
|
|
390
482
|
}
|
|
391
483
|
}
|
|
@@ -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
|
}
|