@prisma-next/target-postgres 0.2.0 → 0.3.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/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.case1.test.ts`: Planner unit tests
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
@@ -11,4 +11,4 @@ var postgresTargetDescriptorMeta = {
11
11
  export {
12
12
  postgresTargetDescriptorMeta
13
13
  };
14
- //# sourceMappingURL=chunk-2EJEPMD3.js.map
14
+ //# sourceMappingURL=chunk-RKEXRSSI.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/core/descriptor-meta.ts"],"sourcesContent":["export const postgresTargetDescriptorMeta = {\n kind: 'target',\n familyId: 'sql',\n targetId: 'postgres',\n id: 'postgres',\n version: '0.0.1',\n capabilities: {},\n} as const;\n"],"mappings":";AAAO,IAAM,+BAA+B;AAAA,EAC1C,MAAM;AAAA,EACN,UAAU;AAAA,EACV,UAAU;AAAA,EACV,IAAI;AAAA,EACJ,SAAS;AAAA,EACT,cAAc,CAAC;AACjB;","names":[]}
@@ -0,0 +1,9 @@
1
+ export declare const postgresTargetDescriptorMeta: {
2
+ readonly kind: "target";
3
+ readonly familyId: "sql";
4
+ readonly targetId: "postgres";
5
+ readonly id: "postgres";
6
+ readonly version: "0.0.1";
7
+ readonly capabilities: {};
8
+ };
9
+ //# sourceMappingURL=descriptor-meta.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"descriptor-meta.d.ts","sourceRoot":"","sources":["../../src/core/descriptor-meta.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,4BAA4B;;;;;;;CAO/B,CAAC"}
@@ -0,0 +1,14 @@
1
+ import type { SqlMigrationPlanner } from '@prisma-next/family-sql/control';
2
+ type OperationClass = 'extension' | 'table' | 'unique' | 'index' | 'foreignKey';
3
+ export interface PostgresPlanTargetDetails {
4
+ readonly schema: string;
5
+ readonly objectType: OperationClass;
6
+ readonly name: string;
7
+ readonly table?: string;
8
+ }
9
+ interface PlannerConfig {
10
+ readonly defaultSchema: string;
11
+ }
12
+ export declare function createPostgresMigrationPlanner(config?: Partial<PlannerConfig>): SqlMigrationPlanner<PostgresPlanTargetDetails>;
13
+ export {};
14
+ //# sourceMappingURL=planner.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"planner.d.ts","sourceRoot":"","sources":["../../../src/core/migrations/planner.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAEV,mBAAmB,EAIpB,MAAM,iCAAiC,CAAC;AAgBzC,KAAK,cAAc,GAAG,WAAW,GAAG,OAAO,GAAG,QAAQ,GAAG,OAAO,GAAG,YAAY,CAAC;AAuBhF,MAAM,WAAW,yBAAyB;IACxC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,UAAU,EAAE,cAAc,CAAC;IACpC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC;CACzB;AAED,UAAU,aAAa;IACrB,QAAQ,CAAC,aAAa,EAAE,MAAM,CAAC;CAChC;AAMD,wBAAgB,8BAA8B,CAC5C,MAAM,GAAE,OAAO,CAAC,aAAa,CAAM,GAClC,mBAAmB,CAAC,yBAAyB,CAAC,CAKhD"}
@@ -0,0 +1,8 @@
1
+ import type { SqlControlFamilyInstance, SqlMigrationRunner } from '@prisma-next/family-sql/control';
2
+ import type { PostgresPlanTargetDetails } from './planner';
3
+ interface RunnerConfig {
4
+ readonly defaultSchema: string;
5
+ }
6
+ export declare function createPostgresMigrationRunner(family: SqlControlFamilyInstance, config?: Partial<RunnerConfig>): SqlMigrationRunner<PostgresPlanTargetDetails>;
7
+ export {};
8
+ //# sourceMappingURL=runner.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"runner.d.ts","sourceRoot":"","sources":["../../../src/core/migrations/runner.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAEV,wBAAwB,EAIxB,kBAAkB,EAInB,MAAM,iCAAiC,CAAC;AAOzC,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,WAAW,CAAC;AAU3D,UAAU,YAAY;IACpB,QAAQ,CAAC,aAAa,EAAE,MAAM,CAAC;CAChC;AAoCD,wBAAgB,6BAA6B,CAC3C,MAAM,EAAE,wBAAwB,EAChC,MAAM,GAAE,OAAO,CAAC,YAAY,CAAM,GACjC,kBAAkB,CAAC,yBAAyB,CAAC,CAE/C"}
@@ -0,0 +1,30 @@
1
+ export interface SqlStatement {
2
+ readonly sql: string;
3
+ readonly params: readonly unknown[];
4
+ }
5
+ export declare const ensurePrismaContractSchemaStatement: SqlStatement;
6
+ export declare const ensureMarkerTableStatement: SqlStatement;
7
+ export declare const ensureLedgerTableStatement: SqlStatement;
8
+ export interface WriteMarkerInput {
9
+ readonly coreHash: string;
10
+ readonly profileHash: string;
11
+ readonly contractJson?: unknown;
12
+ readonly canonicalVersion?: number | null;
13
+ readonly appTag?: string | null;
14
+ readonly meta?: Record<string, unknown>;
15
+ }
16
+ export declare function buildWriteMarkerStatements(input: WriteMarkerInput): {
17
+ readonly insert: SqlStatement;
18
+ readonly update: SqlStatement;
19
+ };
20
+ export interface LedgerInsertInput {
21
+ readonly originCoreHash?: string | null;
22
+ readonly originProfileHash?: string | null;
23
+ readonly destinationCoreHash: string;
24
+ readonly destinationProfileHash?: string | null;
25
+ readonly contractJsonBefore?: unknown;
26
+ readonly contractJsonAfter?: unknown;
27
+ readonly operations: unknown;
28
+ }
29
+ export declare function buildLedgerInsertStatement(input: LedgerInsertInput): SqlStatement;
30
+ //# sourceMappingURL=statement-builders.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"statement-builders.d.ts","sourceRoot":"","sources":["../../../src/core/migrations/statement-builders.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,YAAY;IAC3B,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,MAAM,EAAE,SAAS,OAAO,EAAE,CAAC;CACrC;AAED,eAAO,MAAM,mCAAmC,EAAE,YAGjD,CAAC;AAEF,eAAO,MAAM,0BAA0B,EAAE,YAYxC,CAAC;AAEF,eAAO,MAAM,0BAA0B,EAAE,YAaxC,CAAC;AAEF,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B,QAAQ,CAAC,YAAY,CAAC,EAAE,OAAO,CAAC;IAChC,QAAQ,CAAC,gBAAgB,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1C,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAChC,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACzC;AAED,wBAAgB,0BAA0B,CAAC,KAAK,EAAE,gBAAgB,GAAG;IACnE,QAAQ,CAAC,MAAM,EAAE,YAAY,CAAC;IAC9B,QAAQ,CAAC,MAAM,EAAE,YAAY,CAAC;CAC/B,CA+CA;AAED,MAAM,WAAW,iBAAiB;IAChC,QAAQ,CAAC,cAAc,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACxC,QAAQ,CAAC,iBAAiB,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC3C,QAAQ,CAAC,mBAAmB,EAAE,MAAM,CAAC;IACrC,QAAQ,CAAC,sBAAsB,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAChD,QAAQ,CAAC,kBAAkB,CAAC,EAAE,OAAO,CAAC;IACtC,QAAQ,CAAC,iBAAiB,CAAC,EAAE,OAAO,CAAC;IACrC,QAAQ,CAAC,UAAU,EAAE,OAAO,CAAC;CAC9B;AAED,wBAAgB,0BAA0B,CAAC,KAAK,EAAE,iBAAiB,GAAG,YAAY,CA6BjF"}
@@ -1,16 +1,8 @@
1
- import { SqlControlTargetDescriptor } from '@prisma-next/family-sql/control';
2
-
3
- type OperationClass = 'extension' | 'table' | 'unique' | 'index' | 'foreignKey';
4
- interface PostgresPlanTargetDetails {
5
- readonly schema: string;
6
- readonly objectType: OperationClass;
7
- readonly name: string;
8
- readonly table?: string;
9
- }
10
-
1
+ import type { SqlControlTargetDescriptor } from '@prisma-next/family-sql/control';
2
+ import type { PostgresPlanTargetDetails } from '../core/migrations/planner';
11
3
  /**
12
4
  * Postgres target descriptor for CLI config.
13
5
  */
14
6
  declare const postgresTargetDescriptor: SqlControlTargetDescriptor<'postgres', PostgresPlanTargetDetails>;
15
-
16
- export { postgresTargetDescriptor as default };
7
+ export default postgresTargetDescriptor;
8
+ //# sourceMappingURL=control.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"control.d.ts","sourceRoot":"","sources":["../../src/exports/control.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAEV,0BAA0B,EAC3B,MAAM,iCAAiC,CAAC;AAEzC,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,4BAA4B,CAAC;AAI5E;;GAEG;AACH,QAAA,MAAM,wBAAwB,EAAE,0BAA0B,CAAC,UAAU,EAAE,yBAAyB,CAoC7F,CAAC;AAEJ,eAAe,wBAAwB,CAAC"}
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  postgresTargetDescriptorMeta
3
- } from "./chunk-2EJEPMD3.js";
3
+ } from "../chunk-RKEXRSSI.js";
4
4
 
5
5
  // src/core/migrations/planner.ts
6
6
  import {
@@ -1,5 +1,4 @@
1
- import { TargetPackRef } from '@prisma-next/contract/framework-components';
2
-
1
+ import type { TargetPackRef } from '@prisma-next/contract/framework-components';
3
2
  declare const postgresPack: TargetPackRef<'sql', 'postgres'>;
4
-
5
- export { postgresPack as default };
3
+ export default postgresPack;
4
+ //# sourceMappingURL=pack.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pack.d.ts","sourceRoot":"","sources":["../../src/exports/pack.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,4CAA4C,CAAC;AAGhF,QAAA,MAAM,YAAY,EAAE,aAAa,CAAC,KAAK,EAAE,UAAU,CAAgC,CAAC;AAEpF,eAAe,YAAY,CAAC"}
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  postgresTargetDescriptorMeta
3
- } from "./chunk-2EJEPMD3.js";
3
+ } from "../chunk-RKEXRSSI.js";
4
4
 
5
5
  // src/exports/pack.ts
6
6
  var postgresPack = postgresTargetDescriptorMeta;
@@ -1,13 +1,12 @@
1
- import { RuntimeTargetDescriptor, RuntimeTargetInstance } from '@prisma-next/core-execution-plane/types';
2
-
1
+ import type { RuntimeTargetDescriptor, RuntimeTargetInstance } from '@prisma-next/core-execution-plane/types';
3
2
  /**
4
3
  * Postgres runtime target instance interface.
5
4
  */
6
- interface PostgresRuntimeTargetInstance extends RuntimeTargetInstance<'sql', 'postgres'> {
5
+ export interface PostgresRuntimeTargetInstance extends RuntimeTargetInstance<'sql', 'postgres'> {
7
6
  }
8
7
  /**
9
8
  * Postgres target descriptor for runtime plane.
10
9
  */
11
10
  declare const postgresRuntimeTargetDescriptor: RuntimeTargetDescriptor<'sql', 'postgres', PostgresRuntimeTargetInstance>;
12
-
13
- export { type PostgresRuntimeTargetInstance, postgresRuntimeTargetDescriptor as default };
11
+ export default postgresRuntimeTargetDescriptor;
12
+ //# sourceMappingURL=runtime.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"runtime.d.ts","sourceRoot":"","sources":["../../src/exports/runtime.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,uBAAuB,EACvB,qBAAqB,EACtB,MAAM,yCAAyC,CAAC;AAGjD;;GAEG;AACH,MAAM,WAAW,6BAA8B,SAAQ,qBAAqB,CAAC,KAAK,EAAE,UAAU,CAAC;CAAG;AAElG;;GAEG;AACH,QAAA,MAAM,+BAA+B,EAAE,uBAAuB,CAC5D,KAAK,EACL,UAAU,EACV,6BAA6B,CAS9B,CAAC;AAEF,eAAe,+BAA+B,CAAC"}
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  postgresTargetDescriptorMeta
3
- } from "./chunk-2EJEPMD3.js";
3
+ } from "../chunk-RKEXRSSI.js";
4
4
 
5
5
  // src/exports/runtime.ts
6
6
  var postgresRuntimeTargetDescriptor = {
package/package.json CHANGED
@@ -1,33 +1,33 @@
1
1
  {
2
2
  "name": "@prisma-next/target-postgres",
3
- "version": "0.2.0",
3
+ "version": "0.3.0-dev.10",
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.2.0",
10
- "@prisma-next/cli": "0.2.0",
11
- "@prisma-next/contract": "0.2.0",
12
- "@prisma-next/sql-contract": "0.2.0",
13
- "@prisma-next/sql-errors": "0.2.0",
14
- "@prisma-next/sql-schema-ir": "0.2.0",
15
- "@prisma-next/core-control-plane": "0.2.0",
16
- "@prisma-next/core-execution-plane": "0.2.0",
17
- "@prisma-next/utils": "0.2.0"
9
+ "@prisma-next/contract": "0.3.0-dev.10",
10
+ "@prisma-next/cli": "0.3.0-dev.10",
11
+ "@prisma-next/core-execution-plane": "0.3.0-dev.10",
12
+ "@prisma-next/core-control-plane": "0.3.0-dev.10",
13
+ "@prisma-next/family-sql": "0.3.0-dev.10",
14
+ "@prisma-next/sql-contract": "0.3.0-dev.10",
15
+ "@prisma-next/sql-errors": "0.3.0-dev.10",
16
+ "@prisma-next/sql-schema-ir": "0.3.0-dev.10",
17
+ "@prisma-next/utils": "0.3.0-dev.10"
18
18
  },
19
19
  "devDependencies": {
20
- "@vitest/coverage-v8": "^4.0.0",
21
- "vite-tsconfig-paths": "^5.1.4",
22
- "tsup": "^8.3.0",
23
- "typescript": "^5.9.3",
24
- "vitest": "^4.0.16",
25
- "@prisma-next/adapter-postgres": "0.2.0",
26
- "@prisma-next/driver-postgres": "0.2.0",
20
+ "@vitest/coverage-v8": "4.0.16",
21
+ "tsup": "8.5.1",
22
+ "typescript": "5.9.3",
23
+ "vitest": "4.0.16",
24
+ "@prisma-next/adapter-postgres": "0.3.0-dev.10",
25
+ "@prisma-next/driver-postgres": "0.3.0-dev.10",
27
26
  "@prisma-next/test-utils": "0.0.1"
28
27
  },
29
28
  "files": [
30
29
  "dist",
30
+ "src",
31
31
  "packs"
32
32
  ],
33
33
  "exports": {
@@ -45,7 +45,7 @@
45
45
  }
46
46
  },
47
47
  "scripts": {
48
- "build": "tsup --config tsup.config.ts",
48
+ "build": "tsup --config tsup.config.ts && tsc --project tsconfig.build.json",
49
49
  "test": "vitest run --passWithNoTests",
50
50
  "test:coverage": "vitest run --coverage --passWithNoTests",
51
51
  "typecheck": "tsc --project tsconfig.json --noEmit",
@@ -0,0 +1,8 @@
1
+ export const postgresTargetDescriptorMeta = {
2
+ kind: 'target',
3
+ familyId: 'sql',
4
+ targetId: 'postgres',
5
+ id: 'postgres',
6
+ version: '0.0.1',
7
+ capabilities: {},
8
+ } as const;