@prisma-next/target-postgres 0.13.0-dev.14 → 0.13.0-dev.16
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/control.mjs +15 -18
- package/dist/control.mjs.map +1 -1
- package/dist/{data-transform-D25tLeYU.mjs → data-transform-BOWpliq8.mjs} +9 -17
- package/dist/data-transform-BOWpliq8.mjs.map +1 -0
- package/dist/{data-transform-DGOqcLrf.d.mts → data-transform-DDgWdB5o.d.mts} +2 -2
- package/dist/data-transform-DDgWdB5o.d.mts.map +1 -0
- package/dist/data-transform.d.mts +1 -1
- package/dist/data-transform.mjs +1 -1
- package/dist/{issue-planner-B0A7RFN2.mjs → issue-planner-399UDGjU.mjs} +10 -3
- package/dist/issue-planner-399UDGjU.mjs.map +1 -0
- package/dist/issue-planner.d.mts +1 -1
- package/dist/issue-planner.d.mts.map +1 -1
- package/dist/issue-planner.mjs +1 -1
- package/dist/migration.d.mts +2 -2
- package/dist/migration.mjs +3 -3
- package/dist/{op-factory-call-Clp7Zr1z.mjs → op-factory-call-1URu-iTb.mjs} +16 -8
- package/dist/op-factory-call-1URu-iTb.mjs.map +1 -0
- package/dist/{op-factory-call-DMA86_2D.d.mts → op-factory-call-DEvD9sbB.d.mts} +5 -5
- package/dist/op-factory-call-DEvD9sbB.d.mts.map +1 -0
- package/dist/op-factory-call.d.mts +1 -1
- package/dist/op-factory-call.mjs +1 -1
- package/dist/{planner-DID7RZCQ.mjs → planner-Dh6oTlSF.mjs} +3 -3
- package/dist/planner-Dh6oTlSF.mjs.map +1 -0
- package/dist/{planner-produced-postgres-migration-B4EDvLdz.d.mts → planner-produced-postgres-migration-CIX9peJN.d.mts} +5 -6
- package/dist/planner-produced-postgres-migration-CIX9peJN.d.mts.map +1 -0
- package/dist/{planner-produced-postgres-migration-B8gZBPOR.mjs → planner-produced-postgres-migration-CzP4ttHe.mjs} +6 -4
- package/dist/planner-produced-postgres-migration-CzP4ttHe.mjs.map +1 -0
- package/dist/planner-produced-postgres-migration.d.mts +1 -1
- package/dist/planner-produced-postgres-migration.mjs +1 -1
- package/dist/planner.d.mts +4 -4
- package/dist/planner.d.mts.map +1 -1
- package/dist/planner.mjs +1 -1
- package/dist/{postgres-migration-BCQEjFHK.mjs → postgres-migration-DYLAgHBj.mjs} +3 -3
- package/dist/{postgres-migration-BCQEjFHK.mjs.map → postgres-migration-DYLAgHBj.mjs.map} +1 -1
- package/dist/{postgres-migration-DZ_gLUOW.d.mts → postgres-migration-h_DA3LRq.d.mts} +5 -5
- package/dist/postgres-migration-h_DA3LRq.d.mts.map +1 -0
- package/dist/{render-ops-BpjstrKQ.mjs → render-ops-BREh1kHe.mjs} +10 -5
- package/dist/render-ops-BREh1kHe.mjs.map +1 -0
- package/dist/render-ops.d.mts +2 -2
- package/dist/render-ops.d.mts.map +1 -1
- package/dist/render-ops.mjs +1 -1
- package/package.json +17 -17
- package/src/core/migrations/issue-planner.ts +24 -3
- package/src/core/migrations/op-factory-call.ts +22 -9
- package/src/core/migrations/operations/data-transform.ts +15 -18
- package/src/core/migrations/planner-produced-postgres-migration.ts +15 -7
- package/src/core/migrations/planner.ts +6 -4
- package/src/core/migrations/postgres-migration.ts +3 -3
- package/src/core/migrations/render-ops.ts +26 -13
- package/src/core/migrations/runner.ts +26 -16
- package/dist/data-transform-D25tLeYU.mjs.map +0 -1
- package/dist/data-transform-DGOqcLrf.d.mts.map +0 -1
- package/dist/issue-planner-B0A7RFN2.mjs.map +0 -1
- package/dist/op-factory-call-Clp7Zr1z.mjs.map +0 -1
- package/dist/op-factory-call-DMA86_2D.d.mts.map +0 -1
- package/dist/planner-DID7RZCQ.mjs.map +0 -1
- package/dist/planner-produced-postgres-migration-B4EDvLdz.d.mts.map +0 -1
- package/dist/planner-produced-postgres-migration-B8gZBPOR.mjs.map +0 -1
- package/dist/postgres-migration-DZ_gLUOW.d.mts.map +0 -1
- package/dist/render-ops-BpjstrKQ.mjs.map +0 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { t as PostgresPlanTargetDetails } from "./planner-target-details-CIY6tLeo.mjs";
|
|
2
|
-
import { n as DataTransformOptions } from "./data-transform-
|
|
2
|
+
import { n as DataTransformOptions } from "./data-transform-DDgWdB5o.mjs";
|
|
3
3
|
import { DdlColumn, DdlTableConstraint } from "@prisma-next/sql-relational-core/ast";
|
|
4
4
|
import { SqlMigrationPlanOperation } from "@prisma-next/family-sql/control";
|
|
5
5
|
import { SqlStorage } from "@prisma-next/sql-contract/types";
|
|
@@ -44,7 +44,7 @@ declare abstract class PostgresMigration extends Migration<PostgresPlanTargetDet
|
|
|
44
44
|
* supplies the stored control adapter. Authors call this from inside
|
|
45
45
|
* `get operations()`; the adapter argument is hidden from the call site.
|
|
46
46
|
*/
|
|
47
|
-
protected dataTransform<TContract extends Contract<SqlStorage>>(contract: TContract, name: string, options: DataTransformOptions): SqlMigrationPlanOperation<PostgresPlanTargetDetails
|
|
47
|
+
protected dataTransform<TContract extends Contract<SqlStorage>>(contract: TContract, name: string, options: DataTransformOptions): Promise<SqlMigrationPlanOperation<PostgresPlanTargetDetails>>;
|
|
48
48
|
/**
|
|
49
49
|
* Emit a `CREATE TABLE` migration operation. Builds a typed DDL node from
|
|
50
50
|
* the supplied options and lowers it through the stored control adapter.
|
|
@@ -56,7 +56,7 @@ declare abstract class PostgresMigration extends Migration<PostgresPlanTargetDet
|
|
|
56
56
|
readonly ifNotExists?: boolean;
|
|
57
57
|
readonly columns: readonly DdlColumn[];
|
|
58
58
|
readonly constraints?: readonly DdlTableConstraint[];
|
|
59
|
-
}): SqlMigrationPlanOperation<PostgresPlanTargetDetails
|
|
59
|
+
}): Promise<SqlMigrationPlanOperation<PostgresPlanTargetDetails>>;
|
|
60
60
|
/**
|
|
61
61
|
* Emit a `CREATE SCHEMA` migration operation. Builds a typed DDL node from
|
|
62
62
|
* the supplied options and lowers it through the stored control adapter.
|
|
@@ -65,8 +65,8 @@ declare abstract class PostgresMigration extends Migration<PostgresPlanTargetDet
|
|
|
65
65
|
protected createSchema(options: {
|
|
66
66
|
readonly schema: string;
|
|
67
67
|
readonly ifNotExists?: boolean;
|
|
68
|
-
}): SqlMigrationPlanOperation<PostgresPlanTargetDetails
|
|
68
|
+
}): Promise<SqlMigrationPlanOperation<PostgresPlanTargetDetails>>;
|
|
69
69
|
}
|
|
70
70
|
//#endregion
|
|
71
71
|
export { PostgresMigration as t };
|
|
72
|
-
//# sourceMappingURL=postgres-migration-
|
|
72
|
+
//# sourceMappingURL=postgres-migration-h_DA3LRq.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"postgres-migration-h_DA3LRq.d.mts","names":[],"sources":["../src/core/migrations/postgres-migration.ts"],"mappings":";;;;;;;;;;;;;AAiCA;;;;;;;;;;;;;;;;;;uBAAsB,iBAAA,SAA0B,SAAA,CAC9C,yBAAA;EAAA,SAGS,QAAA;EAmEL;;;;;;EAAA,mBA3De,cAAA,EAAgB,iBAAA;cAEvB,KAAA,GAAQ,YAAA;EAFe;;;;;EAAA,UAiBzB,aAAA,mBAAgC,QAAA,CAAS,UAAA,GACjD,QAAA,EAAU,SAAA,EACV,IAAA,UACA,OAAA,EAAS,oBAAA,GACR,OAAA,CAAQ,yBAAA,CAA0B,yBAAA;EAJK;;;;;EAAA,UAgBhC,WAAA,CAAY,OAAA;IAAA,SACX,MAAA;IAAA,SACA,KAAA;IAAA,SACA,WAAA;IAAA,SACA,OAAA,WAAkB,SAAA;IAAA,SAClB,WAAA,YAAuB,kBAAA;EAAA,IAC9B,OAAA,CAAQ,yBAAA,CAA0B,yBAAA;EAJ3B;;;;;EAAA,UAqBD,YAAA,CAAa,OAAA;IAAA,SACZ,MAAA;IAAA,SACA,WAAA;EAAA,IACP,OAAA,CAAQ,yBAAA,CAA0B,yBAAA;AAAA"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { blindCast } from "@prisma-next/utils/casts";
|
|
2
|
+
import { isThenable } from "@prisma-next/utils/promise";
|
|
2
3
|
//#region src/core/migrations/render-ops.ts
|
|
3
4
|
/**
|
|
4
5
|
* Asserts an op materialised by an `OpFactoryCall` targets postgres. The
|
|
@@ -8,17 +9,21 @@ import { blindCast } from "@prisma-next/utils/casts";
|
|
|
8
9
|
* place to fail loudly with op metadata (`id` + `target.id`).
|
|
9
10
|
*/
|
|
10
11
|
function assertPostgresOp(op, callFactoryName) {
|
|
11
|
-
const targetId = op.target?.id;
|
|
12
|
+
const targetId = blindCast(op).target?.id;
|
|
12
13
|
if (targetId !== "postgres") throw new Error(`renderOps: expected postgres op but got target.id="${String(targetId)}" for op.id="${op.id}" (factoryName="${callFactoryName}"). An OpFactoryCall produced an op for a different target on the postgres planner path; check the call's target binding.`);
|
|
13
14
|
}
|
|
14
15
|
function renderOps(calls, lowerer) {
|
|
15
16
|
return calls.map((c) => {
|
|
16
|
-
const
|
|
17
|
-
|
|
18
|
-
|
|
17
|
+
const opOrPromise = blindCast(c).toOp(lowerer);
|
|
18
|
+
if (isThenable(opOrPromise)) return opOrPromise.then((op) => {
|
|
19
|
+
assertPostgresOp(op, c.factoryName);
|
|
20
|
+
return op;
|
|
21
|
+
});
|
|
22
|
+
assertPostgresOp(opOrPromise, c.factoryName);
|
|
23
|
+
return opOrPromise;
|
|
19
24
|
});
|
|
20
25
|
}
|
|
21
26
|
//#endregion
|
|
22
27
|
export { renderOps as t };
|
|
23
28
|
|
|
24
|
-
//# sourceMappingURL=render-ops-
|
|
29
|
+
//# sourceMappingURL=render-ops-BREh1kHe.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"render-ops-BREh1kHe.mjs","names":[],"sources":["../src/core/migrations/render-ops.ts"],"sourcesContent":["import type { SqlMigrationPlanOperation } from '@prisma-next/family-sql/control';\nimport type { ExecuteRequestLowerer } from '@prisma-next/family-sql/control-adapter';\nimport type {\n MigrationPlanOperation,\n OpFactoryCall,\n} from '@prisma-next/framework-components/control';\nimport { blindCast } from '@prisma-next/utils/casts';\nimport { isThenable } from '@prisma-next/utils/promise';\nimport type { PostgresPlanTargetDetails } from './planner-target-details';\n\ntype Op = SqlMigrationPlanOperation<PostgresPlanTargetDetails>;\n\n/**\n * Asserts an op materialised by an `OpFactoryCall` targets postgres. The\n * extension surface lets any contributor emit calls, so this is the\n * integration boundary where a stray non-postgres op would otherwise\n * silently flow through to postgres-shaped renderers — exactly the\n * place to fail loudly with op metadata (`id` + `target.id`).\n */\nfunction assertPostgresOp(op: MigrationPlanOperation, callFactoryName: string): asserts op is Op {\n const targetId = blindCast<\n { target?: { id?: string } },\n 'op.target is present on concrete SqlMigrationPlanOperation but absent on the framework MigrationPlanOperation base'\n >(op).target?.id;\n if (targetId !== 'postgres') {\n throw new Error(\n `renderOps: expected postgres op but got target.id=\"${String(targetId)}\" for op.id=\"${op.id}\" (factoryName=\"${callFactoryName}\"). An OpFactoryCall produced an op for a different target on the postgres planner path; check the call's target binding.`,\n );\n }\n}\n\nexport function renderOps(\n calls: readonly OpFactoryCall[],\n lowerer?: ExecuteRequestLowerer,\n): (Op | Promise<Op>)[] {\n return calls.map((c) => {\n const opOrPromise = blindCast<\n { toOp(lowerer?: ExecuteRequestLowerer): Op | Promise<Op> },\n 'PG OpFactoryCall.toOp accepts an optional ExecuteRequestLowerer; the framework interface omits it because not all targets need a lowerer — the PG target overrides with this extended signature'\n >(c).toOp(lowerer);\n if (isThenable(opOrPromise)) {\n return opOrPromise.then((op) => {\n assertPostgresOp(op, c.factoryName);\n return op;\n });\n }\n assertPostgresOp(opOrPromise, c.factoryName);\n return opOrPromise;\n });\n}\n"],"mappings":";;;;;;;;;;AAmBA,SAAS,iBAAiB,IAA4B,iBAA2C;CAC/F,MAAM,WAAW,UAGf,EAAE,CAAC,CAAC,QAAQ;CACd,IAAI,aAAa,YACf,MAAM,IAAI,MACR,sDAAsD,OAAO,QAAQ,EAAE,eAAe,GAAG,GAAG,kBAAkB,gBAAgB,0HAChI;AAEJ;AAEA,SAAgB,UACd,OACA,SACsB;CACtB,OAAO,MAAM,KAAK,MAAM;EACtB,MAAM,cAAc,UAGlB,CAAC,CAAC,CAAC,KAAK,OAAO;EACjB,IAAI,WAAW,WAAW,GACxB,OAAO,YAAY,MAAM,OAAO;GAC9B,iBAAiB,IAAI,EAAE,WAAW;GAClC,OAAO;EACT,CAAC;EAEH,iBAAiB,aAAa,EAAE,WAAW;EAC3C,OAAO;CACT,CAAC;AACH"}
|
package/dist/render-ops.d.mts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { t as PostgresPlanTargetDetails } from "./planner-target-details-CIY6tLeo.mjs";
|
|
2
2
|
import { SqlMigrationPlanOperation } from "@prisma-next/family-sql/control";
|
|
3
3
|
import { OpFactoryCall } from "@prisma-next/framework-components/control";
|
|
4
|
-
import {
|
|
4
|
+
import { ExecuteRequestLowerer } from "@prisma-next/family-sql/control-adapter";
|
|
5
5
|
|
|
6
6
|
//#region src/core/migrations/render-ops.d.ts
|
|
7
7
|
type Op = SqlMigrationPlanOperation<PostgresPlanTargetDetails>;
|
|
8
|
-
declare function renderOps(calls: readonly OpFactoryCall[], lowerer?:
|
|
8
|
+
declare function renderOps(calls: readonly OpFactoryCall[], lowerer?: ExecuteRequestLowerer): (Op | Promise<Op>)[];
|
|
9
9
|
//#endregion
|
|
10
10
|
export { renderOps };
|
|
11
11
|
//# sourceMappingURL=render-ops.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"render-ops.d.mts","names":[],"sources":["../src/core/migrations/render-ops.ts"],"mappings":";;;;;;
|
|
1
|
+
{"version":3,"file":"render-ops.d.mts","names":[],"sources":["../src/core/migrations/render-ops.ts"],"mappings":";;;;;;KAUK,EAAA,GAAK,yBAAyB,CAAC,yBAAA;AAAA,iBAqBpB,SAAA,CACd,KAAA,WAAgB,aAAA,IAChB,OAAA,GAAU,qBAAA,IACR,EAAA,GAAK,OAAA,CAAQ,EAAA"}
|
package/dist/render-ops.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { t as renderOps } from "./render-ops-
|
|
1
|
+
import { t as renderOps } from "./render-ops-BREh1kHe.mjs";
|
|
2
2
|
export { renderOps };
|
package/package.json
CHANGED
|
@@ -1,32 +1,32 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@prisma-next/target-postgres",
|
|
3
|
-
"version": "0.13.0-dev.
|
|
3
|
+
"version": "0.13.0-dev.16",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"sideEffects": false,
|
|
7
7
|
"description": "Postgres target pack for Prisma Next",
|
|
8
8
|
"dependencies": {
|
|
9
|
-
"@prisma-next/cli": "0.13.0-dev.
|
|
10
|
-
"@prisma-next/contract": "0.13.0-dev.
|
|
11
|
-
"@prisma-next/errors": "0.13.0-dev.
|
|
12
|
-
"@prisma-next/family-sql": "0.13.0-dev.
|
|
13
|
-
"@prisma-next/framework-components": "0.13.0-dev.
|
|
14
|
-
"@prisma-next/migration-tools": "0.13.0-dev.
|
|
15
|
-
"@prisma-next/ts-render": "0.13.0-dev.
|
|
16
|
-
"@prisma-next/sql-contract": "0.13.0-dev.
|
|
17
|
-
"@prisma-next/sql-errors": "0.13.0-dev.
|
|
18
|
-
"@prisma-next/sql-operations": "0.13.0-dev.
|
|
19
|
-
"@prisma-next/sql-relational-core": "0.13.0-dev.
|
|
20
|
-
"@prisma-next/sql-schema-ir": "0.13.0-dev.
|
|
21
|
-
"@prisma-next/utils": "0.13.0-dev.
|
|
9
|
+
"@prisma-next/cli": "0.13.0-dev.16",
|
|
10
|
+
"@prisma-next/contract": "0.13.0-dev.16",
|
|
11
|
+
"@prisma-next/errors": "0.13.0-dev.16",
|
|
12
|
+
"@prisma-next/family-sql": "0.13.0-dev.16",
|
|
13
|
+
"@prisma-next/framework-components": "0.13.0-dev.16",
|
|
14
|
+
"@prisma-next/migration-tools": "0.13.0-dev.16",
|
|
15
|
+
"@prisma-next/ts-render": "0.13.0-dev.16",
|
|
16
|
+
"@prisma-next/sql-contract": "0.13.0-dev.16",
|
|
17
|
+
"@prisma-next/sql-errors": "0.13.0-dev.16",
|
|
18
|
+
"@prisma-next/sql-operations": "0.13.0-dev.16",
|
|
19
|
+
"@prisma-next/sql-relational-core": "0.13.0-dev.16",
|
|
20
|
+
"@prisma-next/sql-schema-ir": "0.13.0-dev.16",
|
|
21
|
+
"@prisma-next/utils": "0.13.0-dev.16",
|
|
22
22
|
"@standard-schema/spec": "^1.1.0",
|
|
23
23
|
"arktype": "^2.2.0",
|
|
24
24
|
"pathe": "^2.0.3"
|
|
25
25
|
},
|
|
26
26
|
"devDependencies": {
|
|
27
|
-
"@prisma-next/test-utils": "0.13.0-dev.
|
|
28
|
-
"@prisma-next/tsconfig": "0.13.0-dev.
|
|
29
|
-
"@prisma-next/tsdown": "0.13.0-dev.
|
|
27
|
+
"@prisma-next/test-utils": "0.13.0-dev.16",
|
|
28
|
+
"@prisma-next/tsconfig": "0.13.0-dev.16",
|
|
29
|
+
"@prisma-next/tsdown": "0.13.0-dev.16",
|
|
30
30
|
"tsdown": "0.22.1",
|
|
31
31
|
"typescript": "5.9.3",
|
|
32
32
|
"vitest": "4.1.8"
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
* through `mapIssueToCall` for the default case.
|
|
9
9
|
*/
|
|
10
10
|
|
|
11
|
-
import type { Contract } from '@prisma-next/contract/types';
|
|
11
|
+
import type { Contract, JsonValue } from '@prisma-next/contract/types';
|
|
12
12
|
import type {
|
|
13
13
|
CodecControlHooks,
|
|
14
14
|
MigrationOperationPolicy,
|
|
@@ -25,9 +25,11 @@ import type {
|
|
|
25
25
|
StorageTable,
|
|
26
26
|
StorageTypeInstance,
|
|
27
27
|
} from '@prisma-next/sql-contract/types';
|
|
28
|
-
import type { DdlColumn, DdlTableConstraint } from '@prisma-next/sql-relational-core/ast';
|
|
28
|
+
import type { CodecRef, DdlColumn, DdlTableConstraint } from '@prisma-next/sql-relational-core/ast';
|
|
29
29
|
import * as contractFree from '@prisma-next/sql-relational-core/contract-free';
|
|
30
30
|
import type { SqlSchemaIR } from '@prisma-next/sql-schema-ir/types';
|
|
31
|
+
import { blindCast } from '@prisma-next/utils/casts';
|
|
32
|
+
import { ifDefined } from '@prisma-next/utils/defined';
|
|
31
33
|
import type { Result } from '@prisma-next/utils/result';
|
|
32
34
|
import { notOk, ok } from '@prisma-next/utils/result';
|
|
33
35
|
import { PostgresEnumType } from '../postgres-enum-type';
|
|
@@ -65,6 +67,7 @@ import {
|
|
|
65
67
|
type StrategyContext,
|
|
66
68
|
tableAt,
|
|
67
69
|
} from './planner-strategies';
|
|
70
|
+
import { resolveColumnTypeMetadata } from './planner-type-resolution';
|
|
68
71
|
|
|
69
72
|
export type { CallMigrationStrategy, StrategyContext };
|
|
70
73
|
|
|
@@ -214,9 +217,27 @@ function toDdlColumn(
|
|
|
214
217
|
): DdlColumn {
|
|
215
218
|
const typeSql = buildColumnTypeSql(column, codecHooks, storageTypes);
|
|
216
219
|
const ddlDefault = postgresDefaultToDdlColumnDefault(column.default);
|
|
220
|
+
const resolved = resolveColumnTypeMetadata(
|
|
221
|
+
column,
|
|
222
|
+
storageTypes as Record<string, StorageTypeInstance | PostgresEnumStorageEntry>,
|
|
223
|
+
);
|
|
224
|
+
const codecRef: CodecRef | undefined = resolved.codecId
|
|
225
|
+
? {
|
|
226
|
+
codecId: resolved.codecId,
|
|
227
|
+
...(resolved.typeParams !== undefined
|
|
228
|
+
? {
|
|
229
|
+
typeParams: blindCast<
|
|
230
|
+
JsonValue,
|
|
231
|
+
'resolved.typeParams is JsonValue-shaped storage metadata; the narrowed (non-undefined) value lands in CodecRef.typeParams which is JsonValue'
|
|
232
|
+
>(resolved.typeParams),
|
|
233
|
+
}
|
|
234
|
+
: {}),
|
|
235
|
+
}
|
|
236
|
+
: undefined;
|
|
217
237
|
return contractFree.col(name, typeSql, {
|
|
218
238
|
...(!column.nullable ? { notNull: true } : {}),
|
|
219
|
-
...(
|
|
239
|
+
...ifDefined('default', ddlDefault),
|
|
240
|
+
...ifDefined('codecRef', codecRef),
|
|
220
241
|
});
|
|
221
242
|
}
|
|
222
243
|
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
|
|
23
23
|
import { errorUnfilledPlaceholder } from '@prisma-next/errors/migration';
|
|
24
24
|
import type { SqlMigrationPlanOperation } from '@prisma-next/family-sql/control';
|
|
25
|
-
import type { Lowerer } from '@prisma-next/family-sql/control-adapter';
|
|
25
|
+
import type { ExecuteRequestLowerer, Lowerer } from '@prisma-next/family-sql/control-adapter';
|
|
26
26
|
import type {
|
|
27
27
|
OpFactoryCall as FrameworkOpFactoryCall,
|
|
28
28
|
MigrationOperationClass,
|
|
@@ -36,6 +36,7 @@ import type {
|
|
|
36
36
|
import { FunctionColumnDefault, LiteralColumnDefault } from '@prisma-next/sql-relational-core/ast';
|
|
37
37
|
import { type ImportRequirement, jsonToTsSource, TsExpression } from '@prisma-next/ts-render';
|
|
38
38
|
import { blindCast } from '@prisma-next/utils/casts';
|
|
39
|
+
import { ifDefined } from '@prisma-next/utils/defined';
|
|
39
40
|
import * as contractFreeDdl from '../../contract-free/ddl';
|
|
40
41
|
import { escapeLiteral, quoteIdentifier } from '../sql-utils';
|
|
41
42
|
import type { PostgresColumnDefault } from '../types';
|
|
@@ -85,7 +86,7 @@ abstract class PostgresOpFactoryCallNode extends TsExpression implements Framewo
|
|
|
85
86
|
abstract readonly factoryName: string;
|
|
86
87
|
abstract readonly operationClass: MigrationOperationClass;
|
|
87
88
|
abstract readonly label: string;
|
|
88
|
-
abstract toOp(lowerer?: Lowerer): Op
|
|
89
|
+
abstract toOp(lowerer?: Lowerer): Op | Promise<Op>;
|
|
89
90
|
|
|
90
91
|
importRequirements(): readonly ImportRequirement[] {
|
|
91
92
|
return [{ moduleSpecifier: POSTGRES_MIGRATION_FACADE, symbol: this.factoryName }];
|
|
@@ -213,7 +214,7 @@ export class CreateTableCall extends PostgresOpFactoryCallNode {
|
|
|
213
214
|
this.freeze();
|
|
214
215
|
}
|
|
215
216
|
|
|
216
|
-
toOp(lowerer?:
|
|
217
|
+
async toOp(lowerer?: ExecuteRequestLowerer): Promise<Op> {
|
|
217
218
|
if (lowerer === undefined) {
|
|
218
219
|
throw new Error(
|
|
219
220
|
`CreateTableCall.toOp: a DDL lowerer is required on the Postgres planner path (table "${this.tableName}"). Pass the control adapter to createPostgresMigrationPlanner.`,
|
|
@@ -223,9 +224,9 @@ export class CreateTableCall extends PostgresOpFactoryCallNode {
|
|
|
223
224
|
...(this.schemaName !== UNBOUND_NAMESPACE_ID ? { schema: this.schemaName } : {}),
|
|
224
225
|
table: this.tableName,
|
|
225
226
|
columns: this.columns,
|
|
226
|
-
...(
|
|
227
|
+
...ifDefined('constraints', this.constraints),
|
|
227
228
|
});
|
|
228
|
-
const
|
|
229
|
+
const statement = await lowerer.lowerToExecuteRequest(ddlNode);
|
|
229
230
|
const schemaName = this.schemaName;
|
|
230
231
|
const tableName = this.tableName;
|
|
231
232
|
return {
|
|
@@ -240,7 +241,13 @@ export class CreateTableCall extends PostgresOpFactoryCallNode {
|
|
|
240
241
|
`SELECT to_regclass(${toRegclassLiteral(schemaName, tableName)}) IS NULL`,
|
|
241
242
|
),
|
|
242
243
|
],
|
|
243
|
-
execute: [
|
|
244
|
+
execute: [
|
|
245
|
+
{
|
|
246
|
+
description: `create table "${tableName}"`,
|
|
247
|
+
sql: statement.sql,
|
|
248
|
+
params: statement.params ?? [],
|
|
249
|
+
},
|
|
250
|
+
],
|
|
244
251
|
postcheck: [
|
|
245
252
|
step(
|
|
246
253
|
`verify table "${tableName}" exists`,
|
|
@@ -1016,14 +1023,14 @@ export class CreateSchemaCall extends PostgresOpFactoryCallNode {
|
|
|
1016
1023
|
this.freeze();
|
|
1017
1024
|
}
|
|
1018
1025
|
|
|
1019
|
-
toOp(lowerer?:
|
|
1026
|
+
async toOp(lowerer?: ExecuteRequestLowerer): Promise<Op> {
|
|
1020
1027
|
if (lowerer === undefined) {
|
|
1021
1028
|
throw new Error(
|
|
1022
1029
|
`CreateSchemaCall.toOp: a DDL lowerer is required on the Postgres planner path (schema "${this.schemaName}"). Pass the control adapter to createPostgresMigrationPlanner.`,
|
|
1023
1030
|
);
|
|
1024
1031
|
}
|
|
1025
1032
|
const ddlNode = contractFreeDdl.createSchema({ schema: this.schemaName, ifNotExists: true });
|
|
1026
|
-
const
|
|
1033
|
+
const statement = await lowerer.lowerToExecuteRequest(ddlNode);
|
|
1027
1034
|
const schemaName = this.schemaName;
|
|
1028
1035
|
return {
|
|
1029
1036
|
id: `schema.${schemaName}`,
|
|
@@ -1031,7 +1038,13 @@ export class CreateSchemaCall extends PostgresOpFactoryCallNode {
|
|
|
1031
1038
|
operationClass: 'additive',
|
|
1032
1039
|
target: { id: 'postgres' },
|
|
1033
1040
|
precheck: [],
|
|
1034
|
-
execute: [
|
|
1041
|
+
execute: [
|
|
1042
|
+
{
|
|
1043
|
+
description: `Create schema "${schemaName}"`,
|
|
1044
|
+
sql: statement.sql,
|
|
1045
|
+
params: statement.params ?? [],
|
|
1046
|
+
},
|
|
1047
|
+
],
|
|
1035
1048
|
postcheck: [],
|
|
1036
1049
|
};
|
|
1037
1050
|
}
|
|
@@ -61,8 +61,8 @@ import type {
|
|
|
61
61
|
SqlMigrationPlanOperationStep,
|
|
62
62
|
} from '@prisma-next/family-sql/control';
|
|
63
63
|
import type { SqlControlAdapter } from '@prisma-next/family-sql/control-adapter';
|
|
64
|
-
import type { SerializedQueryPlan } from '@prisma-next/framework-components/control';
|
|
65
64
|
import type { SqlStorage } from '@prisma-next/sql-contract/types';
|
|
65
|
+
import type { SqlExecuteRequest } from '@prisma-next/sql-relational-core/ast';
|
|
66
66
|
import type { SqlQueryPlan } from '@prisma-next/sql-relational-core/plan';
|
|
67
67
|
import { ifDefined } from '@prisma-next/utils/defined';
|
|
68
68
|
import type { PostgresPlanTargetDetails } from '../planner-target-details';
|
|
@@ -96,25 +96,29 @@ export interface DataTransformOptions {
|
|
|
96
96
|
readonly run: DataTransformClosure | readonly DataTransformClosure[];
|
|
97
97
|
}
|
|
98
98
|
|
|
99
|
-
export function dataTransform<TContract extends Contract<SqlStorage>>(
|
|
99
|
+
export async function dataTransform<TContract extends Contract<SqlStorage>>(
|
|
100
100
|
contract: TContract,
|
|
101
101
|
name: string,
|
|
102
102
|
options: DataTransformOptions,
|
|
103
103
|
adapter: SqlControlAdapter<'postgres'>,
|
|
104
|
-
): SqlMigrationPlanOperation<PostgresPlanTargetDetails
|
|
104
|
+
): Promise<SqlMigrationPlanOperation<PostgresPlanTargetDetails>> {
|
|
105
105
|
const runClosures: readonly DataTransformClosure[] = Array.isArray(options.run)
|
|
106
106
|
? options.run
|
|
107
107
|
: [options.run as DataTransformClosure];
|
|
108
108
|
|
|
109
|
-
const checkPlan = options.check
|
|
110
|
-
|
|
109
|
+
const checkPlan = options.check
|
|
110
|
+
? await invokeAndLower(options.check, contract, adapter, name)
|
|
111
|
+
: null;
|
|
112
|
+
const runPlans = await Promise.all(
|
|
113
|
+
runClosures.map((closure) => invokeAndLower(closure, contract, adapter, name)),
|
|
114
|
+
);
|
|
111
115
|
|
|
112
116
|
const precheck: readonly SqlMigrationPlanOperationStep[] = checkPlan
|
|
113
117
|
? [
|
|
114
118
|
{
|
|
115
119
|
description: `Check ${name} has work to do`,
|
|
116
120
|
sql: `SELECT EXISTS (${checkPlan.sql}) AS ok`,
|
|
117
|
-
params: checkPlan.params,
|
|
121
|
+
params: checkPlan.params ?? [],
|
|
118
122
|
},
|
|
119
123
|
]
|
|
120
124
|
: [];
|
|
@@ -122,7 +126,7 @@ export function dataTransform<TContract extends Contract<SqlStorage>>(
|
|
|
122
126
|
const execute: readonly SqlMigrationPlanOperationStep[] = runPlans.map((plan) => ({
|
|
123
127
|
description: `Run ${name}`,
|
|
124
128
|
sql: plan.sql,
|
|
125
|
-
params: plan.params,
|
|
129
|
+
params: plan.params ?? [],
|
|
126
130
|
}));
|
|
127
131
|
|
|
128
132
|
const postcheck: readonly SqlMigrationPlanOperationStep[] = checkPlan
|
|
@@ -130,7 +134,7 @@ export function dataTransform<TContract extends Contract<SqlStorage>>(
|
|
|
130
134
|
{
|
|
131
135
|
description: `Verify ${name} resolved all violations`,
|
|
132
136
|
sql: `SELECT NOT EXISTS (${checkPlan.sql}) AS ok`,
|
|
133
|
-
params: checkPlan.params,
|
|
137
|
+
params: checkPlan.params ?? [],
|
|
134
138
|
},
|
|
135
139
|
]
|
|
136
140
|
: [];
|
|
@@ -147,23 +151,16 @@ export function dataTransform<TContract extends Contract<SqlStorage>>(
|
|
|
147
151
|
};
|
|
148
152
|
}
|
|
149
153
|
|
|
150
|
-
function invokeAndLower(
|
|
154
|
+
async function invokeAndLower(
|
|
151
155
|
closure: DataTransformClosure,
|
|
152
156
|
contract: Contract<SqlStorage>,
|
|
153
157
|
adapter: SqlControlAdapter<'postgres'>,
|
|
154
158
|
name: string,
|
|
155
|
-
):
|
|
159
|
+
): Promise<SqlExecuteRequest> {
|
|
156
160
|
const result = closure();
|
|
157
161
|
const plan = isBuildable(result) ? result.build() : result;
|
|
158
162
|
assertContractMatches(plan, contract, name);
|
|
159
|
-
|
|
160
|
-
const params = lowered.params.map((slot) => {
|
|
161
|
-
if (slot.kind === 'literal') return slot.value;
|
|
162
|
-
throw new Error(
|
|
163
|
-
`data-transform: bind-site slot '${slot.name}' is not allowed in migration plans`,
|
|
164
|
-
);
|
|
165
|
-
});
|
|
166
|
-
return { sql: lowered.sql, params };
|
|
163
|
+
return adapter.lowerToExecuteRequest(plan.ast, { contract });
|
|
167
164
|
}
|
|
168
165
|
|
|
169
166
|
function isBuildable(value: unknown): value is Buildable {
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
*/
|
|
25
25
|
|
|
26
26
|
import type { SqlMigrationPlanOperation } from '@prisma-next/family-sql/control';
|
|
27
|
-
import type {
|
|
27
|
+
import type { ExecuteRequestLowerer } from '@prisma-next/family-sql/control-adapter';
|
|
28
28
|
import type {
|
|
29
29
|
MigrationPlanWithAuthoringSurface,
|
|
30
30
|
OpFactoryCall,
|
|
@@ -35,8 +35,6 @@ import { PostgresMigration } from './postgres-migration';
|
|
|
35
35
|
import { renderOps } from './render-ops';
|
|
36
36
|
import { renderCallsToTypeScript } from './render-typescript';
|
|
37
37
|
|
|
38
|
-
type Op = SqlMigrationPlanOperation<PostgresPlanTargetDetails>;
|
|
39
|
-
|
|
40
38
|
export class TypeScriptRenderablePostgresMigration
|
|
41
39
|
extends PostgresMigration
|
|
42
40
|
implements MigrationPlanWithAuthoringSurface
|
|
@@ -44,13 +42,19 @@ export class TypeScriptRenderablePostgresMigration
|
|
|
44
42
|
readonly #calls: readonly OpFactoryCall[];
|
|
45
43
|
readonly #meta: MigrationMeta;
|
|
46
44
|
readonly #spaceId: string;
|
|
47
|
-
readonly #lowerer:
|
|
45
|
+
readonly #lowerer: ExecuteRequestLowerer | undefined;
|
|
46
|
+
#operationsCache:
|
|
47
|
+
| readonly (
|
|
48
|
+
| SqlMigrationPlanOperation<PostgresPlanTargetDetails>
|
|
49
|
+
| Promise<SqlMigrationPlanOperation<PostgresPlanTargetDetails>>
|
|
50
|
+
)[]
|
|
51
|
+
| undefined;
|
|
48
52
|
|
|
49
53
|
constructor(
|
|
50
54
|
calls: readonly OpFactoryCall[],
|
|
51
55
|
meta: MigrationMeta,
|
|
52
56
|
spaceId: string,
|
|
53
|
-
lowerer?:
|
|
57
|
+
lowerer?: ExecuteRequestLowerer,
|
|
54
58
|
) {
|
|
55
59
|
super();
|
|
56
60
|
this.#calls = calls;
|
|
@@ -59,8 +63,12 @@ export class TypeScriptRenderablePostgresMigration
|
|
|
59
63
|
this.#lowerer = lowerer;
|
|
60
64
|
}
|
|
61
65
|
|
|
62
|
-
override get operations(): readonly
|
|
63
|
-
|
|
66
|
+
override get operations(): readonly (
|
|
67
|
+
| SqlMigrationPlanOperation<PostgresPlanTargetDetails>
|
|
68
|
+
| Promise<SqlMigrationPlanOperation<PostgresPlanTargetDetails>>
|
|
69
|
+
)[] {
|
|
70
|
+
this.#operationsCache ??= renderOps(this.#calls, this.#lowerer);
|
|
71
|
+
return this.#operationsCache;
|
|
64
72
|
}
|
|
65
73
|
|
|
66
74
|
override describe(): MigrationMeta {
|
|
@@ -12,7 +12,7 @@ import {
|
|
|
12
12
|
planFieldEventOperations,
|
|
13
13
|
plannerFailure,
|
|
14
14
|
} from '@prisma-next/family-sql/control';
|
|
15
|
-
import type {
|
|
15
|
+
import type { ExecuteRequestLowerer } from '@prisma-next/family-sql/control-adapter';
|
|
16
16
|
import { verifySqlSchema } from '@prisma-next/family-sql/schema-verify';
|
|
17
17
|
import type { TargetBoundComponentDescriptor } from '@prisma-next/framework-components/components';
|
|
18
18
|
import type {
|
|
@@ -52,7 +52,9 @@ type VerifySqlSchemaOptionsWithComponents = Parameters<typeof verifySqlSchema>[0
|
|
|
52
52
|
readonly frameworkComponents: PlannerFrameworkComponents;
|
|
53
53
|
};
|
|
54
54
|
|
|
55
|
-
export function createPostgresMigrationPlanner(
|
|
55
|
+
export function createPostgresMigrationPlanner(
|
|
56
|
+
lowerer: ExecuteRequestLowerer,
|
|
57
|
+
): PostgresMigrationPlanner {
|
|
56
58
|
return new PostgresMigrationPlanner(lowerer);
|
|
57
59
|
}
|
|
58
60
|
|
|
@@ -88,9 +90,9 @@ export type PostgresPlanResult =
|
|
|
88
90
|
* authoring surface.
|
|
89
91
|
*/
|
|
90
92
|
export class PostgresMigrationPlanner implements MigrationPlanner<'sql', 'postgres'> {
|
|
91
|
-
readonly #lowerer:
|
|
93
|
+
readonly #lowerer: ExecuteRequestLowerer | undefined;
|
|
92
94
|
|
|
93
|
-
constructor(lowerer?:
|
|
95
|
+
constructor(lowerer?: ExecuteRequestLowerer) {
|
|
94
96
|
this.#lowerer = lowerer;
|
|
95
97
|
}
|
|
96
98
|
|
|
@@ -64,7 +64,7 @@ export abstract class PostgresMigration extends SqlMigration<
|
|
|
64
64
|
contract: TContract,
|
|
65
65
|
name: string,
|
|
66
66
|
options: DataTransformOptions,
|
|
67
|
-
): SqlMigrationPlanOperation<PostgresPlanTargetDetails
|
|
67
|
+
): Promise<SqlMigrationPlanOperation<PostgresPlanTargetDetails>> {
|
|
68
68
|
if (!this.controlAdapter) {
|
|
69
69
|
throw errorPostgresMigrationStackMissing();
|
|
70
70
|
}
|
|
@@ -82,7 +82,7 @@ export abstract class PostgresMigration extends SqlMigration<
|
|
|
82
82
|
readonly ifNotExists?: boolean;
|
|
83
83
|
readonly columns: readonly DdlColumn[];
|
|
84
84
|
readonly constraints?: readonly DdlTableConstraint[];
|
|
85
|
-
}): SqlMigrationPlanOperation<PostgresPlanTargetDetails
|
|
85
|
+
}): Promise<SqlMigrationPlanOperation<PostgresPlanTargetDetails>> {
|
|
86
86
|
if (!this.controlAdapter) {
|
|
87
87
|
throw errorPostgresMigrationStackMissing();
|
|
88
88
|
}
|
|
@@ -102,7 +102,7 @@ export abstract class PostgresMigration extends SqlMigration<
|
|
|
102
102
|
protected createSchema(options: {
|
|
103
103
|
readonly schema: string;
|
|
104
104
|
readonly ifNotExists?: boolean;
|
|
105
|
-
}): SqlMigrationPlanOperation<PostgresPlanTargetDetails
|
|
105
|
+
}): Promise<SqlMigrationPlanOperation<PostgresPlanTargetDetails>> {
|
|
106
106
|
if (!this.controlAdapter) {
|
|
107
107
|
throw errorPostgresMigrationStackMissing();
|
|
108
108
|
}
|
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
import type { SqlMigrationPlanOperation } from '@prisma-next/family-sql/control';
|
|
2
|
-
import type {
|
|
3
|
-
import type {
|
|
2
|
+
import type { ExecuteRequestLowerer } from '@prisma-next/family-sql/control-adapter';
|
|
3
|
+
import type {
|
|
4
|
+
MigrationPlanOperation,
|
|
5
|
+
OpFactoryCall,
|
|
6
|
+
} from '@prisma-next/framework-components/control';
|
|
4
7
|
import { blindCast } from '@prisma-next/utils/casts';
|
|
8
|
+
import { isThenable } from '@prisma-next/utils/promise';
|
|
5
9
|
import type { PostgresPlanTargetDetails } from './planner-target-details';
|
|
6
10
|
|
|
7
11
|
type Op = SqlMigrationPlanOperation<PostgresPlanTargetDetails>;
|
|
@@ -13,11 +17,11 @@ type Op = SqlMigrationPlanOperation<PostgresPlanTargetDetails>;
|
|
|
13
17
|
* silently flow through to postgres-shaped renderers — exactly the
|
|
14
18
|
* place to fail loudly with op metadata (`id` + `target.id`).
|
|
15
19
|
*/
|
|
16
|
-
function assertPostgresOp(
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
20
|
+
function assertPostgresOp(op: MigrationPlanOperation, callFactoryName: string): asserts op is Op {
|
|
21
|
+
const targetId = blindCast<
|
|
22
|
+
{ target?: { id?: string } },
|
|
23
|
+
'op.target is present on concrete SqlMigrationPlanOperation but absent on the framework MigrationPlanOperation base'
|
|
24
|
+
>(op).target?.id;
|
|
21
25
|
if (targetId !== 'postgres') {
|
|
22
26
|
throw new Error(
|
|
23
27
|
`renderOps: expected postgres op but got target.id="${String(targetId)}" for op.id="${op.id}" (factoryName="${callFactoryName}"). An OpFactoryCall produced an op for a different target on the postgres planner path; check the call's target binding.`,
|
|
@@ -25,13 +29,22 @@ function assertPostgresOp(
|
|
|
25
29
|
}
|
|
26
30
|
}
|
|
27
31
|
|
|
28
|
-
export function renderOps(
|
|
32
|
+
export function renderOps(
|
|
33
|
+
calls: readonly OpFactoryCall[],
|
|
34
|
+
lowerer?: ExecuteRequestLowerer,
|
|
35
|
+
): (Op | Promise<Op>)[] {
|
|
29
36
|
return calls.map((c) => {
|
|
30
|
-
const
|
|
31
|
-
{ toOp(lowerer?:
|
|
32
|
-
'PG OpFactoryCall.toOp accepts an optional
|
|
37
|
+
const opOrPromise = blindCast<
|
|
38
|
+
{ toOp(lowerer?: ExecuteRequestLowerer): Op | Promise<Op> },
|
|
39
|
+
'PG OpFactoryCall.toOp accepts an optional ExecuteRequestLowerer; the framework interface omits it because not all targets need a lowerer — the PG target overrides with this extended signature'
|
|
33
40
|
>(c).toOp(lowerer);
|
|
34
|
-
|
|
35
|
-
|
|
41
|
+
if (isThenable(opOrPromise)) {
|
|
42
|
+
return opOrPromise.then((op) => {
|
|
43
|
+
assertPostgresOp(op, c.factoryName);
|
|
44
|
+
return op;
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
assertPostgresOp(opOrPromise, c.factoryName);
|
|
48
|
+
return opOrPromise;
|
|
36
49
|
});
|
|
37
50
|
}
|