@prisma-next/family-sql 0.3.0-dev.4 → 0.3.0-dev.41
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 +11 -6
- package/dist/assembly-BVS641kd.mjs +106 -0
- package/dist/assembly-BVS641kd.mjs.map +1 -0
- package/dist/control-adapter.d.mts +60 -0
- package/dist/control-adapter.d.mts.map +1 -0
- package/dist/control-adapter.mjs +1 -0
- package/dist/control-instance-CWKSpACr.d.mts +292 -0
- package/dist/control-instance-CWKSpACr.d.mts.map +1 -0
- package/dist/control.d.mts +64 -0
- package/dist/control.d.mts.map +1 -0
- package/dist/control.mjs +534 -0
- package/dist/control.mjs.map +1 -0
- package/dist/runtime.d.mts +27 -0
- package/dist/runtime.d.mts.map +1 -0
- package/dist/runtime.mjs +38 -0
- package/dist/runtime.mjs.map +1 -0
- package/dist/schema-verify.d.mts +48 -0
- package/dist/schema-verify.d.mts.map +1 -0
- package/dist/schema-verify.mjs +4 -0
- package/dist/test-utils.d.mts +2 -0
- package/dist/test-utils.mjs +3 -0
- package/dist/verify-BfMETJcM.mjs +108 -0
- package/dist/verify-BfMETJcM.mjs.map +1 -0
- package/dist/verify-sql-schema-DMG0mz1g.mjs +997 -0
- package/dist/verify-sql-schema-DMG0mz1g.mjs.map +1 -0
- package/dist/verify-sql-schema-DhHnkpPa.d.mts +67 -0
- package/dist/verify-sql-schema-DhHnkpPa.d.mts.map +1 -0
- package/dist/{exports/verify.d.ts → verify.d.mts} +8 -5
- package/dist/verify.d.mts.map +1 -0
- package/dist/verify.mjs +3 -0
- package/package.json +38 -48
- package/src/core/assembly.ts +216 -0
- package/src/core/control-adapter.ts +67 -0
- package/src/core/control-descriptor.ts +37 -0
- package/src/core/control-instance.ts +750 -0
- package/src/core/migrations/plan-helpers.ts +164 -0
- package/src/core/migrations/policies.ts +8 -0
- package/src/core/migrations/types.ts +279 -0
- package/src/core/runtime-descriptor.ts +23 -0
- package/src/core/runtime-instance.ts +22 -0
- package/src/core/schema-verify/verify-helpers.ts +532 -0
- package/src/core/schema-verify/verify-sql-schema.ts +1102 -0
- package/src/core/verify.ts +168 -0
- package/src/exports/control-adapter.ts +1 -0
- package/src/exports/control.ts +59 -0
- package/src/exports/runtime.ts +3 -0
- package/src/exports/schema-verify.ts +19 -0
- package/src/exports/test-utils.ts +10 -0
- package/src/exports/verify.ts +1 -0
- package/dist/exports/chunk-6P44BVZ4.js +0 -580
- package/dist/exports/chunk-6P44BVZ4.js.map +0 -1
- package/dist/exports/chunk-C3GKWCKA.js +0 -96
- package/dist/exports/chunk-C3GKWCKA.js.map +0 -1
- package/dist/exports/chunk-F252JMEU.js +0 -772
- package/dist/exports/chunk-F252JMEU.js.map +0 -1
- package/dist/exports/control-adapter.d.ts +0 -44
- package/dist/exports/control-adapter.js +0 -1
- package/dist/exports/control-adapter.js.map +0 -1
- package/dist/exports/control.d.ts +0 -75
- package/dist/exports/control.js +0 -149
- package/dist/exports/control.js.map +0 -1
- package/dist/exports/instance-DiZi2k_2.d.ts +0 -127
- package/dist/exports/runtime.d.ts +0 -66
- package/dist/exports/runtime.js +0 -64
- package/dist/exports/runtime.js.map +0 -1
- package/dist/exports/schema-verify.d.ts +0 -75
- package/dist/exports/schema-verify.js +0 -11
- package/dist/exports/schema-verify.js.map +0 -1
- package/dist/exports/test-utils.d.ts +0 -33
- package/dist/exports/test-utils.js +0 -17
- package/dist/exports/test-utils.js.map +0 -1
- package/dist/exports/types-Bh7ftf0Q.d.ts +0 -275
- package/dist/exports/verify.js +0 -11
- package/dist/exports/verify.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,279 @@
|
|
|
1
|
+
import type { TargetBoundComponentDescriptor } from '@prisma-next/contract/framework-components';
|
|
2
|
+
import type {
|
|
3
|
+
ControlAdapterDescriptor,
|
|
4
|
+
ControlDriverInstance,
|
|
5
|
+
ControlExtensionDescriptor,
|
|
6
|
+
ControlTargetDescriptor,
|
|
7
|
+
ControlTargetInstance,
|
|
8
|
+
MigrationOperationPolicy,
|
|
9
|
+
MigrationPlan,
|
|
10
|
+
MigrationPlannerConflict,
|
|
11
|
+
MigrationPlannerFailureResult,
|
|
12
|
+
MigrationPlannerSuccessResult,
|
|
13
|
+
MigrationPlanOperation,
|
|
14
|
+
MigrationRunnerExecutionChecks,
|
|
15
|
+
MigrationRunnerFailure,
|
|
16
|
+
MigrationRunnerSuccessValue,
|
|
17
|
+
OperationContext,
|
|
18
|
+
SchemaIssue,
|
|
19
|
+
} from '@prisma-next/core-control-plane/types';
|
|
20
|
+
import type { SqlContract, SqlStorage, StorageTypeInstance } from '@prisma-next/sql-contract/types';
|
|
21
|
+
import type { SqlOperationSignature } from '@prisma-next/sql-operations';
|
|
22
|
+
import type { SqlSchemaIR } from '@prisma-next/sql-schema-ir/types';
|
|
23
|
+
import type { Result } from '@prisma-next/utils/result';
|
|
24
|
+
import type { SqlControlFamilyInstance } from '../control-instance';
|
|
25
|
+
|
|
26
|
+
export type AnyRecord = Readonly<Record<string, unknown>>;
|
|
27
|
+
|
|
28
|
+
export interface SqlControlStaticContributions {
|
|
29
|
+
readonly operationSignatures: () => ReadonlyArray<SqlOperationSignature>;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export interface ComponentDatabaseDependency<TTargetDetails> {
|
|
33
|
+
readonly id: string;
|
|
34
|
+
readonly label: string;
|
|
35
|
+
readonly install: readonly SqlMigrationPlanOperation<TTargetDetails>[];
|
|
36
|
+
readonly verifyDatabaseDependencyInstalled: (schema: SqlSchemaIR) => readonly SchemaIssue[];
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export interface ComponentDatabaseDependencies<TTargetDetails> {
|
|
40
|
+
readonly init?: readonly ComponentDatabaseDependency<TTargetDetails>[];
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export interface DatabaseDependencyProvider {
|
|
44
|
+
readonly databaseDependencies?: ComponentDatabaseDependencies<unknown>;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export interface StorageTypePlanResult<TTargetDetails> {
|
|
48
|
+
readonly operations: readonly SqlMigrationPlanOperation<TTargetDetails>[];
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Input for expanding parameterized native types.
|
|
53
|
+
*/
|
|
54
|
+
export interface ExpandNativeTypeInput {
|
|
55
|
+
readonly nativeType: string;
|
|
56
|
+
readonly codecId?: string;
|
|
57
|
+
readonly typeParams?: Record<string, unknown>;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export interface CodecControlHooks<TTargetDetails = unknown> {
|
|
61
|
+
planTypeOperations?: (options: {
|
|
62
|
+
readonly typeName: string;
|
|
63
|
+
readonly typeInstance: StorageTypeInstance;
|
|
64
|
+
readonly contract: SqlContract<SqlStorage>;
|
|
65
|
+
readonly schema: SqlSchemaIR;
|
|
66
|
+
readonly schemaName?: string;
|
|
67
|
+
readonly policy: MigrationOperationPolicy;
|
|
68
|
+
}) => StorageTypePlanResult<TTargetDetails>;
|
|
69
|
+
verifyType?: (options: {
|
|
70
|
+
readonly typeName: string;
|
|
71
|
+
readonly typeInstance: StorageTypeInstance;
|
|
72
|
+
readonly schema: SqlSchemaIR;
|
|
73
|
+
readonly schemaName?: string;
|
|
74
|
+
}) => readonly SchemaIssue[];
|
|
75
|
+
introspectTypes?: (options: {
|
|
76
|
+
readonly driver: ControlDriverInstance<'sql', string>;
|
|
77
|
+
readonly schemaName?: string;
|
|
78
|
+
}) => Promise<Record<string, StorageTypeInstance>>;
|
|
79
|
+
/**
|
|
80
|
+
* Expands a parameterized native type to its full SQL representation.
|
|
81
|
+
* Used by schema verification to compare contract types against database types.
|
|
82
|
+
*
|
|
83
|
+
* For example, expands:
|
|
84
|
+
* - { nativeType: 'character varying', typeParams: { length: 255 } } -> 'character varying(255)'
|
|
85
|
+
* - { nativeType: 'numeric', typeParams: { precision: 10, scale: 2 } } -> 'numeric(10,2)'
|
|
86
|
+
*
|
|
87
|
+
* Returns the expanded type string, or the original nativeType if no expansion is needed.
|
|
88
|
+
*/
|
|
89
|
+
expandNativeType?: (input: ExpandNativeTypeInput) => string;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
export interface SqlControlExtensionDescriptor<TTargetId extends string>
|
|
93
|
+
extends ControlExtensionDescriptor<'sql', TTargetId>,
|
|
94
|
+
SqlControlStaticContributions {
|
|
95
|
+
readonly databaseDependencies?: ComponentDatabaseDependencies<unknown>;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
export interface SqlControlAdapterDescriptor<TTargetId extends string>
|
|
99
|
+
extends ControlAdapterDescriptor<'sql', TTargetId>,
|
|
100
|
+
SqlControlStaticContributions {}
|
|
101
|
+
|
|
102
|
+
export interface SqlMigrationPlanOperationStep {
|
|
103
|
+
readonly description: string;
|
|
104
|
+
readonly sql: string;
|
|
105
|
+
readonly meta?: AnyRecord;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
export interface SqlMigrationPlanOperationTarget<TTargetDetails> {
|
|
109
|
+
readonly id: string;
|
|
110
|
+
readonly details?: TTargetDetails;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
export interface SqlMigrationPlanOperation<TTargetDetails> extends MigrationPlanOperation {
|
|
114
|
+
readonly summary?: string;
|
|
115
|
+
readonly target: SqlMigrationPlanOperationTarget<TTargetDetails>;
|
|
116
|
+
readonly precheck: readonly SqlMigrationPlanOperationStep[];
|
|
117
|
+
readonly execute: readonly SqlMigrationPlanOperationStep[];
|
|
118
|
+
readonly postcheck: readonly SqlMigrationPlanOperationStep[];
|
|
119
|
+
readonly meta?: AnyRecord;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
export interface SqlMigrationPlanContractInfo {
|
|
123
|
+
readonly storageHash: string;
|
|
124
|
+
readonly profileHash?: string;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
export interface SqlMigrationPlan<TTargetDetails> extends MigrationPlan {
|
|
128
|
+
/**
|
|
129
|
+
* Origin contract identity that the plan expects the database to currently be at.
|
|
130
|
+
* If omitted, the runner treats the origin as "no marker present" (empty database),
|
|
131
|
+
* and will only proceed if no marker exists (or if the marker already matches destination).
|
|
132
|
+
*/
|
|
133
|
+
readonly origin?: SqlMigrationPlanContractInfo | null;
|
|
134
|
+
/**
|
|
135
|
+
* Destination contract identity that the plan intends to reach.
|
|
136
|
+
*/
|
|
137
|
+
readonly destination: SqlMigrationPlanContractInfo;
|
|
138
|
+
readonly operations: readonly SqlMigrationPlanOperation<TTargetDetails>[];
|
|
139
|
+
readonly meta?: AnyRecord;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
export type SqlPlannerConflictKind =
|
|
143
|
+
| 'typeMismatch'
|
|
144
|
+
| 'nullabilityConflict'
|
|
145
|
+
| 'indexIncompatible'
|
|
146
|
+
| 'foreignKeyConflict'
|
|
147
|
+
| 'missingButNonAdditive'
|
|
148
|
+
| 'unsupportedExtension'
|
|
149
|
+
| 'extensionMissing'
|
|
150
|
+
| 'unsupportedOperation';
|
|
151
|
+
|
|
152
|
+
export interface SqlPlannerConflictLocation {
|
|
153
|
+
readonly table?: string;
|
|
154
|
+
readonly column?: string;
|
|
155
|
+
readonly index?: string;
|
|
156
|
+
readonly constraint?: string;
|
|
157
|
+
readonly extension?: string;
|
|
158
|
+
readonly type?: string;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
export interface SqlPlannerConflict extends MigrationPlannerConflict {
|
|
162
|
+
readonly kind: SqlPlannerConflictKind;
|
|
163
|
+
readonly location?: SqlPlannerConflictLocation;
|
|
164
|
+
readonly meta?: AnyRecord;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
export interface SqlPlannerSuccessResult<TTargetDetails>
|
|
168
|
+
extends Omit<MigrationPlannerSuccessResult, 'plan'> {
|
|
169
|
+
readonly kind: 'success';
|
|
170
|
+
readonly plan: SqlMigrationPlan<TTargetDetails>;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
export interface SqlPlannerFailureResult extends Omit<MigrationPlannerFailureResult, 'conflicts'> {
|
|
174
|
+
readonly kind: 'failure';
|
|
175
|
+
readonly conflicts: readonly SqlPlannerConflict[];
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
export type SqlPlannerResult<TTargetDetails> =
|
|
179
|
+
| SqlPlannerSuccessResult<TTargetDetails>
|
|
180
|
+
| SqlPlannerFailureResult;
|
|
181
|
+
|
|
182
|
+
export interface SqlMigrationPlannerPlanOptions {
|
|
183
|
+
readonly contract: SqlContract<SqlStorage>;
|
|
184
|
+
readonly schema: SqlSchemaIR;
|
|
185
|
+
readonly policy: MigrationOperationPolicy;
|
|
186
|
+
readonly schemaName?: string;
|
|
187
|
+
/**
|
|
188
|
+
* Active framework components participating in this composition.
|
|
189
|
+
* SQL targets can interpret this list to derive database dependencies.
|
|
190
|
+
* All components must have matching familyId ('sql') and targetId.
|
|
191
|
+
*/
|
|
192
|
+
readonly frameworkComponents: ReadonlyArray<TargetBoundComponentDescriptor<'sql', string>>;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
export interface SqlMigrationPlanner<TTargetDetails> {
|
|
196
|
+
plan(options: SqlMigrationPlannerPlanOptions): SqlPlannerResult<TTargetDetails>;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
export interface SqlMigrationRunnerExecuteCallbacks<TTargetDetails> {
|
|
200
|
+
onOperationStart?(operation: SqlMigrationPlanOperation<TTargetDetails>): void;
|
|
201
|
+
onOperationComplete?(operation: SqlMigrationPlanOperation<TTargetDetails>): void;
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
export interface SqlMigrationRunnerExecuteOptions<TTargetDetails> {
|
|
205
|
+
readonly plan: SqlMigrationPlan<TTargetDetails>;
|
|
206
|
+
readonly driver: ControlDriverInstance<'sql', string>;
|
|
207
|
+
/**
|
|
208
|
+
* Destination contract IR.
|
|
209
|
+
* Must correspond to `plan.destination` and is used for schema verification and marker/ledger writes.
|
|
210
|
+
*/
|
|
211
|
+
readonly destinationContract: SqlContract<SqlStorage>;
|
|
212
|
+
/**
|
|
213
|
+
* Execution-time policy that defines which operation classes are allowed.
|
|
214
|
+
* The runner validates each operation against this policy before execution.
|
|
215
|
+
*/
|
|
216
|
+
readonly policy: MigrationOperationPolicy;
|
|
217
|
+
readonly schemaName?: string;
|
|
218
|
+
readonly strictVerification?: boolean;
|
|
219
|
+
readonly callbacks?: SqlMigrationRunnerExecuteCallbacks<TTargetDetails>;
|
|
220
|
+
readonly context?: OperationContext;
|
|
221
|
+
/**
|
|
222
|
+
* Execution-time checks configuration.
|
|
223
|
+
* All checks default to `true` (enabled) when omitted.
|
|
224
|
+
*/
|
|
225
|
+
readonly executionChecks?: MigrationRunnerExecutionChecks;
|
|
226
|
+
/**
|
|
227
|
+
* Active framework components participating in this composition.
|
|
228
|
+
* SQL targets can interpret this list to derive database dependencies.
|
|
229
|
+
* All components must have matching familyId ('sql') and targetId.
|
|
230
|
+
*/
|
|
231
|
+
readonly frameworkComponents: ReadonlyArray<TargetBoundComponentDescriptor<'sql', string>>;
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
export type SqlMigrationRunnerErrorCode =
|
|
235
|
+
| 'DESTINATION_CONTRACT_MISMATCH'
|
|
236
|
+
| 'MARKER_ORIGIN_MISMATCH'
|
|
237
|
+
| 'POLICY_VIOLATION'
|
|
238
|
+
| 'PRECHECK_FAILED'
|
|
239
|
+
| 'POSTCHECK_FAILED'
|
|
240
|
+
| 'SCHEMA_VERIFY_FAILED'
|
|
241
|
+
| 'EXECUTION_FAILED';
|
|
242
|
+
|
|
243
|
+
export interface SqlMigrationRunnerFailure extends MigrationRunnerFailure {
|
|
244
|
+
readonly code: SqlMigrationRunnerErrorCode;
|
|
245
|
+
readonly meta?: AnyRecord;
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
export interface SqlMigrationRunnerSuccessValue extends MigrationRunnerSuccessValue {}
|
|
249
|
+
|
|
250
|
+
export type SqlMigrationRunnerResult = Result<
|
|
251
|
+
SqlMigrationRunnerSuccessValue,
|
|
252
|
+
SqlMigrationRunnerFailure
|
|
253
|
+
>;
|
|
254
|
+
|
|
255
|
+
export interface SqlMigrationRunner<TTargetDetails> {
|
|
256
|
+
execute(
|
|
257
|
+
options: SqlMigrationRunnerExecuteOptions<TTargetDetails>,
|
|
258
|
+
): Promise<SqlMigrationRunnerResult>;
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
export interface SqlControlTargetDescriptor<TTargetId extends string, TTargetDetails>
|
|
262
|
+
extends ControlTargetDescriptor<
|
|
263
|
+
'sql',
|
|
264
|
+
TTargetId,
|
|
265
|
+
ControlTargetInstance<'sql', TTargetId>,
|
|
266
|
+
SqlControlFamilyInstance
|
|
267
|
+
>,
|
|
268
|
+
SqlControlStaticContributions {
|
|
269
|
+
createPlanner(family: SqlControlFamilyInstance): SqlMigrationPlanner<TTargetDetails>;
|
|
270
|
+
createRunner(family: SqlControlFamilyInstance): SqlMigrationRunner<TTargetDetails>;
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
export interface CreateSqlMigrationPlanOptions<TTargetDetails> {
|
|
274
|
+
readonly targetId: string;
|
|
275
|
+
readonly origin?: SqlMigrationPlanContractInfo | null;
|
|
276
|
+
readonly destination: SqlMigrationPlanContractInfo;
|
|
277
|
+
readonly operations: readonly SqlMigrationPlanOperation<TTargetDetails>[];
|
|
278
|
+
readonly meta?: AnyRecord;
|
|
279
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { RuntimeFamilyDescriptor } from '@prisma-next/core-execution-plane/types';
|
|
2
|
+
import { createSqlRuntimeFamilyInstance, type SqlRuntimeFamilyInstance } from './runtime-instance';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* SQL execution-plane family descriptor.
|
|
6
|
+
*
|
|
7
|
+
* Note: this is currently named `sqlRuntimeFamilyDescriptor` because the execution plane
|
|
8
|
+
* framework types are still using the `Runtime*` naming (`RuntimeFamilyDescriptor`, etc.).
|
|
9
|
+
*
|
|
10
|
+
* This will be renamed to `sqlExecutionFamilyDescriptor` as part of `TML-1842`.
|
|
11
|
+
*/
|
|
12
|
+
export const sqlRuntimeFamilyDescriptor: RuntimeFamilyDescriptor<'sql', SqlRuntimeFamilyInstance> =
|
|
13
|
+
{
|
|
14
|
+
kind: 'family',
|
|
15
|
+
id: 'sql',
|
|
16
|
+
familyId: 'sql',
|
|
17
|
+
version: '0.0.1',
|
|
18
|
+
create() {
|
|
19
|
+
return createSqlRuntimeFamilyInstance();
|
|
20
|
+
},
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
Object.freeze(sqlRuntimeFamilyDescriptor);
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { RuntimeFamilyInstance } from '@prisma-next/core-execution-plane/types';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* SQL execution-plane family instance interface.
|
|
5
|
+
*
|
|
6
|
+
* Note: this is currently named `SqlRuntimeFamilyInstance` because the execution plane
|
|
7
|
+
* framework types are still using the `Runtime*` naming (`RuntimeFamilyInstance`, etc.).
|
|
8
|
+
*
|
|
9
|
+
* This will be renamed to `SqlExecutionFamilyInstance` as part of `TML-1842`.
|
|
10
|
+
*/
|
|
11
|
+
export interface SqlRuntimeFamilyInstance extends RuntimeFamilyInstance<'sql'> {}
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Creates a SQL execution-plane family instance.
|
|
15
|
+
*
|
|
16
|
+
* This will be renamed to `createSqlExecutionFamilyInstance()` as part of `TML-1842`.
|
|
17
|
+
*/
|
|
18
|
+
export function createSqlRuntimeFamilyInstance(): SqlRuntimeFamilyInstance {
|
|
19
|
+
return {
|
|
20
|
+
familyId: 'sql' as const,
|
|
21
|
+
};
|
|
22
|
+
}
|