@prisma-next/family-sql 0.1.0-dev.2 → 0.1.0-dev.21

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
@@ -12,8 +12,10 @@ Provides the SQL family descriptor (`ControlFamilyDescriptor`) that includes:
12
12
 
13
13
  - **Family Descriptor Export**: Exports the SQL `ControlFamilyDescriptor` for use in CLI configuration files
14
14
  - **Family Instance Creation**: Creates `SqlFamilyInstance` objects that implement control-plane domain actions (`verify`, `schemaVerify`, `introspect`, `emitContract`, `validateContractIR`)
15
+ - **Planner & Runner SPI**: Owns the `MigrationPlanner` / `MigrationRunner` interfaces plus the `SqlControlTargetDescriptor` helper so targets can expose planners and runners (e.g., Postgres init planner/runner)
15
16
  - **Family Hook Integration**: Integrates the SQL target family hook (`sqlTargetFamilyHook`) from `@prisma-next/sql-contract-emitter`
16
17
  - **Control Plane Entry Point**: Serves as the control plane entry point for the SQL family, enabling the CLI to select the family hook and create family instances
18
+ - **Component Database Dependencies**: Consumes database dependencies declared by framework components (target/adapter/extensions). Callers pass the active `frameworkComponents` list into planning/execution/verification; SQL layers structurally narrow to components that declare `databaseDependencies` and use their pure verification hooks (no fuzzy matching against `contract.extensions`).
17
19
 
18
20
  ## Usage
19
21
 
@@ -39,6 +41,33 @@ const familyInstance = sql.create({
39
41
  const contractIR = familyInstance.validateContractIR(contractJson);
40
42
  const verifyResult = await familyInstance.verify({ driver, contractIR, ... });
41
43
  const emitResult = await familyInstance.emitContract({ contractIR: rawContract }); // Handles stripping mappings and validation internally
44
+
45
+ // Targets that implement SqlControlTargetDescriptor can build planners
46
+ const planner = postgresTargetDescriptor.createPlanner(familyInstance);
47
+ // frameworkComponents should include the active target, adapter, and any extension descriptors so
48
+ // planner/runner can resolve database dependencies declared by those components.
49
+ const planResult = planner.plan({
50
+ contract: sqlContract,
51
+ schema,
52
+ policy,
53
+ frameworkComponents: [postgresTargetDescriptor, postgresAdapterDescriptor, pgVectorExtensionDescriptor],
54
+ });
55
+
56
+ // Targets also provide runners for executing plans
57
+ const runner = postgresTargetDescriptor.createRunner(familyInstance);
58
+ const executeResult = await runner.execute({
59
+ plan: planResult.plan,
60
+ driver,
61
+ destinationContract: sqlContract,
62
+ frameworkComponents: [postgresTargetDescriptor, postgresAdapterDescriptor, pgVectorExtensionDescriptor],
63
+ });
64
+
65
+ // executeResult is a Result<MigrationRunnerSuccessValue, MigrationRunnerFailure>
66
+ if (executeResult.ok) {
67
+ console.log(`Executed ${executeResult.value.operationsExecuted} operations`);
68
+ } else {
69
+ console.error(`Migration failed: ${executeResult.failure.code} - ${executeResult.failure.summary}`);
70
+ }
42
71
  ```
43
72
 
44
73
  ## Architecture
@@ -68,6 +97,19 @@ The descriptor is "pure data + factory" - it only provides the hook and factory
68
97
  - **`src/core/assembly.ts`**: Assembly helpers for building operation registries and extracting type imports from descriptors. Test utilities import `convertOperationManifest` from the same package via relative path.
69
98
  - **`src/core/verify.ts`**: Verification helpers (`readMarker`, `collectSupportedCodecTypeIds`)
70
99
  - **`src/core/control-adapter.ts`**: SQL control adapter interface (`SqlControlAdapter`) for control-plane operations
100
+ - **`src/core/migrations/`**: Migration IR helpers plus planner and runner SPI types (`MigrationPlanner`, `MigrationRunner`, `SqlControlTargetDescriptor`). Runners return `MigrationRunnerResult` which is a union of success/failure.
101
+
102
+ ### Migration Runner Error Codes
103
+
104
+ The runner returns structured errors with the following codes:
105
+
106
+ - **`DESTINATION_CONTRACT_MISMATCH`**: Plan destination hash doesn't match provided contract hash
107
+ - **`MARKER_ORIGIN_MISMATCH`**: Existing marker doesn't match plan's expected origin
108
+ - **`POLICY_VIOLATION`**: Operation class is not allowed by the plan's policy
109
+ - **`PRECHECK_FAILED`**: Operation precheck returned false
110
+ - **`POSTCHECK_FAILED`**: Operation postcheck returned false after execution
111
+ - **`SCHEMA_VERIFY_FAILED`**: Resulting schema doesn't satisfy the destination contract
112
+ - **`EXECUTION_FAILED`**: SQL execution error during operation execution
71
113
  - **`src/exports/control.ts`**: Control plane entry point (exports `SqlFamilyDescriptor` instance)
72
114
  - **`src/exports/runtime.ts`**: Runtime entry point (placeholder for future functionality)
73
115