@prisma-next/target-postgres 0.2.0 → 0.3.0-pr.72.3
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/README.md +23 -8
- package/package.json +12 -12
package/README.md
CHANGED
|
@@ -17,8 +17,8 @@ Provides the Postgres target descriptor (`SqlControlTargetDescriptor`) for CLI c
|
|
|
17
17
|
- **Target Descriptor Export**: Exports the Postgres `SqlControlTargetDescriptor` for use in CLI configuration files
|
|
18
18
|
- **Descriptor-First Design**: All declarative fields (version, capabilities, types, operations) are properties directly on the descriptor, eliminating the need for separate manifest files
|
|
19
19
|
- **Multi-Plane Support**: Provides both migration-plane (control) and runtime-plane entry points for the Postgres target
|
|
20
|
-
- **Planner Factory**: Implements `createPlanner()` to create Postgres-specific migration planners
|
|
21
|
-
- **Runner Factory**: Implements `createRunner()` to create Postgres-specific migration runners
|
|
20
|
+
- **Planner Factory**: Implements `migrations.createPlanner()` to create Postgres-specific migration planners
|
|
21
|
+
- **Runner Factory**: Implements `migrations.createRunner()` to create Postgres-specific migration runners
|
|
22
22
|
- **Database Dependency Consumption**: The planner extracts database dependencies from the configured framework components (passed as `frameworkComponents`), verifies each dependency against the live schema, and only emits install operations when required. The runner reuses the same metadata for post-apply verification, so there are no hardcoded extension mappings—database dependencies stay component-owned.
|
|
23
23
|
|
|
24
24
|
This package spans multiple planes:
|
|
@@ -26,6 +26,15 @@ This package spans multiple planes:
|
|
|
26
26
|
- **Runtime plane** (`src/exports/runtime.ts`): Runtime entry point for target-specific runtime code (future)
|
|
27
27
|
- **Authoring pack ref** (`src/exports/pack.ts`): Pure data surface for contract builder workflows
|
|
28
28
|
|
|
29
|
+
## `db init`
|
|
30
|
+
|
|
31
|
+
This package provides the Postgres implementation of the SQL migration planner/runner used by `prisma-next db init`:
|
|
32
|
+
|
|
33
|
+
- **Planner** (`src/core/migrations/planner.ts`): produces an additive-only `MigrationPlan` to bring the database schema in line with a destination contract. Extra unrelated schema is tolerated; non-additive mismatches (type/nullability/constraint incompatibilities) surface as structured conflicts.
|
|
34
|
+
- **Runner** (`src/core/migrations/runner.ts`): executes a plan under an advisory lock, verifies the post-state schema, then writes the contract marker and appends a ledger entry in the `prisma_contract` schema.
|
|
35
|
+
|
|
36
|
+
For the CLI orchestration, see `packages/1-framework/3-tooling/cli/src/commands/db-init.ts`.
|
|
37
|
+
|
|
29
38
|
## Usage
|
|
30
39
|
|
|
31
40
|
### Control Plane (CLI)
|
|
@@ -43,8 +52,8 @@ import postgresDriver from '@prisma-next/driver-postgres/control';
|
|
|
43
52
|
// - id: 'postgres'
|
|
44
53
|
// - version: '0.0.1'
|
|
45
54
|
// - capabilities, types, operations (directly on descriptor)
|
|
46
|
-
// - createPlanner(): creates a Postgres migration planner
|
|
47
|
-
// - createRunner(): creates a Postgres migration runner
|
|
55
|
+
// - migrations.createPlanner(): creates a Postgres migration planner
|
|
56
|
+
// - migrations.createRunner(): creates a Postgres migration runner
|
|
48
57
|
|
|
49
58
|
// Create family instance with target, adapter, and driver
|
|
50
59
|
const family = sqlFamilyDescriptor.create({
|
|
@@ -54,18 +63,23 @@ const family = sqlFamilyDescriptor.create({
|
|
|
54
63
|
extensions: [],
|
|
55
64
|
});
|
|
56
65
|
|
|
66
|
+
// Include the active framework components so planner/runner can resolve
|
|
67
|
+
// component-owned database dependencies (e.g., extension installs).
|
|
68
|
+
const frameworkComponents = [postgres, postgresAdapter];
|
|
69
|
+
|
|
57
70
|
// Create planner and runner from target descriptor
|
|
58
|
-
const planner = postgres.createPlanner(family);
|
|
59
|
-
const runner = postgres.createRunner(family);
|
|
71
|
+
const planner = postgres.migrations.createPlanner(family);
|
|
72
|
+
const runner = postgres.migrations.createRunner(family);
|
|
60
73
|
|
|
61
74
|
// Plan and execute migrations
|
|
62
|
-
const planResult = planner.plan({ contract, schema, policy });
|
|
75
|
+
const planResult = planner.plan({ contract, schema, policy, frameworkComponents });
|
|
63
76
|
if (planResult.kind === 'success') {
|
|
64
77
|
const executeResult = await runner.execute({
|
|
65
78
|
plan: planResult.plan,
|
|
66
79
|
driver,
|
|
67
80
|
destinationContract: contract,
|
|
68
81
|
policy,
|
|
82
|
+
frameworkComponents,
|
|
69
83
|
});
|
|
70
84
|
if (!executeResult.ok) {
|
|
71
85
|
// Handle structured failure (e.g., EXECUTION_FAILED, PRECHECK_FAILED)
|
|
@@ -134,7 +148,8 @@ This package ships a mix of fast planner unit tests and slower runner integratio
|
|
|
134
148
|
|
|
135
149
|
- **Default (`pnpm --filter @prisma-next/target-postgres test`)**: runs all tests including integration tests
|
|
136
150
|
- **Test files**:
|
|
137
|
-
- `test/migrations/planner.
|
|
151
|
+
- `test/migrations/planner.behavior.test.ts`: Planner unit tests (classification, conflicts, dependency ops)
|
|
152
|
+
- `test/migrations/planner.integration.test.ts`: Planner integration tests
|
|
138
153
|
- `test/migrations/runner.*.integration.test.ts`: Runner integration tests (basic, errors, idempotency, policy)
|
|
139
154
|
|
|
140
155
|
```bash
|
package/package.json
CHANGED
|
@@ -1,20 +1,20 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@prisma-next/target-postgres",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0-pr.72.3",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"description": "Postgres target pack for Prisma Next",
|
|
7
7
|
"dependencies": {
|
|
8
8
|
"arktype": "^2.0.0",
|
|
9
|
-
"@prisma-next/family-sql": "0.
|
|
10
|
-
"@prisma-next/cli": "0.
|
|
11
|
-
"@prisma-next/contract": "0.
|
|
12
|
-
"@prisma-next/sql-contract": "0.
|
|
13
|
-
"@prisma-next/sql-errors": "0.
|
|
14
|
-
"@prisma-next/sql-schema-ir": "0.
|
|
15
|
-
"@prisma-next/core-control-plane": "0.
|
|
16
|
-
"@prisma-next/core-execution-plane": "0.
|
|
17
|
-
"@prisma-next/utils": "0.
|
|
9
|
+
"@prisma-next/family-sql": "0.3.0-pr.72.3",
|
|
10
|
+
"@prisma-next/cli": "0.3.0-pr.72.3",
|
|
11
|
+
"@prisma-next/contract": "0.3.0-pr.72.3",
|
|
12
|
+
"@prisma-next/sql-contract": "0.3.0-pr.72.3",
|
|
13
|
+
"@prisma-next/sql-errors": "0.3.0-pr.72.3",
|
|
14
|
+
"@prisma-next/sql-schema-ir": "0.3.0-pr.72.3",
|
|
15
|
+
"@prisma-next/core-control-plane": "0.3.0-pr.72.3",
|
|
16
|
+
"@prisma-next/core-execution-plane": "0.3.0-pr.72.3",
|
|
17
|
+
"@prisma-next/utils": "0.3.0-pr.72.3"
|
|
18
18
|
},
|
|
19
19
|
"devDependencies": {
|
|
20
20
|
"@vitest/coverage-v8": "^4.0.0",
|
|
@@ -22,8 +22,8 @@
|
|
|
22
22
|
"tsup": "^8.3.0",
|
|
23
23
|
"typescript": "^5.9.3",
|
|
24
24
|
"vitest": "^4.0.16",
|
|
25
|
-
"@prisma-next/adapter-postgres": "0.
|
|
26
|
-
"@prisma-next/driver-postgres": "0.
|
|
25
|
+
"@prisma-next/adapter-postgres": "0.3.0-pr.72.3",
|
|
26
|
+
"@prisma-next/driver-postgres": "0.3.0-pr.72.3",
|
|
27
27
|
"@prisma-next/test-utils": "0.0.1"
|
|
28
28
|
},
|
|
29
29
|
"files": [
|