@prisma-next/family-sql 0.3.0-dev.2 → 0.3.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/dist/{exports/chunk-6P44BVZ4.js → chunk-F27CR6XZ.js} +12 -3
- package/dist/chunk-F27CR6XZ.js.map +1 -0
- package/dist/{exports/chunk-C3GKWCKA.js → chunk-SU7LN2UH.js} +1 -1
- package/dist/chunk-SU7LN2UH.js.map +1 -0
- package/dist/{exports/chunk-F252JMEU.js → chunk-XH2Y5NTD.js} +59 -116
- package/dist/chunk-XH2Y5NTD.js.map +1 -0
- package/dist/core/assembly.d.ts +25 -0
- package/dist/core/assembly.d.ts.map +1 -0
- package/dist/core/control-adapter.d.ts +42 -0
- package/dist/core/control-adapter.d.ts.map +1 -0
- package/dist/core/descriptor.d.ts +24 -0
- package/dist/core/descriptor.d.ts.map +1 -0
- package/dist/{exports/instance-DiZi2k_2.d.ts → core/instance.d.ts} +28 -15
- package/dist/core/instance.d.ts.map +1 -0
- package/dist/core/migrations/plan-helpers.d.ts +20 -0
- package/dist/core/migrations/plan-helpers.d.ts.map +1 -0
- package/dist/core/migrations/policies.d.ts +6 -0
- package/dist/core/migrations/policies.d.ts.map +1 -0
- package/dist/{exports/types-Bh7ftf0Q.d.ts → core/migrations/types.d.ts} +41 -36
- package/dist/core/migrations/types.d.ts.map +1 -0
- package/dist/core/runtime-descriptor.d.ts +19 -0
- package/dist/core/runtime-descriptor.d.ts.map +1 -0
- package/dist/core/runtime-instance.d.ts +54 -0
- package/dist/core/runtime-instance.d.ts.map +1 -0
- package/dist/core/schema-verify/verify-helpers.d.ts +96 -0
- package/dist/core/schema-verify/verify-helpers.d.ts.map +1 -0
- package/dist/core/schema-verify/verify-sql-schema.d.ts +45 -0
- package/dist/core/schema-verify/verify-sql-schema.d.ts.map +1 -0
- package/dist/core/verify.d.ts +39 -0
- package/dist/core/verify.d.ts.map +1 -0
- package/dist/exports/control-adapter.d.ts +2 -44
- package/dist/exports/control-adapter.d.ts.map +1 -0
- package/dist/exports/control.d.ts +8 -160
- package/dist/exports/control.d.ts.map +1 -0
- package/dist/exports/control.js +7 -7
- package/dist/exports/control.js.map +1 -1
- package/dist/exports/runtime.d.ts +3 -61
- package/dist/exports/runtime.d.ts.map +1 -0
- package/dist/exports/schema-verify.d.ts +8 -72
- package/dist/exports/schema-verify.d.ts.map +1 -0
- package/dist/exports/schema-verify.js +5 -1
- package/dist/exports/test-utils.d.ts +5 -31
- package/dist/exports/test-utils.d.ts.map +1 -0
- package/dist/exports/test-utils.js +3 -3
- package/dist/exports/verify.d.ts +2 -28
- package/dist/exports/verify.d.ts.map +1 -0
- package/dist/exports/verify.js +1 -1
- package/package.json +24 -25
- package/src/core/assembly.ts +117 -0
- package/src/core/control-adapter.ts +52 -0
- package/src/core/descriptor.ts +33 -0
- package/src/core/instance.ts +903 -0
- package/src/core/migrations/plan-helpers.ts +164 -0
- package/src/core/migrations/policies.ts +8 -0
- package/src/core/migrations/types.ts +380 -0
- package/src/core/runtime-descriptor.ts +45 -0
- package/src/core/runtime-instance.ts +144 -0
- package/src/core/schema-verify/verify-helpers.ts +532 -0
- package/src/core/schema-verify/verify-sql-schema.ts +588 -0
- package/src/core/verify.ts +177 -0
- package/src/exports/control-adapter.ts +1 -0
- package/src/exports/control.ts +56 -0
- package/src/exports/runtime.ts +7 -0
- package/src/exports/schema-verify.ts +16 -0
- package/src/exports/test-utils.ts +11 -0
- package/src/exports/verify.ts +1 -0
- package/dist/exports/chunk-6P44BVZ4.js.map +0 -1
- package/dist/exports/chunk-C3GKWCKA.js.map +0 -1
- package/dist/exports/chunk-F252JMEU.js.map +0 -1
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
import type { NotOk, Ok } from '@prisma-next/utils/result';
|
|
2
|
+
import { notOk, ok } from '@prisma-next/utils/result';
|
|
3
|
+
import type {
|
|
4
|
+
AnyRecord,
|
|
5
|
+
CreateSqlMigrationPlanOptions,
|
|
6
|
+
SqlMigrationPlan,
|
|
7
|
+
SqlMigrationPlanOperation,
|
|
8
|
+
SqlMigrationPlanOperationStep,
|
|
9
|
+
SqlMigrationPlanOperationTarget,
|
|
10
|
+
SqlMigrationRunnerErrorCode,
|
|
11
|
+
SqlMigrationRunnerFailure,
|
|
12
|
+
SqlMigrationRunnerSuccessValue,
|
|
13
|
+
SqlPlannerConflict,
|
|
14
|
+
SqlPlannerFailureResult,
|
|
15
|
+
SqlPlannerSuccessResult,
|
|
16
|
+
} from './types';
|
|
17
|
+
|
|
18
|
+
const readOnlyEmptyObject: Record<string, never> = Object.freeze({});
|
|
19
|
+
|
|
20
|
+
function cloneRecord<T extends AnyRecord>(value: T): T {
|
|
21
|
+
if (value === readOnlyEmptyObject) {
|
|
22
|
+
return value;
|
|
23
|
+
}
|
|
24
|
+
return Object.freeze({ ...value }) as T;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function freezeSteps(
|
|
28
|
+
steps: readonly SqlMigrationPlanOperationStep[],
|
|
29
|
+
): readonly SqlMigrationPlanOperationStep[] {
|
|
30
|
+
if (steps.length === 0) {
|
|
31
|
+
return Object.freeze([]);
|
|
32
|
+
}
|
|
33
|
+
return Object.freeze(
|
|
34
|
+
steps.map((step) =>
|
|
35
|
+
Object.freeze({
|
|
36
|
+
description: step.description,
|
|
37
|
+
sql: step.sql,
|
|
38
|
+
...(step.meta ? { meta: cloneRecord(step.meta) } : {}),
|
|
39
|
+
}),
|
|
40
|
+
),
|
|
41
|
+
);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function freezeDetailsValue<T>(value: T): T {
|
|
45
|
+
// Primitives and null/undefined are already immutable, return as-is
|
|
46
|
+
if (value === null || value === undefined) {
|
|
47
|
+
return value;
|
|
48
|
+
}
|
|
49
|
+
if (typeof value !== 'object') {
|
|
50
|
+
return value;
|
|
51
|
+
}
|
|
52
|
+
// Arrays: shallow clone and freeze
|
|
53
|
+
if (Array.isArray(value)) {
|
|
54
|
+
return Object.freeze([...value]) as T;
|
|
55
|
+
}
|
|
56
|
+
// Objects: shallow clone and freeze (matching cloneRecord pattern)
|
|
57
|
+
return Object.freeze({ ...value }) as T;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
function freezeTargetDetails<TTargetDetails>(
|
|
61
|
+
target: SqlMigrationPlanOperationTarget<TTargetDetails>,
|
|
62
|
+
): SqlMigrationPlanOperationTarget<TTargetDetails> {
|
|
63
|
+
return Object.freeze({
|
|
64
|
+
id: target.id,
|
|
65
|
+
...(target.details !== undefined ? { details: freezeDetailsValue(target.details) } : {}),
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
function freezeOperation<TTargetDetails>(
|
|
70
|
+
operation: SqlMigrationPlanOperation<TTargetDetails>,
|
|
71
|
+
): SqlMigrationPlanOperation<TTargetDetails> {
|
|
72
|
+
return Object.freeze({
|
|
73
|
+
id: operation.id,
|
|
74
|
+
label: operation.label,
|
|
75
|
+
...(operation.summary ? { summary: operation.summary } : {}),
|
|
76
|
+
operationClass: operation.operationClass,
|
|
77
|
+
target: freezeTargetDetails(operation.target),
|
|
78
|
+
precheck: freezeSteps(operation.precheck),
|
|
79
|
+
execute: freezeSteps(operation.execute),
|
|
80
|
+
postcheck: freezeSteps(operation.postcheck),
|
|
81
|
+
...(operation.meta ? { meta: cloneRecord(operation.meta) } : {}),
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
function freezeOperations<TTargetDetails>(
|
|
86
|
+
operations: readonly SqlMigrationPlanOperation<TTargetDetails>[],
|
|
87
|
+
): readonly SqlMigrationPlanOperation<TTargetDetails>[] {
|
|
88
|
+
if (operations.length === 0) {
|
|
89
|
+
return Object.freeze([]);
|
|
90
|
+
}
|
|
91
|
+
return Object.freeze(operations.map((operation) => freezeOperation(operation)));
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
export function createMigrationPlan<TTargetDetails>(
|
|
95
|
+
options: CreateSqlMigrationPlanOptions<TTargetDetails>,
|
|
96
|
+
): SqlMigrationPlan<TTargetDetails> {
|
|
97
|
+
return Object.freeze({
|
|
98
|
+
targetId: options.targetId,
|
|
99
|
+
...(options.origin !== undefined
|
|
100
|
+
? { origin: options.origin ? Object.freeze({ ...options.origin }) : null }
|
|
101
|
+
: {}),
|
|
102
|
+
destination: Object.freeze({ ...options.destination }),
|
|
103
|
+
operations: freezeOperations(options.operations),
|
|
104
|
+
...(options.meta ? { meta: cloneRecord(options.meta) } : {}),
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
export function plannerSuccess<TTargetDetails>(
|
|
109
|
+
plan: SqlMigrationPlan<TTargetDetails>,
|
|
110
|
+
): SqlPlannerSuccessResult<TTargetDetails> {
|
|
111
|
+
return Object.freeze({
|
|
112
|
+
kind: 'success',
|
|
113
|
+
plan,
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
export function plannerFailure(conflicts: readonly SqlPlannerConflict[]): SqlPlannerFailureResult {
|
|
118
|
+
return Object.freeze({
|
|
119
|
+
kind: 'failure' as const,
|
|
120
|
+
conflicts: Object.freeze(
|
|
121
|
+
conflicts.map((conflict) =>
|
|
122
|
+
Object.freeze({
|
|
123
|
+
kind: conflict.kind,
|
|
124
|
+
summary: conflict.summary,
|
|
125
|
+
...(conflict.why ? { why: conflict.why } : {}),
|
|
126
|
+
...(conflict.location ? { location: Object.freeze({ ...conflict.location }) } : {}),
|
|
127
|
+
...(conflict.meta ? { meta: cloneRecord(conflict.meta) } : {}),
|
|
128
|
+
}),
|
|
129
|
+
),
|
|
130
|
+
),
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* Creates a successful migration runner result.
|
|
136
|
+
*/
|
|
137
|
+
export function runnerSuccess(value: {
|
|
138
|
+
operationsPlanned: number;
|
|
139
|
+
operationsExecuted: number;
|
|
140
|
+
}): Ok<SqlMigrationRunnerSuccessValue> {
|
|
141
|
+
return ok(
|
|
142
|
+
Object.freeze({
|
|
143
|
+
operationsPlanned: value.operationsPlanned,
|
|
144
|
+
operationsExecuted: value.operationsExecuted,
|
|
145
|
+
}),
|
|
146
|
+
);
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
/**
|
|
150
|
+
* Creates a failed migration runner result.
|
|
151
|
+
*/
|
|
152
|
+
export function runnerFailure(
|
|
153
|
+
code: SqlMigrationRunnerErrorCode,
|
|
154
|
+
summary: string,
|
|
155
|
+
options?: { why?: string; meta?: AnyRecord },
|
|
156
|
+
): NotOk<SqlMigrationRunnerFailure> {
|
|
157
|
+
const failure: SqlMigrationRunnerFailure = Object.freeze({
|
|
158
|
+
code,
|
|
159
|
+
summary,
|
|
160
|
+
...(options?.why ? { why: options.why } : {}),
|
|
161
|
+
...(options?.meta ? { meta: cloneRecord(options.meta) } : {}),
|
|
162
|
+
});
|
|
163
|
+
return notOk(failure);
|
|
164
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { MigrationOperationPolicy } from '@prisma-next/core-control-plane/types';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Policy used by `db init`: additive-only operations, no widening/destructive steps.
|
|
5
|
+
*/
|
|
6
|
+
export const INIT_ADDITIVE_POLICY: MigrationOperationPolicy = Object.freeze({
|
|
7
|
+
allowedOperationClasses: Object.freeze(['additive'] as const),
|
|
8
|
+
});
|
|
@@ -0,0 +1,380 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SQL-specific migration types.
|
|
3
|
+
*
|
|
4
|
+
* These types extend the canonical migration types from the framework control plane
|
|
5
|
+
* with SQL-specific fields for execution (precheck SQL, execute SQL, etc.).
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import type { TargetBoundComponentDescriptor } from '@prisma-next/contract/framework-components';
|
|
9
|
+
import type {
|
|
10
|
+
ControlDriverInstance,
|
|
11
|
+
ControlExtensionDescriptor,
|
|
12
|
+
ControlTargetDescriptor,
|
|
13
|
+
ControlTargetInstance,
|
|
14
|
+
MigrationOperationPolicy,
|
|
15
|
+
MigrationPlan,
|
|
16
|
+
MigrationPlannerConflict,
|
|
17
|
+
MigrationPlannerFailureResult,
|
|
18
|
+
MigrationPlannerSuccessResult,
|
|
19
|
+
MigrationPlanOperation,
|
|
20
|
+
MigrationRunnerExecutionChecks,
|
|
21
|
+
MigrationRunnerFailure,
|
|
22
|
+
MigrationRunnerSuccessValue,
|
|
23
|
+
OperationContext,
|
|
24
|
+
SchemaIssue,
|
|
25
|
+
} from '@prisma-next/core-control-plane/types';
|
|
26
|
+
import type { SqlContract, SqlStorage } from '@prisma-next/sql-contract/types';
|
|
27
|
+
import type { SqlSchemaIR } from '@prisma-next/sql-schema-ir/types';
|
|
28
|
+
import type { Result } from '@prisma-next/utils/result';
|
|
29
|
+
import type { SqlControlFamilyInstance } from '../instance';
|
|
30
|
+
|
|
31
|
+
export type AnyRecord = Readonly<Record<string, unknown>>;
|
|
32
|
+
|
|
33
|
+
// ============================================================================
|
|
34
|
+
// Component Database Dependencies
|
|
35
|
+
// ============================================================================
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* A single database dependency declared by a framework component.
|
|
39
|
+
* Uses SqlMigrationPlanOperation so we inherit the existing precheck/execute/postcheck contract.
|
|
40
|
+
*
|
|
41
|
+
* Database dependencies allow components (extensions, adapters) to declare what database-side
|
|
42
|
+
* persistence structures they require (e.g., Postgres extensions, schemas, functions).
|
|
43
|
+
* The planner emits these as migration operations, and the verifier uses the pure verification
|
|
44
|
+
* hook to check satisfaction against the schema IR.
|
|
45
|
+
*/
|
|
46
|
+
export interface ComponentDatabaseDependency<TTargetDetails> {
|
|
47
|
+
/** Stable identifier for the dependency (e.g. 'postgres.extension.vector') */
|
|
48
|
+
readonly id: string;
|
|
49
|
+
/** Human label for output (e.g. 'Enable vector extension') */
|
|
50
|
+
readonly label: string;
|
|
51
|
+
/**
|
|
52
|
+
* Operations that install/ensure the dependency.
|
|
53
|
+
* Use SqlMigrationPlanOperation so we inherit the existing precheck/execute/postcheck contract.
|
|
54
|
+
*/
|
|
55
|
+
readonly install: readonly SqlMigrationPlanOperation<TTargetDetails>[];
|
|
56
|
+
/**
|
|
57
|
+
* Pure verification hook: checks whether this dependency is already installed
|
|
58
|
+
* based on the in-memory schema IR (no DB I/O).
|
|
59
|
+
*
|
|
60
|
+
* This must return structured issues suitable for CLI and tree output, not just a boolean.
|
|
61
|
+
*/
|
|
62
|
+
readonly verifyDatabaseDependencyInstalled: (schema: SqlSchemaIR) => readonly SchemaIssue[];
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Database dependencies declared by a framework component.
|
|
67
|
+
*/
|
|
68
|
+
export interface ComponentDatabaseDependencies<TTargetDetails> {
|
|
69
|
+
/**
|
|
70
|
+
* Dependencies required for db init.
|
|
71
|
+
* Future: update dependencies can be added later (e.g. widening/destructive).
|
|
72
|
+
*/
|
|
73
|
+
readonly init?: readonly ComponentDatabaseDependency<TTargetDetails>[];
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Minimal structural type implemented by any descriptor that can expose
|
|
78
|
+
* component-owned database dependencies. Targets/adapters typically omit
|
|
79
|
+
* the property, while extensions provide dependency metadata.
|
|
80
|
+
*/
|
|
81
|
+
export interface DatabaseDependencyProvider {
|
|
82
|
+
readonly databaseDependencies?: ComponentDatabaseDependencies<unknown>;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
// ============================================================================
|
|
86
|
+
// SQL Control Extension Descriptor
|
|
87
|
+
// ============================================================================
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* SQL-specific extension descriptor with optional database dependencies.
|
|
91
|
+
* Extends the core ControlExtensionDescriptor with SQL-specific metadata.
|
|
92
|
+
*
|
|
93
|
+
* Database dependencies are attached to the descriptor (not the instance) because
|
|
94
|
+
* they are declarative metadata that planner/verifier need without constructing instances.
|
|
95
|
+
*/
|
|
96
|
+
export interface SqlControlExtensionDescriptor<TTargetId extends string>
|
|
97
|
+
extends ControlExtensionDescriptor<'sql', TTargetId> {
|
|
98
|
+
/** Optional database dependencies this extension requires. */
|
|
99
|
+
readonly databaseDependencies?: ComponentDatabaseDependencies<unknown>;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
// ============================================================================
|
|
103
|
+
// SQL-Specific Plan Types
|
|
104
|
+
// ============================================================================
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* A single step in a SQL migration operation (precheck, execute, or postcheck).
|
|
108
|
+
*/
|
|
109
|
+
export interface SqlMigrationPlanOperationStep {
|
|
110
|
+
readonly description: string;
|
|
111
|
+
readonly sql: string;
|
|
112
|
+
readonly meta?: AnyRecord;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* Target details for a SQL migration operation (table, column, index, etc.).
|
|
117
|
+
*/
|
|
118
|
+
export interface SqlMigrationPlanOperationTarget<TTargetDetails> {
|
|
119
|
+
readonly id: string;
|
|
120
|
+
readonly details?: TTargetDetails;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* A single SQL migration operation with SQL-specific fields.
|
|
125
|
+
* Extends the core MigrationPlanOperation with SQL execution details.
|
|
126
|
+
*/
|
|
127
|
+
export interface SqlMigrationPlanOperation<TTargetDetails> extends MigrationPlanOperation {
|
|
128
|
+
/** Optional detailed explanation of what this operation does and why. */
|
|
129
|
+
readonly summary?: string;
|
|
130
|
+
readonly target: SqlMigrationPlanOperationTarget<TTargetDetails>;
|
|
131
|
+
readonly precheck: readonly SqlMigrationPlanOperationStep[];
|
|
132
|
+
readonly execute: readonly SqlMigrationPlanOperationStep[];
|
|
133
|
+
readonly postcheck: readonly SqlMigrationPlanOperationStep[];
|
|
134
|
+
readonly meta?: AnyRecord;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* Contract identity information for SQL migrations.
|
|
139
|
+
*/
|
|
140
|
+
export interface SqlMigrationPlanContractInfo {
|
|
141
|
+
readonly coreHash: string;
|
|
142
|
+
readonly profileHash?: string;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
/**
|
|
146
|
+
* A SQL migration plan with SQL-specific fields.
|
|
147
|
+
* Extends the core MigrationPlan with origin tracking and metadata.
|
|
148
|
+
*/
|
|
149
|
+
export interface SqlMigrationPlan<TTargetDetails> extends MigrationPlan {
|
|
150
|
+
/**
|
|
151
|
+
* Origin contract identity that the plan expects the database to currently be at.
|
|
152
|
+
* If omitted, the runner treats the origin as "no marker present" (empty database),
|
|
153
|
+
* and will only proceed if no marker exists (or if the marker already matches destination).
|
|
154
|
+
*/
|
|
155
|
+
readonly origin?: SqlMigrationPlanContractInfo | null;
|
|
156
|
+
/**
|
|
157
|
+
* Destination contract identity that the plan intends to reach.
|
|
158
|
+
*/
|
|
159
|
+
readonly destination: SqlMigrationPlanContractInfo;
|
|
160
|
+
readonly operations: readonly SqlMigrationPlanOperation<TTargetDetails>[];
|
|
161
|
+
readonly meta?: AnyRecord;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
// ============================================================================
|
|
165
|
+
// SQL-Specific Planner Types
|
|
166
|
+
// ============================================================================
|
|
167
|
+
|
|
168
|
+
/**
|
|
169
|
+
* Specific conflict kinds for SQL migrations.
|
|
170
|
+
*/
|
|
171
|
+
export type SqlPlannerConflictKind =
|
|
172
|
+
| 'typeMismatch'
|
|
173
|
+
| 'nullabilityConflict'
|
|
174
|
+
| 'indexIncompatible'
|
|
175
|
+
| 'foreignKeyConflict'
|
|
176
|
+
| 'missingButNonAdditive'
|
|
177
|
+
| 'unsupportedExtension'
|
|
178
|
+
| 'extensionMissing'
|
|
179
|
+
| 'unsupportedOperation';
|
|
180
|
+
|
|
181
|
+
/**
|
|
182
|
+
* Location information for SQL planner conflicts.
|
|
183
|
+
*/
|
|
184
|
+
export interface SqlPlannerConflictLocation {
|
|
185
|
+
readonly table?: string;
|
|
186
|
+
readonly column?: string;
|
|
187
|
+
readonly index?: string;
|
|
188
|
+
readonly constraint?: string;
|
|
189
|
+
readonly extension?: string;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
/**
|
|
193
|
+
* A SQL-specific planner conflict with additional location information.
|
|
194
|
+
* Extends the core MigrationPlannerConflict.
|
|
195
|
+
*/
|
|
196
|
+
export interface SqlPlannerConflict extends MigrationPlannerConflict {
|
|
197
|
+
readonly kind: SqlPlannerConflictKind;
|
|
198
|
+
readonly location?: SqlPlannerConflictLocation;
|
|
199
|
+
readonly meta?: AnyRecord;
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
/**
|
|
203
|
+
* Successful SQL planner result with the migration plan.
|
|
204
|
+
*/
|
|
205
|
+
export interface SqlPlannerSuccessResult<TTargetDetails>
|
|
206
|
+
extends Omit<MigrationPlannerSuccessResult, 'plan'> {
|
|
207
|
+
readonly kind: 'success';
|
|
208
|
+
readonly plan: SqlMigrationPlan<TTargetDetails>;
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
/**
|
|
212
|
+
* Failed SQL planner result with the list of conflicts.
|
|
213
|
+
*/
|
|
214
|
+
export interface SqlPlannerFailureResult extends Omit<MigrationPlannerFailureResult, 'conflicts'> {
|
|
215
|
+
readonly kind: 'failure';
|
|
216
|
+
readonly conflicts: readonly SqlPlannerConflict[];
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
/**
|
|
220
|
+
* Union type for SQL planner results.
|
|
221
|
+
*/
|
|
222
|
+
export type SqlPlannerResult<TTargetDetails> =
|
|
223
|
+
| SqlPlannerSuccessResult<TTargetDetails>
|
|
224
|
+
| SqlPlannerFailureResult;
|
|
225
|
+
|
|
226
|
+
/**
|
|
227
|
+
* Options for SQL migration planner.
|
|
228
|
+
*/
|
|
229
|
+
export interface SqlMigrationPlannerPlanOptions {
|
|
230
|
+
readonly contract: SqlContract<SqlStorage>;
|
|
231
|
+
readonly schema: SqlSchemaIR;
|
|
232
|
+
readonly policy: MigrationOperationPolicy;
|
|
233
|
+
readonly schemaName?: string;
|
|
234
|
+
/**
|
|
235
|
+
* Active framework components participating in this composition.
|
|
236
|
+
* SQL targets can interpret this list to derive database dependencies.
|
|
237
|
+
* All components must have matching familyId ('sql') and targetId.
|
|
238
|
+
*/
|
|
239
|
+
readonly frameworkComponents: ReadonlyArray<TargetBoundComponentDescriptor<'sql', string>>;
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
/**
|
|
243
|
+
* SQL migration planner interface.
|
|
244
|
+
* Extends the core MigrationPlanner with SQL-specific types.
|
|
245
|
+
*/
|
|
246
|
+
export interface SqlMigrationPlanner<TTargetDetails> {
|
|
247
|
+
plan(options: SqlMigrationPlannerPlanOptions): SqlPlannerResult<TTargetDetails>;
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
// ============================================================================
|
|
251
|
+
// SQL-Specific Runner Types
|
|
252
|
+
// ============================================================================
|
|
253
|
+
|
|
254
|
+
/**
|
|
255
|
+
* Callbacks for SQL migration runner execution.
|
|
256
|
+
*/
|
|
257
|
+
export interface SqlMigrationRunnerExecuteCallbacks<TTargetDetails> {
|
|
258
|
+
onOperationStart?(operation: SqlMigrationPlanOperation<TTargetDetails>): void;
|
|
259
|
+
onOperationComplete?(operation: SqlMigrationPlanOperation<TTargetDetails>): void;
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
/**
|
|
263
|
+
* Options for SQL migration runner execution.
|
|
264
|
+
*/
|
|
265
|
+
export interface SqlMigrationRunnerExecuteOptions<TTargetDetails> {
|
|
266
|
+
readonly plan: SqlMigrationPlan<TTargetDetails>;
|
|
267
|
+
readonly driver: ControlDriverInstance<'sql', string>;
|
|
268
|
+
/**
|
|
269
|
+
* Destination contract IR.
|
|
270
|
+
* Must correspond to `plan.destination` and is used for schema verification and marker/ledger writes.
|
|
271
|
+
*/
|
|
272
|
+
readonly destinationContract: SqlContract<SqlStorage>;
|
|
273
|
+
/**
|
|
274
|
+
* Execution-time policy that defines which operation classes are allowed.
|
|
275
|
+
* The runner validates each operation against this policy before execution.
|
|
276
|
+
*/
|
|
277
|
+
readonly policy: MigrationOperationPolicy;
|
|
278
|
+
readonly schemaName?: string;
|
|
279
|
+
readonly strictVerification?: boolean;
|
|
280
|
+
readonly callbacks?: SqlMigrationRunnerExecuteCallbacks<TTargetDetails>;
|
|
281
|
+
readonly context?: OperationContext;
|
|
282
|
+
/**
|
|
283
|
+
* Execution-time checks configuration.
|
|
284
|
+
* All checks default to `true` (enabled) when omitted.
|
|
285
|
+
*/
|
|
286
|
+
readonly executionChecks?: MigrationRunnerExecutionChecks;
|
|
287
|
+
/**
|
|
288
|
+
* Active framework components participating in this composition.
|
|
289
|
+
* SQL targets can interpret this list to derive database dependencies.
|
|
290
|
+
* All components must have matching familyId ('sql') and targetId.
|
|
291
|
+
*/
|
|
292
|
+
readonly frameworkComponents: ReadonlyArray<TargetBoundComponentDescriptor<'sql', string>>;
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
/**
|
|
296
|
+
* Error codes for SQL migration runner failures.
|
|
297
|
+
*/
|
|
298
|
+
export type SqlMigrationRunnerErrorCode =
|
|
299
|
+
| 'DESTINATION_CONTRACT_MISMATCH'
|
|
300
|
+
| 'MARKER_ORIGIN_MISMATCH'
|
|
301
|
+
| 'POLICY_VIOLATION'
|
|
302
|
+
| 'PRECHECK_FAILED'
|
|
303
|
+
| 'POSTCHECK_FAILED'
|
|
304
|
+
| 'SCHEMA_VERIFY_FAILED'
|
|
305
|
+
| 'EXECUTION_FAILED';
|
|
306
|
+
|
|
307
|
+
/**
|
|
308
|
+
* Detailed information about a SQL migration runner failure.
|
|
309
|
+
* Extends the core MigrationRunnerFailure with SQL-specific error codes.
|
|
310
|
+
*/
|
|
311
|
+
export interface SqlMigrationRunnerFailure extends MigrationRunnerFailure {
|
|
312
|
+
readonly code: SqlMigrationRunnerErrorCode;
|
|
313
|
+
readonly meta?: AnyRecord;
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
/**
|
|
317
|
+
* Success value for SQL migration runner execution.
|
|
318
|
+
* Extends core type for type branding and potential SQL-specific extensions.
|
|
319
|
+
*/
|
|
320
|
+
export interface SqlMigrationRunnerSuccessValue extends MigrationRunnerSuccessValue {}
|
|
321
|
+
|
|
322
|
+
/**
|
|
323
|
+
* Result type for SQL migration runner execution.
|
|
324
|
+
*/
|
|
325
|
+
export type SqlMigrationRunnerResult = Result<
|
|
326
|
+
SqlMigrationRunnerSuccessValue,
|
|
327
|
+
SqlMigrationRunnerFailure
|
|
328
|
+
>;
|
|
329
|
+
|
|
330
|
+
/**
|
|
331
|
+
* SQL migration runner interface.
|
|
332
|
+
* Extends the core MigrationRunner with SQL-specific types.
|
|
333
|
+
*/
|
|
334
|
+
export interface SqlMigrationRunner<TTargetDetails> {
|
|
335
|
+
execute(
|
|
336
|
+
options: SqlMigrationRunnerExecuteOptions<TTargetDetails>,
|
|
337
|
+
): Promise<SqlMigrationRunnerResult>;
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
// ============================================================================
|
|
341
|
+
// SQL Control Target Descriptor
|
|
342
|
+
// ============================================================================
|
|
343
|
+
|
|
344
|
+
/**
|
|
345
|
+
* SQL control target descriptor with migration support.
|
|
346
|
+
* Extends the core ControlTargetDescriptor with SQL-specific migration methods.
|
|
347
|
+
*/
|
|
348
|
+
export interface SqlControlTargetDescriptor<TTargetId extends string, TTargetDetails>
|
|
349
|
+
extends ControlTargetDescriptor<
|
|
350
|
+
'sql',
|
|
351
|
+
TTargetId,
|
|
352
|
+
ControlTargetInstance<'sql', TTargetId>,
|
|
353
|
+
SqlControlFamilyInstance
|
|
354
|
+
> {
|
|
355
|
+
/**
|
|
356
|
+
* Creates a SQL migration planner for this target.
|
|
357
|
+
* Direct method for SQL-specific usage.
|
|
358
|
+
*/
|
|
359
|
+
createPlanner(family: SqlControlFamilyInstance): SqlMigrationPlanner<TTargetDetails>;
|
|
360
|
+
/**
|
|
361
|
+
* Creates a SQL migration runner for this target.
|
|
362
|
+
* Direct method for SQL-specific usage.
|
|
363
|
+
*/
|
|
364
|
+
createRunner(family: SqlControlFamilyInstance): SqlMigrationRunner<TTargetDetails>;
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
// ============================================================================
|
|
368
|
+
// Helper Types
|
|
369
|
+
// ============================================================================
|
|
370
|
+
|
|
371
|
+
/**
|
|
372
|
+
* Options for creating a SQL migration plan.
|
|
373
|
+
*/
|
|
374
|
+
export interface CreateSqlMigrationPlanOptions<TTargetDetails> {
|
|
375
|
+
readonly targetId: string;
|
|
376
|
+
readonly origin?: SqlMigrationPlanContractInfo | null;
|
|
377
|
+
readonly destination: SqlMigrationPlanContractInfo;
|
|
378
|
+
readonly operations: readonly SqlMigrationPlanOperation<TTargetDetails>[];
|
|
379
|
+
readonly meta?: AnyRecord;
|
|
380
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
RuntimeAdapterDescriptor,
|
|
3
|
+
RuntimeDriverDescriptor,
|
|
4
|
+
RuntimeExtensionDescriptor,
|
|
5
|
+
RuntimeFamilyDescriptor,
|
|
6
|
+
RuntimeTargetDescriptor,
|
|
7
|
+
} from '@prisma-next/core-execution-plane/types';
|
|
8
|
+
import {
|
|
9
|
+
createSqlRuntimeFamilyInstance,
|
|
10
|
+
type SqlRuntimeAdapterInstance,
|
|
11
|
+
type SqlRuntimeDriverInstance,
|
|
12
|
+
type SqlRuntimeFamilyInstance,
|
|
13
|
+
} from './runtime-instance';
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* SQL runtime family descriptor implementation.
|
|
17
|
+
* Provides factory method to create SQL runtime family instance.
|
|
18
|
+
*/
|
|
19
|
+
export class SqlRuntimeFamilyDescriptor
|
|
20
|
+
implements RuntimeFamilyDescriptor<'sql', SqlRuntimeFamilyInstance>
|
|
21
|
+
{
|
|
22
|
+
readonly kind = 'family' as const;
|
|
23
|
+
readonly id = 'sql';
|
|
24
|
+
readonly familyId = 'sql' as const;
|
|
25
|
+
readonly version = '0.0.1';
|
|
26
|
+
|
|
27
|
+
create<TTargetId extends string>(options: {
|
|
28
|
+
readonly target: RuntimeTargetDescriptor<'sql', TTargetId>;
|
|
29
|
+
readonly adapter: RuntimeAdapterDescriptor<
|
|
30
|
+
'sql',
|
|
31
|
+
TTargetId,
|
|
32
|
+
SqlRuntimeAdapterInstance<TTargetId>
|
|
33
|
+
>;
|
|
34
|
+
readonly driver: RuntimeDriverDescriptor<'sql', TTargetId, SqlRuntimeDriverInstance<TTargetId>>;
|
|
35
|
+
readonly extensionPacks: readonly RuntimeExtensionDescriptor<'sql', TTargetId>[];
|
|
36
|
+
}): SqlRuntimeFamilyInstance {
|
|
37
|
+
return createSqlRuntimeFamilyInstance({
|
|
38
|
+
family: this,
|
|
39
|
+
target: options.target,
|
|
40
|
+
adapter: options.adapter,
|
|
41
|
+
driver: options.driver,
|
|
42
|
+
extensionPacks: options.extensionPacks,
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
}
|