@prisma-next/family-sql 0.3.0-dev.6 → 0.3.0-dev.64

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.
Files changed (102) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +15 -6
  3. package/dist/assembly-BVS641kd.mjs +106 -0
  4. package/dist/assembly-BVS641kd.mjs.map +1 -0
  5. package/dist/control-adapter.d.mts +60 -0
  6. package/dist/control-adapter.d.mts.map +1 -0
  7. package/dist/control-adapter.mjs +1 -0
  8. package/dist/control-instance-62RsSxEp.d.mts +291 -0
  9. package/dist/control-instance-62RsSxEp.d.mts.map +1 -0
  10. package/dist/control.d.mts +106 -0
  11. package/dist/control.d.mts.map +1 -0
  12. package/dist/control.mjs +640 -0
  13. package/dist/control.mjs.map +1 -0
  14. package/dist/runtime.d.mts +27 -0
  15. package/dist/runtime.d.mts.map +1 -0
  16. package/dist/runtime.mjs +38 -0
  17. package/dist/runtime.mjs.map +1 -0
  18. package/dist/schema-verify.d.mts +48 -0
  19. package/dist/schema-verify.d.mts.map +1 -0
  20. package/dist/schema-verify.mjs +4 -0
  21. package/dist/test-utils.d.mts +2 -0
  22. package/dist/test-utils.mjs +3 -0
  23. package/dist/verify-BfMETJcM.mjs +108 -0
  24. package/dist/verify-BfMETJcM.mjs.map +1 -0
  25. package/dist/verify-sql-schema-CpAVEi8A.mjs +1058 -0
  26. package/dist/verify-sql-schema-CpAVEi8A.mjs.map +1 -0
  27. package/dist/verify-sql-schema-DhHnkpPa.d.mts +67 -0
  28. package/dist/verify-sql-schema-DhHnkpPa.d.mts.map +1 -0
  29. package/dist/verify.d.mts +31 -0
  30. package/dist/verify.d.mts.map +1 -0
  31. package/dist/verify.mjs +3 -0
  32. package/package.json +36 -47
  33. package/src/core/assembly.ts +158 -59
  34. package/src/core/control-adapter.ts +15 -0
  35. package/src/core/control-descriptor.ts +37 -0
  36. package/src/core/{instance.ts → control-instance.ts} +108 -241
  37. package/src/core/migrations/contract-to-schema-ir.ts +181 -0
  38. package/src/core/migrations/types.ts +63 -165
  39. package/src/core/runtime-descriptor.ts +19 -41
  40. package/src/core/runtime-instance.ts +11 -133
  41. package/src/core/schema-verify/verify-helpers.ts +187 -97
  42. package/src/core/schema-verify/verify-sql-schema.ts +910 -392
  43. package/src/core/verify.ts +4 -13
  44. package/src/exports/control.ts +15 -6
  45. package/src/exports/runtime.ts +2 -6
  46. package/src/exports/schema-verify.ts +10 -2
  47. package/src/exports/test-utils.ts +0 -1
  48. package/dist/chunk-6K3RPBDP.js +0 -580
  49. package/dist/chunk-6K3RPBDP.js.map +0 -1
  50. package/dist/chunk-BHEGVBY7.js +0 -772
  51. package/dist/chunk-BHEGVBY7.js.map +0 -1
  52. package/dist/chunk-SU7LN2UH.js +0 -96
  53. package/dist/chunk-SU7LN2UH.js.map +0 -1
  54. package/dist/core/assembly.d.ts +0 -25
  55. package/dist/core/assembly.d.ts.map +0 -1
  56. package/dist/core/control-adapter.d.ts +0 -42
  57. package/dist/core/control-adapter.d.ts.map +0 -1
  58. package/dist/core/descriptor.d.ts +0 -31
  59. package/dist/core/descriptor.d.ts.map +0 -1
  60. package/dist/core/instance.d.ts +0 -142
  61. package/dist/core/instance.d.ts.map +0 -1
  62. package/dist/core/migrations/plan-helpers.d.ts +0 -20
  63. package/dist/core/migrations/plan-helpers.d.ts.map +0 -1
  64. package/dist/core/migrations/policies.d.ts +0 -6
  65. package/dist/core/migrations/policies.d.ts.map +0 -1
  66. package/dist/core/migrations/types.d.ts +0 -280
  67. package/dist/core/migrations/types.d.ts.map +0 -1
  68. package/dist/core/runtime-descriptor.d.ts +0 -19
  69. package/dist/core/runtime-descriptor.d.ts.map +0 -1
  70. package/dist/core/runtime-instance.d.ts +0 -54
  71. package/dist/core/runtime-instance.d.ts.map +0 -1
  72. package/dist/core/schema-verify/verify-helpers.d.ts +0 -50
  73. package/dist/core/schema-verify/verify-helpers.d.ts.map +0 -1
  74. package/dist/core/schema-verify/verify-sql-schema.d.ts +0 -45
  75. package/dist/core/schema-verify/verify-sql-schema.d.ts.map +0 -1
  76. package/dist/core/verify.d.ts +0 -39
  77. package/dist/core/verify.d.ts.map +0 -1
  78. package/dist/exports/control-adapter.d.ts +0 -2
  79. package/dist/exports/control-adapter.d.ts.map +0 -1
  80. package/dist/exports/control-adapter.js +0 -1
  81. package/dist/exports/control-adapter.js.map +0 -1
  82. package/dist/exports/control.d.ts +0 -13
  83. package/dist/exports/control.d.ts.map +0 -1
  84. package/dist/exports/control.js +0 -149
  85. package/dist/exports/control.js.map +0 -1
  86. package/dist/exports/runtime.d.ts +0 -8
  87. package/dist/exports/runtime.d.ts.map +0 -1
  88. package/dist/exports/runtime.js +0 -64
  89. package/dist/exports/runtime.js.map +0 -1
  90. package/dist/exports/schema-verify.d.ts +0 -11
  91. package/dist/exports/schema-verify.d.ts.map +0 -1
  92. package/dist/exports/schema-verify.js +0 -11
  93. package/dist/exports/schema-verify.js.map +0 -1
  94. package/dist/exports/test-utils.d.ts +0 -7
  95. package/dist/exports/test-utils.d.ts.map +0 -1
  96. package/dist/exports/test-utils.js +0 -17
  97. package/dist/exports/test-utils.js.map +0 -1
  98. package/dist/exports/verify.d.ts +0 -2
  99. package/dist/exports/verify.d.ts.map +0 -1
  100. package/dist/exports/verify.js +0 -11
  101. package/dist/exports/verify.js.map +0 -1
  102. package/src/core/descriptor.ts +0 -37
@@ -0,0 +1,181 @@
1
+ import type { ColumnDefault } from '@prisma-next/contract/types';
2
+ import type { MigrationPlannerConflict } from '@prisma-next/core-control-plane/types';
3
+ import type {
4
+ ForeignKey,
5
+ Index,
6
+ SqlStorage,
7
+ StorageColumn,
8
+ StorageTable,
9
+ UniqueConstraint,
10
+ } from '@prisma-next/sql-contract/types';
11
+ import type {
12
+ SqlColumnIR,
13
+ SqlForeignKeyIR,
14
+ SqlIndexIR,
15
+ SqlSchemaIR,
16
+ SqlTableIR,
17
+ SqlUniqueIR,
18
+ } from '@prisma-next/sql-schema-ir/types';
19
+ import { ifDefined } from '@prisma-next/utils/defined';
20
+
21
+ function convertDefault(def: ColumnDefault): string {
22
+ if (def.kind === 'function') {
23
+ return def.expression;
24
+ }
25
+ if (typeof def.value === 'string') {
26
+ return `'${def.value.replaceAll("'", "''")}'`;
27
+ }
28
+ return String(def.value);
29
+ }
30
+
31
+ /**
32
+ * Target-specific callback that expands a column's base `nativeType` and optional
33
+ * `typeParams` into the fully-qualified type string used by the database
34
+ * (e.g. `character` + `{ length: 36 }` → `character(36)`).
35
+ *
36
+ * This lives in the family layer as a callback rather than importing a concrete
37
+ * implementation because each target (Postgres, MySQL, SQLite, …) has its own
38
+ * parameterization syntax. The target wires its expander when calling
39
+ * `contractToSchemaIR`, keeping the family layer target-agnostic.
40
+ */
41
+ export type NativeTypeExpander = (input: {
42
+ readonly nativeType: string;
43
+ readonly codecId?: string;
44
+ readonly typeParams?: Record<string, unknown>;
45
+ }) => string;
46
+
47
+ function convertColumn(
48
+ name: string,
49
+ column: StorageColumn,
50
+ expandNativeType?: NativeTypeExpander,
51
+ ): SqlColumnIR {
52
+ const nativeType = expandNativeType
53
+ ? expandNativeType({
54
+ nativeType: column.nativeType,
55
+ codecId: column.codecId,
56
+ ...ifDefined('typeParams', column.typeParams),
57
+ })
58
+ : column.nativeType;
59
+ return {
60
+ name,
61
+ nativeType,
62
+ nullable: column.nullable,
63
+ ...(column.default != null ? { default: convertDefault(column.default) } : {}),
64
+ };
65
+ }
66
+
67
+ function convertUnique(unique: UniqueConstraint): SqlUniqueIR {
68
+ return {
69
+ columns: unique.columns,
70
+ ...(unique.name != null ? { name: unique.name } : {}),
71
+ };
72
+ }
73
+
74
+ function convertIndex(index: Index): SqlIndexIR {
75
+ return {
76
+ columns: index.columns,
77
+ unique: false,
78
+ ...(index.name != null ? { name: index.name } : {}),
79
+ };
80
+ }
81
+
82
+ function convertForeignKey(fk: ForeignKey): SqlForeignKeyIR {
83
+ return {
84
+ columns: fk.columns,
85
+ referencedTable: fk.references.table,
86
+ referencedColumns: fk.references.columns,
87
+ ...(fk.name != null ? { name: fk.name } : {}),
88
+ };
89
+ }
90
+
91
+ function convertTable(
92
+ name: string,
93
+ table: StorageTable,
94
+ expandNativeType?: NativeTypeExpander,
95
+ ): SqlTableIR {
96
+ const columns: Record<string, SqlColumnIR> = {};
97
+ for (const [colName, colDef] of Object.entries(table.columns)) {
98
+ columns[colName] = convertColumn(colName, colDef, expandNativeType);
99
+ }
100
+
101
+ return {
102
+ name,
103
+ columns,
104
+ ...(table.primaryKey != null ? { primaryKey: table.primaryKey } : {}),
105
+ foreignKeys: table.foreignKeys.map(convertForeignKey),
106
+ uniques: table.uniques.map(convertUnique),
107
+ indexes: table.indexes.map(convertIndex),
108
+ };
109
+ }
110
+
111
+ /**
112
+ * Detects destructive changes between two contract storages.
113
+ *
114
+ * The additive-only planner silently ignores removals (tables, columns).
115
+ * This function detects those removals so callers can report them as conflicts
116
+ * rather than silently producing an empty plan.
117
+ *
118
+ * Returns an empty array if no destructive changes are found.
119
+ */
120
+ export function detectDestructiveChanges(
121
+ from: SqlStorage | null,
122
+ to: SqlStorage,
123
+ ): readonly MigrationPlannerConflict[] {
124
+ if (!from) return [];
125
+
126
+ const hasOwn = (value: object, key: string): boolean => Object.hasOwn(value, key);
127
+
128
+ const conflicts: MigrationPlannerConflict[] = [];
129
+
130
+ for (const tableName of Object.keys(from.tables)) {
131
+ if (!hasOwn(to.tables, tableName)) {
132
+ conflicts.push({
133
+ kind: 'tableRemoved',
134
+ summary: `Table "${tableName}" was removed`,
135
+ });
136
+ continue;
137
+ }
138
+
139
+ const toTable = to.tables[tableName] as StorageTable;
140
+ const fromTable = from.tables[tableName];
141
+ if (!fromTable) continue;
142
+
143
+ for (const columnName of Object.keys(fromTable.columns)) {
144
+ if (!hasOwn(toTable.columns, columnName)) {
145
+ conflicts.push({
146
+ kind: 'columnRemoved',
147
+ summary: `Column "${tableName}"."${columnName}" was removed`,
148
+ });
149
+ }
150
+ }
151
+ }
152
+
153
+ return conflicts;
154
+ }
155
+
156
+ /**
157
+ * Converts a contract's `SqlStorage` to `SqlSchemaIR`.
158
+ *
159
+ * Drops codec metadata (`codecId`, `typeRef`) since the schema IR only represents structural
160
+ * information. When `expandNativeType` is provided, parameterized types are expanded
161
+ * (e.g. `character` + `{ length: 36 }` → `character(36)`) so the resulting IR compares
162
+ * correctly against the "to" contract during planning.
163
+ *
164
+ * `extensions` is always `[]` — the planner resolves extension dependencies from framework
165
+ * components, and an empty array means "nothing installed yet" which is correct for the
166
+ * "from" side of a diff.
167
+ */
168
+ export function contractToSchemaIR(
169
+ storage: SqlStorage,
170
+ expandNativeType?: NativeTypeExpander,
171
+ ): SqlSchemaIR {
172
+ const tables: Record<string, SqlTableIR> = {};
173
+ for (const [tableName, tableDef] of Object.entries(storage.tables)) {
174
+ tables[tableName] = convertTable(tableName, tableDef, expandNativeType);
175
+ }
176
+
177
+ return {
178
+ tables,
179
+ extensions: [],
180
+ };
181
+ }
@@ -1,12 +1,6 @@
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
1
  import type { TargetBoundComponentDescriptor } from '@prisma-next/contract/framework-components';
9
2
  import type {
3
+ ControlAdapterDescriptor,
10
4
  ControlDriverInstance,
11
5
  ControlExtensionDescriptor,
12
6
  ControlTargetDescriptor,
@@ -23,109 +17,100 @@ import type {
23
17
  OperationContext,
24
18
  SchemaIssue,
25
19
  } from '@prisma-next/core-control-plane/types';
26
- import type { SqlContract, SqlStorage } from '@prisma-next/sql-contract/types';
20
+ import type { SqlContract, SqlStorage, StorageTypeInstance } from '@prisma-next/sql-contract/types';
21
+ import type { SqlOperationSignature } from '@prisma-next/sql-operations';
27
22
  import type { SqlSchemaIR } from '@prisma-next/sql-schema-ir/types';
28
23
  import type { Result } from '@prisma-next/utils/result';
29
- import type { SqlControlFamilyInstance } from '../instance';
24
+ import type { SqlControlFamilyInstance } from '../control-instance';
30
25
 
31
26
  export type AnyRecord = Readonly<Record<string, unknown>>;
32
27
 
33
- // ============================================================================
34
- // Component Database Dependencies
35
- // ============================================================================
28
+ export interface SqlControlStaticContributions {
29
+ readonly operationSignatures: () => ReadonlyArray<SqlOperationSignature>;
30
+ }
36
31
 
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
32
  export interface ComponentDatabaseDependency<TTargetDetails> {
47
- /** Stable identifier for the dependency (e.g. 'postgres.extension.vector') */
48
33
  readonly id: string;
49
- /** Human label for output (e.g. 'Enable vector extension') */
50
34
  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
35
  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
36
  readonly verifyDatabaseDependencyInstalled: (schema: SqlSchemaIR) => readonly SchemaIssue[];
63
37
  }
64
38
 
65
- /**
66
- * Database dependencies declared by a framework component.
67
- */
68
39
  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
40
  readonly init?: readonly ComponentDatabaseDependency<TTargetDetails>[];
74
41
  }
75
42
 
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
43
  export interface DatabaseDependencyProvider {
82
44
  readonly databaseDependencies?: ComponentDatabaseDependencies<unknown>;
83
45
  }
84
46
 
85
- // ============================================================================
86
- // SQL Control Extension Descriptor
87
- // ============================================================================
47
+ export interface StorageTypePlanResult<TTargetDetails> {
48
+ readonly operations: readonly SqlMigrationPlanOperation<TTargetDetails>[];
49
+ }
88
50
 
89
51
  /**
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.
52
+ * Input for expanding parameterized native types.
95
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
+
96
92
  export interface SqlControlExtensionDescriptor<TTargetId extends string>
97
- extends ControlExtensionDescriptor<'sql', TTargetId> {
98
- /** Optional database dependencies this extension requires. */
93
+ extends ControlExtensionDescriptor<'sql', TTargetId>,
94
+ SqlControlStaticContributions {
99
95
  readonly databaseDependencies?: ComponentDatabaseDependencies<unknown>;
100
96
  }
101
97
 
102
- // ============================================================================
103
- // SQL-Specific Plan Types
104
- // ============================================================================
98
+ export interface SqlControlAdapterDescriptor<TTargetId extends string>
99
+ extends ControlAdapterDescriptor<'sql', TTargetId>,
100
+ SqlControlStaticContributions {}
105
101
 
106
- /**
107
- * A single step in a SQL migration operation (precheck, execute, or postcheck).
108
- */
109
102
  export interface SqlMigrationPlanOperationStep {
110
103
  readonly description: string;
111
104
  readonly sql: string;
112
105
  readonly meta?: AnyRecord;
113
106
  }
114
107
 
115
- /**
116
- * Target details for a SQL migration operation (table, column, index, etc.).
117
- */
118
108
  export interface SqlMigrationPlanOperationTarget<TTargetDetails> {
119
109
  readonly id: string;
120
110
  readonly details?: TTargetDetails;
121
111
  }
122
112
 
123
- /**
124
- * A single SQL migration operation with SQL-specific fields.
125
- * Extends the core MigrationPlanOperation with SQL execution details.
126
- */
127
113
  export interface SqlMigrationPlanOperation<TTargetDetails> extends MigrationPlanOperation {
128
- /** Optional detailed explanation of what this operation does and why. */
129
114
  readonly summary?: string;
130
115
  readonly target: SqlMigrationPlanOperationTarget<TTargetDetails>;
131
116
  readonly precheck: readonly SqlMigrationPlanOperationStep[];
@@ -134,23 +119,15 @@ export interface SqlMigrationPlanOperation<TTargetDetails> extends MigrationPlan
134
119
  readonly meta?: AnyRecord;
135
120
  }
136
121
 
137
- /**
138
- * Contract identity information for SQL migrations.
139
- */
140
122
  export interface SqlMigrationPlanContractInfo {
141
- readonly coreHash: string;
123
+ readonly storageHash: string;
142
124
  readonly profileHash?: string;
143
125
  }
144
126
 
145
- /**
146
- * A SQL migration plan with SQL-specific fields.
147
- * Extends the core MigrationPlan with origin tracking and metadata.
148
- */
149
127
  export interface SqlMigrationPlan<TTargetDetails> extends MigrationPlan {
150
128
  /**
151
129
  * 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).
130
+ * If omitted or null, the runner skips origin validation entirely.
154
131
  */
155
132
  readonly origin?: SqlMigrationPlanContractInfo | null;
156
133
  /**
@@ -161,13 +138,6 @@ export interface SqlMigrationPlan<TTargetDetails> extends MigrationPlan {
161
138
  readonly meta?: AnyRecord;
162
139
  }
163
140
 
164
- // ============================================================================
165
- // SQL-Specific Planner Types
166
- // ============================================================================
167
-
168
- /**
169
- * Specific conflict kinds for SQL migrations.
170
- */
171
141
  export type SqlPlannerConflictKind =
172
142
  | 'typeMismatch'
173
143
  | 'nullabilityConflict'
@@ -178,54 +148,36 @@ export type SqlPlannerConflictKind =
178
148
  | 'extensionMissing'
179
149
  | 'unsupportedOperation';
180
150
 
181
- /**
182
- * Location information for SQL planner conflicts.
183
- */
184
151
  export interface SqlPlannerConflictLocation {
185
152
  readonly table?: string;
186
153
  readonly column?: string;
187
154
  readonly index?: string;
188
155
  readonly constraint?: string;
189
156
  readonly extension?: string;
157
+ readonly type?: string;
190
158
  }
191
159
 
192
- /**
193
- * A SQL-specific planner conflict with additional location information.
194
- * Extends the core MigrationPlannerConflict.
195
- */
196
160
  export interface SqlPlannerConflict extends MigrationPlannerConflict {
197
161
  readonly kind: SqlPlannerConflictKind;
198
162
  readonly location?: SqlPlannerConflictLocation;
199
163
  readonly meta?: AnyRecord;
200
164
  }
201
165
 
202
- /**
203
- * Successful SQL planner result with the migration plan.
204
- */
205
166
  export interface SqlPlannerSuccessResult<TTargetDetails>
206
167
  extends Omit<MigrationPlannerSuccessResult, 'plan'> {
207
168
  readonly kind: 'success';
208
169
  readonly plan: SqlMigrationPlan<TTargetDetails>;
209
170
  }
210
171
 
211
- /**
212
- * Failed SQL planner result with the list of conflicts.
213
- */
214
172
  export interface SqlPlannerFailureResult extends Omit<MigrationPlannerFailureResult, 'conflicts'> {
215
173
  readonly kind: 'failure';
216
174
  readonly conflicts: readonly SqlPlannerConflict[];
217
175
  }
218
176
 
219
- /**
220
- * Union type for SQL planner results.
221
- */
222
177
  export type SqlPlannerResult<TTargetDetails> =
223
178
  | SqlPlannerSuccessResult<TTargetDetails>
224
179
  | SqlPlannerFailureResult;
225
180
 
226
- /**
227
- * Options for SQL migration planner.
228
- */
229
181
  export interface SqlMigrationPlannerPlanOptions {
230
182
  readonly contract: SqlContract<SqlStorage>;
231
183
  readonly schema: SqlSchemaIR;
@@ -239,29 +191,15 @@ export interface SqlMigrationPlannerPlanOptions {
239
191
  readonly frameworkComponents: ReadonlyArray<TargetBoundComponentDescriptor<'sql', string>>;
240
192
  }
241
193
 
242
- /**
243
- * SQL migration planner interface.
244
- * Extends the core MigrationPlanner with SQL-specific types.
245
- */
246
194
  export interface SqlMigrationPlanner<TTargetDetails> {
247
195
  plan(options: SqlMigrationPlannerPlanOptions): SqlPlannerResult<TTargetDetails>;
248
196
  }
249
197
 
250
- // ============================================================================
251
- // SQL-Specific Runner Types
252
- // ============================================================================
253
-
254
- /**
255
- * Callbacks for SQL migration runner execution.
256
- */
257
198
  export interface SqlMigrationRunnerExecuteCallbacks<TTargetDetails> {
258
199
  onOperationStart?(operation: SqlMigrationPlanOperation<TTargetDetails>): void;
259
200
  onOperationComplete?(operation: SqlMigrationPlanOperation<TTargetDetails>): void;
260
201
  }
261
202
 
262
- /**
263
- * Options for SQL migration runner execution.
264
- */
265
203
  export interface SqlMigrationRunnerExecuteOptions<TTargetDetails> {
266
204
  readonly plan: SqlMigrationPlan<TTargetDetails>;
267
205
  readonly driver: ControlDriverInstance<'sql', string>;
@@ -292,9 +230,6 @@ export interface SqlMigrationRunnerExecuteOptions<TTargetDetails> {
292
230
  readonly frameworkComponents: ReadonlyArray<TargetBoundComponentDescriptor<'sql', string>>;
293
231
  }
294
232
 
295
- /**
296
- * Error codes for SQL migration runner failures.
297
- */
298
233
  export type SqlMigrationRunnerErrorCode =
299
234
  | 'DESTINATION_CONTRACT_MISMATCH'
300
235
  | 'MARKER_ORIGIN_MISMATCH'
@@ -304,73 +239,36 @@ export type SqlMigrationRunnerErrorCode =
304
239
  | 'SCHEMA_VERIFY_FAILED'
305
240
  | 'EXECUTION_FAILED';
306
241
 
307
- /**
308
- * Detailed information about a SQL migration runner failure.
309
- * Extends the core MigrationRunnerFailure with SQL-specific error codes.
310
- */
311
242
  export interface SqlMigrationRunnerFailure extends MigrationRunnerFailure {
312
243
  readonly code: SqlMigrationRunnerErrorCode;
313
244
  readonly meta?: AnyRecord;
314
245
  }
315
246
 
316
- /**
317
- * Success value for SQL migration runner execution.
318
- * Extends core type for type branding and potential SQL-specific extensions.
319
- */
320
247
  export interface SqlMigrationRunnerSuccessValue extends MigrationRunnerSuccessValue {}
321
248
 
322
- /**
323
- * Result type for SQL migration runner execution.
324
- */
325
249
  export type SqlMigrationRunnerResult = Result<
326
250
  SqlMigrationRunnerSuccessValue,
327
251
  SqlMigrationRunnerFailure
328
252
  >;
329
253
 
330
- /**
331
- * SQL migration runner interface.
332
- * Extends the core MigrationRunner with SQL-specific types.
333
- */
334
254
  export interface SqlMigrationRunner<TTargetDetails> {
335
255
  execute(
336
256
  options: SqlMigrationRunnerExecuteOptions<TTargetDetails>,
337
257
  ): Promise<SqlMigrationRunnerResult>;
338
258
  }
339
259
 
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
260
  export interface SqlControlTargetDescriptor<TTargetId extends string, TTargetDetails>
349
261
  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
- */
262
+ 'sql',
263
+ TTargetId,
264
+ ControlTargetInstance<'sql', TTargetId>,
265
+ SqlControlFamilyInstance
266
+ >,
267
+ SqlControlStaticContributions {
359
268
  createPlanner(family: SqlControlFamilyInstance): SqlMigrationPlanner<TTargetDetails>;
360
- /**
361
- * Creates a SQL migration runner for this target.
362
- * Direct method for SQL-specific usage.
363
- */
364
269
  createRunner(family: SqlControlFamilyInstance): SqlMigrationRunner<TTargetDetails>;
365
270
  }
366
271
 
367
- // ============================================================================
368
- // Helper Types
369
- // ============================================================================
370
-
371
- /**
372
- * Options for creating a SQL migration plan.
373
- */
374
272
  export interface CreateSqlMigrationPlanOptions<TTargetDetails> {
375
273
  readonly targetId: string;
376
274
  readonly origin?: SqlMigrationPlanContractInfo | null;
@@ -1,45 +1,23 @@
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';
1
+ import type { RuntimeFamilyDescriptor } from '@prisma-next/core-execution-plane/types';
2
+ import { createSqlRuntimeFamilyInstance, type SqlRuntimeFamilyInstance } from './runtime-instance';
14
3
 
15
4
  /**
16
- * SQL runtime family descriptor implementation.
17
- * Provides factory method to create SQL runtime family instance.
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`.
18
11
  */
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';
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
+ };
26
22
 
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
- }
23
+ Object.freeze(sqlRuntimeFamilyDescriptor);