@prisma-next/family-sql 0.1.0-dev.14 → 0.1.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/README.md CHANGED
@@ -12,7 +12,7 @@ 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 SPI**: Owns the `MigrationPlanner` interface plus the `SqlControlTargetDescriptor` helper so targets can expose planners (e.g., Postgres init planner)
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)
16
16
  - **Family Hook Integration**: Integrates the SQL target family hook (`sqlTargetFamilyHook`) from `@prisma-next/sql-contract-emitter`
17
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
18
 
@@ -44,6 +44,21 @@ const emitResult = await familyInstance.emitContract({ contractIR: rawContract }
44
44
  // Targets that implement SqlControlTargetDescriptor can build planners
45
45
  const planner = postgresTargetDescriptor.createPlanner(familyInstance);
46
46
  const planResult = planner.plan({ contract: sqlContract, schema, policy });
47
+
48
+ // Targets also provide runners for executing plans
49
+ const runner = postgresTargetDescriptor.createRunner(familyInstance);
50
+ const executeResult = await runner.execute({
51
+ plan: planResult.plan,
52
+ driver,
53
+ destinationContract: sqlContract,
54
+ });
55
+
56
+ // executeResult is a Result<MigrationRunnerSuccessValue, MigrationRunnerFailure>
57
+ if (executeResult.ok) {
58
+ console.log(`Executed ${executeResult.value.operationsExecuted} operations`);
59
+ } else {
60
+ console.error(`Migration failed: ${executeResult.failure.code} - ${executeResult.failure.summary}`);
61
+ }
47
62
  ```
48
63
 
49
64
  ## Architecture
@@ -73,7 +88,19 @@ The descriptor is "pure data + factory" - it only provides the hook and factory
73
88
  - **`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.
74
89
  - **`src/core/verify.ts`**: Verification helpers (`readMarker`, `collectSupportedCodecTypeIds`)
75
90
  - **`src/core/control-adapter.ts`**: SQL control adapter interface (`SqlControlAdapter`) for control-plane operations
76
- - **`src/core/migrations/`**: Migration IR helpers plus planner SPI types (`MigrationPlanner`, `SqlControlTargetDescriptor`)
91
+ - **`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.
92
+
93
+ ### Migration Runner Error Codes
94
+
95
+ The runner returns structured errors with the following codes:
96
+
97
+ - **`DESTINATION_CONTRACT_MISMATCH`**: Plan destination hash doesn't match provided contract hash
98
+ - **`MARKER_ORIGIN_MISMATCH`**: Existing marker doesn't match plan's expected origin
99
+ - **`POLICY_VIOLATION`**: Operation class is not allowed by the plan's policy
100
+ - **`PRECHECK_FAILED`**: Operation precheck returned false
101
+ - **`POSTCHECK_FAILED`**: Operation postcheck returned false after execution
102
+ - **`SCHEMA_VERIFY_FAILED`**: Resulting schema doesn't satisfy the destination contract
103
+ - **`EXECUTION_FAILED`**: SQL execution error during operation execution
77
104
  - **`src/exports/control.ts`**: Control plane entry point (exports `SqlFamilyDescriptor` instance)
78
105
  - **`src/exports/runtime.ts`**: Runtime entry point (placeholder for future functionality)
79
106