qubu 0.4.2 → 0.5.0

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 (61) hide show
  1. package/dist/{canonical-BXUguqfo.mjs → canonical-DMvR9yBe.mjs} +4 -4
  2. package/dist/codegen.d.mts +1 -1
  3. package/dist/codegen.mjs +7 -4
  4. package/dist/{column-hqKr7-1I.mjs → column-DmazTL67.mjs} +15 -2
  5. package/dist/{complete-WYyVozgK.mjs → complete-DP7pliuY.mjs} +6 -6
  6. package/dist/{complete-types-IjEn5VPN.d.mts → complete-types-CY0KbzNw.d.mts} +1 -1
  7. package/dist/core.d.mts +1 -1
  8. package/dist/core.mjs +3 -3
  9. package/dist/diff.d.mts +201 -1
  10. package/dist/diff.mjs +8 -8
  11. package/dist/{index-1DpA3mUh.d.mts → index-C-480HmV.d.mts} +12 -12
  12. package/dist/index.d.mts +2 -2
  13. package/dist/index.mjs +226 -44
  14. package/dist/introspection.d.mts +2 -2
  15. package/dist/introspection.mjs +24 -13
  16. package/dist/mysql.d.mts +2 -2
  17. package/dist/{on-conflict-hfPW0KmQ.mjs → on-conflict-jPsl9l0K.mjs} +6 -3
  18. package/dist/postgres.d.mts +2 -2
  19. package/dist/postgres.mjs +3 -3
  20. package/dist/{registry-BRMLYwDp.mjs → registry-BGqa05et.mjs} +2 -2
  21. package/dist/{relational-BZ3WDPzC.mjs → relational-x3BDVX9e.mjs} +2 -2
  22. package/dist/schema.d.mts +2 -2
  23. package/dist/schema.mjs +5 -5
  24. package/dist/{snapshot-C-W65HEd.mjs → snapshot-BSraiLtH.mjs} +2 -2
  25. package/dist/snapshot.d.mts +4 -4
  26. package/dist/snapshot.mjs +585 -5
  27. package/dist/{source-BcS2AsIg.mjs → source-C4Vmu5bb.mjs} +1 -1
  28. package/dist/{sqlite-Cg0nwYEH.mjs → sqlite-CsIUtZ2Q.mjs} +6 -6
  29. package/dist/sqlite.d.mts +30 -3
  30. package/dist/sqlite.mjs +28 -2
  31. package/dist/{table-Bp5irMSj.mjs → table-DLQ7YWth.mjs} +2 -2
  32. package/dist/{types-BK1COGZe.d.mts → types-C0VkiwpR.d.mts} +146 -41
  33. package/dist/{types-JSZHpUEj.d.mts → types-CTCqtFlS.d.mts} +1 -1
  34. package/dist/{types-JM3FcAnX.mjs → types-CTENnDh9.mjs} +2 -2
  35. package/dist/{value-Bi71Agyf.mjs → value-BEEj_Ayd.mjs} +1 -1
  36. package/dist/vite/ambient.d.ts +6 -0
  37. package/docs/config.json +1 -0
  38. package/docs/dialects-and-execution.md +47 -0
  39. package/docs/guides/drizzle.md +2 -1
  40. package/docs/index.md +6 -2
  41. package/docs/migrations/adapters.md +70 -0
  42. package/docs/migrations/artifacts-and-policy.md +123 -0
  43. package/docs/migrations/index.md +46 -0
  44. package/docs/migrations/lotta-adoption.md +50 -0
  45. package/docs/migrations/operations.md +133 -0
  46. package/docs/migrations/recovery.md +121 -0
  47. package/docs/reference/introspection-support.md +1 -1
  48. package/docs/reference/supported-surface.md +59 -44
  49. package/docs/schema/catalog-model.md +1 -1
  50. package/docs/schema/columns-and-writes.md +14 -0
  51. package/docs/schema/ddl-emission.md +15 -10
  52. package/docs/schema/introspection.md +4 -3
  53. package/docs/schema/migration-plans.md +6 -6
  54. package/docs/schema/snapshots.md +2 -2
  55. package/package.json +5 -14
  56. package/dist/ddl.d.mts +0 -118
  57. package/dist/ddl.mjs +0 -1119
  58. package/dist/index-CPvfEheG.d.mts +0 -202
  59. package/dist/migration.d.mts +0 -214
  60. package/dist/migration.mjs +0 -1160
  61. package/dist/mysql-B_cYzzX2.mjs +0 -585
@@ -1,585 +0,0 @@
1
- import { P as isValidSchemaObjectName, r as isColumnReference } from "./column-hqKr7-1I.mjs";
2
- import { _ as isUnsafeSchemaSql, m as validateConstraintDialect, w as validateIndexDialect, y as renderSchemaExpression } from "./registry-BRMLYwDp.mjs";
3
- import { t as createSchemaDialect } from "./dialect-wUKrnPMB.mjs";
4
- import { a as toSnapshotJsonValue } from "./canonical-BXUguqfo.mjs";
5
- import { c as createSchemaSnapshot, p as tryCreateSchemaSnapshot } from "./sqlite-Cg0nwYEH.mjs";
6
- import { postgresDialect } from "./postgres.mjs";
7
- import { mysqlDialect } from "./mysql.mjs";
8
- //#region src/snapshot/postgres.ts
9
- /** PostgreSQL's v1 snapshot extension identity. */
10
- const postgresSnapshotDialect = Object.freeze({
11
- name: "postgresql",
12
- version: 1
13
- });
14
- var PostgresSnapshotDialectError = class extends TypeError {
15
- code = "dialect-mismatch";
16
- };
17
- const postgresStorageTypes = Object.freeze({
18
- integer: "INTEGER",
19
- numeric: "NUMERIC",
20
- text: "TEXT",
21
- boolean: "BOOLEAN",
22
- date: "DATE",
23
- timestamp: "TIMESTAMP",
24
- uuid: "UUID",
25
- json: "JSONB",
26
- bigint: "BIGINT",
27
- binary: "BYTEA"
28
- });
29
- /** PostgreSQL's query dialect plus its schema metadata behavior. */
30
- const postgresSchemaDialect = createSchemaDialect(postgresDialect(), {
31
- version: 1,
32
- validate: validatePostgresSchema,
33
- encodeStorage(storage, context) {
34
- return encodePostgresStorage(storage, context.dialect);
35
- },
36
- encodeExpression(expression, context) {
37
- return encodePostgresExpression(expression, context.mode, context.dialect);
38
- },
39
- encodeDialectExtension(extension, context) {
40
- return encodePostgresExtension(extension, context.dialect);
41
- }
42
- });
43
- /** Snapshot adapter retaining the historical adapter-shaped entry point. */
44
- const postgresSnapshotAdapter = Object.freeze({ dialect: postgresSchemaDialect });
45
- /** Create a canonical PostgreSQL schema snapshot. */
46
- function createPostgresSchemaSnapshot(schema, options = {}) {
47
- return createSchemaSnapshot(schema, {
48
- ...options,
49
- adapter: postgresSnapshotAdapter
50
- });
51
- }
52
- /** Return PostgreSQL capability diagnostics without throwing. */
53
- function tryCreatePostgresSchemaSnapshot(schema, options = {}) {
54
- return tryCreateSchemaSnapshot(schema, {
55
- ...options,
56
- adapter: postgresSnapshotAdapter
57
- });
58
- }
59
- function encodePostgresStorage(storage, dialect) {
60
- if (storage.kind === "native") {
61
- if (storage.dialect !== dialect.name) throw new TypeError(`PostgreSQL storage cannot encode a native declaration owned by "${storage.dialect}"`);
62
- if (storage.type.trim().length === 0) throw new TypeError("PostgreSQL native storage declarations cannot be empty");
63
- return {
64
- kind: "native",
65
- dialect: dialect.name,
66
- type: storage.type
67
- };
68
- }
69
- const type = postgresStorageTypes[storage.type];
70
- if (type === void 0) throw new TypeError(`Unsupported portable storage type for PostgreSQL: ${String(storage.type)}`);
71
- return {
72
- kind: "native",
73
- dialect: dialect.name,
74
- type
75
- };
76
- }
77
- function encodePostgresExpression(expression, mode, dialect) {
78
- if (isUnsafeSchemaSql(expression) && expression.schemaSqlDialect !== dialect.name) throw new PostgresSnapshotDialectError(`Schema SQL is tagged for "${expression.schemaSqlDialect}" but the PostgreSQL schema dialect is "${dialect.name}"`);
79
- const rendered = renderSchemaExpression(expression, {
80
- mode,
81
- dialect
82
- });
83
- if (rendered.parameters.length !== 0) throw new TypeError("PostgreSQL schema expressions must be parameter-free");
84
- return {
85
- kind: "expression",
86
- expressionKind: expression.expressionKind,
87
- sql: rendered.text,
88
- ...isUnsafeSchemaSql(expression) ? { dialect: dialect.name } : {}
89
- };
90
- }
91
- function encodePostgresExtension(extension, dialect) {
92
- if (extension.dialect !== dialect.name) throw new TypeError(`PostgreSQL schema extensions require dialect "${dialect.name}"`);
93
- const data = Object.fromEntries(Object.entries(extension).filter(([key]) => key !== "dialect").sort(([left], [right]) => left.localeCompare(right)));
94
- return {
95
- dialect: dialect.name,
96
- version: dialect.schema.version,
97
- data: sortSnapshotJson$1(toSnapshotJsonValue(data))
98
- };
99
- }
100
- function sortSnapshotJson$1(value) {
101
- if (Array.isArray(value)) return value.map(sortSnapshotJson$1);
102
- if (typeof value !== "object" || value === null) return value;
103
- return Object.fromEntries(Object.entries(value).sort(([left], [right]) => left.localeCompare(right)).map(([key, child]) => [key, sortSnapshotJson$1(child)]));
104
- }
105
- function validatePostgresSchema(schema, context) {
106
- const diagnostics = [];
107
- const tableEntries = Object.entries(schema.registry).sort(([left], [right]) => compareIds$1(left, right));
108
- const relationNames = /* @__PURE__ */ new Map();
109
- if (schema.namespace !== void 0) validatePostgresName(schema.namespace, ["namespace"], "PostgreSQL namespace", diagnostics);
110
- for (const [id, entry] of tableEntries) {
111
- const tablePath = ["tables", id];
112
- validatePostgresName(entry.physicalName, [...tablePath, "physicalName"], "PostgreSQL table", diagnostics);
113
- addRelationName(relationNames, entry.physicalName, [...tablePath, "physicalName"], "table", diagnostics);
114
- }
115
- for (const [id, entry] of tableEntries) validatePostgresTable(id, entry, context, relationNames, diagnostics);
116
- return Object.freeze(diagnostics);
117
- }
118
- function validatePostgresTable(tableId, entry, context, relationNames, diagnostics) {
119
- const table = entry.table;
120
- const tablePath = ["tables", tableId];
121
- const definitions = table.definitions;
122
- for (const [columnId, definition] of Object.entries(definitions).sort(([left], [right]) => compareIds$1(left, right))) {
123
- validatePostgresName(table.sqlNames[columnId] ?? columnId, [
124
- ...tablePath,
125
- "columns",
126
- columnId,
127
- "physicalName"
128
- ], "PostgreSQL column", diagnostics);
129
- if (definition.onUpdate !== void 0) diagnostics.push({
130
- code: "unsupported-dialect-option",
131
- message: "MySQL ON UPDATE expressions are not supported by PostgreSQL",
132
- path: [
133
- ...tablePath,
134
- "columns",
135
- columnId,
136
- "onUpdate"
137
- ]
138
- });
139
- const generated = definition.generatedColumn;
140
- if (generated !== void 0 && generated.kind === "expression" && generated.mode === "virtual") diagnostics.push({
141
- code: "unsupported-dialect-option",
142
- message: "PostgreSQL v1 snapshots support stored generated columns only; virtual generated columns are not supported",
143
- path: [
144
- ...tablePath,
145
- "columns",
146
- columnId,
147
- "generatedColumn",
148
- "mode"
149
- ]
150
- });
151
- }
152
- const metadata = table;
153
- const constraintNames = /* @__PURE__ */ new Map();
154
- const constraints = Object.entries(metadata.constraints);
155
- for (const [constraintId, constraint] of constraints.sort(([left], [right]) => compareIds$1(left, right))) {
156
- const constraintPath = [
157
- ...tablePath,
158
- "constraints",
159
- constraintId
160
- ];
161
- const physicalName = constraint.physicalName ?? constraintId;
162
- validatePostgresName(physicalName, [...constraintPath, "physicalName"], "PostgreSQL constraint", diagnostics);
163
- addScopedName$1(constraintNames, physicalName, [...constraintPath, "physicalName"], "constraint", diagnostics);
164
- appendMetadataDiagnostics$1(diagnostics, validateConstraintDialect(constraint, context.dialect.name, constraintPath));
165
- if (constraint.kind === "check" && constraint.deferrable === true) diagnostics.push({
166
- code: "unsupported-dialect-option",
167
- message: "PostgreSQL CHECK constraints cannot be DEFERRABLE",
168
- path: [...constraintPath, "deferrable"]
169
- });
170
- if (constraint.kind === "foreign-key" && constraint.match === "partial") diagnostics.push({
171
- code: "unsupported-dialect-option",
172
- message: "PostgreSQL does not implement MATCH PARTIAL foreign keys",
173
- path: [...constraintPath, "match"]
174
- });
175
- if (constraint.kind === "unique-constraint" && constraint.nulls === "not-distinct") diagnostics.push({
176
- code: "unsupported-dialect-option",
177
- message: "PostgreSQL NULLS NOT DISTINCT requires a server-version policy; the v1 adapter does not assume PostgreSQL 15 or newer",
178
- path: [...constraintPath, "nulls"]
179
- });
180
- }
181
- const indexes = Object.entries(metadata.indexes);
182
- for (const [indexId, index] of indexes.sort(([left], [right]) => compareIds$1(left, right))) {
183
- const indexPath = [
184
- ...tablePath,
185
- "indexes",
186
- indexId
187
- ];
188
- const physicalName = index.physicalName ?? indexId;
189
- validatePostgresName(physicalName, [...indexPath, "physicalName"], "PostgreSQL index", diagnostics);
190
- addRelationName(relationNames, physicalName, [...indexPath, "physicalName"], "index", diagnostics);
191
- appendMetadataDiagnostics$1(diagnostics, validateIndexDialect(index, context.dialect.name, indexPath));
192
- }
193
- }
194
- function validatePostgresName(name, path, kind, diagnostics) {
195
- if (!isValidSchemaObjectName(name) || name.length === 0) diagnostics.push({
196
- code: "invalid-schema",
197
- message: `${kind} name "${name}" is not a valid unqualified identifier`,
198
- path
199
- });
200
- if (new TextEncoder().encode(name).length > 63) diagnostics.push({
201
- code: "unsupported-dialect-option",
202
- message: `${kind} name exceeds PostgreSQL's 63-byte identifier limit`,
203
- path
204
- });
205
- }
206
- function addRelationName(names, name, path, kind, diagnostics) {
207
- addScopedName$1(names, name, path, kind, diagnostics);
208
- }
209
- function addScopedName$1(names, name, path, kind, diagnostics) {
210
- const previousPath = names.get(name);
211
- if (previousPath !== void 0) {
212
- diagnostics.push({
213
- code: "invalid-schema",
214
- message: `PostgreSQL ${kind} name "${name}" collides with another relation or metadata object`,
215
- path,
216
- relatedPaths: [previousPath]
217
- });
218
- return;
219
- }
220
- names.set(name, path);
221
- }
222
- function appendMetadataDiagnostics$1(diagnostics, issues) {
223
- for (const issue of issues) {
224
- if (issue.code === "dialect-mismatch") continue;
225
- diagnostics.push({
226
- code: issue.code === "unsupported-dialect-option" ? "unsupported-dialect-option" : "invalid-schema",
227
- message: issue.message,
228
- path: issue.path,
229
- ...issue.relatedPaths === void 0 ? {} : { relatedPaths: issue.relatedPaths }
230
- });
231
- }
232
- }
233
- function compareIds$1(left, right) {
234
- return left < right ? -1 : left > right ? 1 : 0;
235
- }
236
- //#endregion
237
- //#region src/snapshot/mysql.ts
238
- /** MySQL's v1 snapshot extension identity. */
239
- const mysqlSnapshotDialect = Object.freeze({
240
- name: "mysql",
241
- version: 1
242
- });
243
- var MysqlSnapshotDialectError = class extends TypeError {
244
- code = "dialect-mismatch";
245
- };
246
- const mysqlStorageTypes = Object.freeze({
247
- integer: "INT",
248
- numeric: "DECIMAL",
249
- text: "TEXT",
250
- boolean: "BOOLEAN",
251
- date: "DATE",
252
- timestamp: "DATETIME",
253
- uuid: "CHAR(36)",
254
- json: "JSON",
255
- bigint: "BIGINT",
256
- binary: "VARBINARY"
257
- });
258
- /** MySQL's query dialect plus its schema metadata behavior. */
259
- const mysqlSchemaDialect = createSchemaDialect(mysqlDialect(), {
260
- version: 1,
261
- validate: validateMysqlSchema,
262
- encodeStorage(storage, context) {
263
- return encodeMysqlStorage(storage, context.dialect);
264
- },
265
- encodeExpression(expression, context) {
266
- return encodeMysqlExpression(expression, context.mode, context.dialect);
267
- },
268
- encodeDialectExtension(extension, context) {
269
- return encodeMysqlExtension(extension, context.dialect);
270
- }
271
- });
272
- /** Snapshot adapter retaining the historical adapter-shaped entry point. */
273
- const mysqlSnapshotAdapter = Object.freeze({ dialect: mysqlSchemaDialect });
274
- /** Create a canonical MySQL schema snapshot. */
275
- function createMysqlSchemaSnapshot(schema, options = {}) {
276
- return createSchemaSnapshot(schema, {
277
- ...options,
278
- adapter: mysqlSnapshotAdapter
279
- });
280
- }
281
- /** Return MySQL capability diagnostics without throwing. */
282
- function tryCreateMysqlSchemaSnapshot(schema, options = {}) {
283
- return tryCreateSchemaSnapshot(schema, {
284
- ...options,
285
- adapter: mysqlSnapshotAdapter
286
- });
287
- }
288
- function encodeMysqlStorage(storage, dialect) {
289
- if (storage.kind === "native") {
290
- if (storage.dialect !== dialect.name) throw new MysqlSnapshotDialectError(`MySQL storage cannot encode a native declaration owned by "${storage.dialect}"`);
291
- if (storage.type.trim().length === 0) throw new TypeError("MySQL native storage declarations cannot be empty");
292
- return {
293
- kind: "native",
294
- dialect: dialect.name,
295
- type: storage.type
296
- };
297
- }
298
- const type = mysqlStorageTypes[storage.type];
299
- if (type === void 0) throw new TypeError(`Unsupported portable storage type for MySQL: ${String(storage.type)}`);
300
- return {
301
- kind: "native",
302
- dialect: dialect.name,
303
- type
304
- };
305
- }
306
- function encodeMysqlExpression(expression, mode, dialect) {
307
- if (isUnsafeSchemaSql(expression) && expression.schemaSqlDialect !== dialect.name) throw new MysqlSnapshotDialectError(`Schema SQL is tagged for "${expression.schemaSqlDialect}" but the MySQL schema dialect is "${dialect.name}"`);
308
- const rendered = renderSchemaExpression(expression, {
309
- mode,
310
- dialect
311
- });
312
- if (rendered.parameters.length !== 0) throw new TypeError("MySQL schema expressions must be parameter-free");
313
- return {
314
- kind: "expression",
315
- expressionKind: expression.expressionKind,
316
- sql: rendered.text,
317
- ...isUnsafeSchemaSql(expression) ? { dialect: dialect.name } : {}
318
- };
319
- }
320
- function encodeMysqlExtension(extension, dialect) {
321
- if (extension.dialect !== dialect.name) throw new MysqlSnapshotDialectError(`MySQL schema extensions require dialect "${dialect.name}"`);
322
- const data = Object.fromEntries(Object.entries(extension).filter(([key]) => key !== "dialect").sort(([left], [right]) => left.localeCompare(right)));
323
- return {
324
- dialect: dialect.name,
325
- version: dialect.schema.version,
326
- data: sortSnapshotJson(toSnapshotJsonValue(data))
327
- };
328
- }
329
- function sortSnapshotJson(value) {
330
- if (Array.isArray(value)) return value.map(sortSnapshotJson);
331
- if (typeof value !== "object" || value === null) return value;
332
- return Object.fromEntries(Object.entries(value).sort(([left], [right]) => left.localeCompare(right)).map(([key, child]) => [key, sortSnapshotJson(child)]));
333
- }
334
- function validateMysqlSchema(schema, context) {
335
- const diagnostics = [];
336
- const tableEntries = Object.entries(schema.registry).sort(([left], [right]) => compareIds(left, right));
337
- const relationNames = /* @__PURE__ */ new Map();
338
- if (schema.namespace !== void 0) validateMysqlName(schema.namespace, ["namespace"], "MySQL database/schema", diagnostics);
339
- for (const [id, entry] of tableEntries) {
340
- const tablePath = ["tables", id];
341
- validateMysqlName(entry.physicalName, [...tablePath, "physicalName"], "MySQL table", diagnostics);
342
- addScopedName(relationNames, entry.physicalName, [...tablePath, "physicalName"], "table", diagnostics);
343
- }
344
- for (const [id, entry] of tableEntries) validateMysqlTable(id, entry, context, diagnostics);
345
- return Object.freeze(diagnostics);
346
- }
347
- function validateMysqlTable(tableId, entry, context, diagnostics) {
348
- const table = entry.table;
349
- const tablePath = ["tables", tableId];
350
- const definitions = table.definitions;
351
- const metadata = table;
352
- for (const [columnId, definition] of Object.entries(definitions).sort(([left], [right]) => compareIds(left, right))) {
353
- const columnPath = [
354
- ...tablePath,
355
- "columns",
356
- columnId
357
- ];
358
- validateMysqlName(table.sqlNames[columnId] ?? columnId, [...columnPath, "physicalName"], "MySQL column", diagnostics);
359
- if (definition.onUpdate !== void 0 && definition.generatedColumn) diagnostics.push({
360
- code: "unsupported-dialect-option",
361
- message: "MySQL generated columns cannot also declare ON UPDATE",
362
- path: [...columnPath, "onUpdate"]
363
- });
364
- const extension = definition.identity?.dialect;
365
- const autoIncrement = extension?.dialect === mysqlSnapshotDialect.name ? extension.autoIncrement : void 0;
366
- if (extension?.dialect === mysqlSnapshotDialect.name && autoIncrement !== void 0 && typeof autoIncrement !== "boolean") diagnostics.push({
367
- code: "unsupported-dialect-option",
368
- message: "MySQL identity autoIncrement must be boolean",
369
- path: [
370
- ...columnPath,
371
- "identity",
372
- "dialect",
373
- "autoIncrement"
374
- ]
375
- });
376
- if (autoIncrement === true) validateMysqlAutoIncrement(columnId, definition, metadata, columnPath, diagnostics);
377
- }
378
- const constraintNames = /* @__PURE__ */ new Map();
379
- const constraints = Object.entries(metadata.constraints);
380
- for (const [constraintId, constraint] of constraints.sort(([left], [right]) => compareIds(left, right))) {
381
- const constraintPath = [
382
- ...tablePath,
383
- "constraints",
384
- constraintId
385
- ];
386
- const physicalName = constraint.physicalName ?? constraintId;
387
- validateMysqlName(physicalName, [...constraintPath, "physicalName"], "MySQL constraint", diagnostics);
388
- addScopedName(constraintNames, physicalName, [...constraintPath, "physicalName"], "constraint", diagnostics);
389
- appendMetadataDiagnostics(diagnostics, validateConstraintDialect(constraint, context.dialect.name, constraintPath));
390
- if (constraint.kind === "foreign-key" && (constraint.match === "full" || constraint.match === "partial")) diagnostics.push({
391
- code: "unsupported-dialect-option",
392
- message: "MySQL v1 snapshots support MATCH SIMPLE foreign keys only",
393
- path: [...constraintPath, "match"]
394
- });
395
- if (constraint.kind === "foreign-key" && (constraint.onUpdate === "set-default" || constraint.onDelete === "set-default")) diagnostics.push({
396
- code: "unsupported-dialect-option",
397
- message: "MySQL does not support SET DEFAULT foreign-key actions",
398
- path: [...constraintPath, constraint.onUpdate === "set-default" ? "onUpdate" : "onDelete"]
399
- });
400
- if (constraint.kind === "unique-constraint" && constraint.nulls === "not-distinct") diagnostics.push({
401
- code: "unsupported-dialect-option",
402
- message: "MySQL ordinary UNIQUE constraints use distinct NULL semantics in v1",
403
- path: [...constraintPath, "nulls"]
404
- });
405
- if (constraint.dialect?.dialect === mysqlSnapshotDialect.name && "enforced" in constraint.dialect && constraint.dialect.enforced !== void 0 && typeof constraint.dialect.enforced !== "boolean") diagnostics.push({
406
- code: "unsupported-dialect-option",
407
- message: "MySQL constraint enforced must be boolean",
408
- path: [
409
- ...constraintPath,
410
- "dialect",
411
- "enforced"
412
- ]
413
- });
414
- }
415
- const indexes = Object.entries(metadata.indexes);
416
- const tableIndexNames = /* @__PURE__ */ new Map();
417
- for (const [indexId, index] of indexes.sort(([left], [right]) => compareIds(left, right))) {
418
- const indexPath = [
419
- ...tablePath,
420
- "indexes",
421
- indexId
422
- ];
423
- const physicalName = index.physicalName ?? indexId;
424
- validateMysqlName(physicalName, [...indexPath, "physicalName"], "MySQL index", diagnostics);
425
- addScopedName(tableIndexNames, physicalName, [...indexPath, "physicalName"], "index", diagnostics);
426
- appendMetadataDiagnostics(diagnostics, validateIndexDialect(index, context.dialect.name, indexPath));
427
- if (index.predicate !== void 0) diagnostics.push({
428
- code: "unsupported-dialect-option",
429
- message: "MySQL does not support partial-index predicates",
430
- path: [...indexPath, "predicate"]
431
- });
432
- for (const [termIndex, term] of index.terms.entries()) if (isOrderTerm(term) && term.nulls !== void 0) diagnostics.push({
433
- code: "unsupported-dialect-option",
434
- message: "MySQL index terms do not support NULLS FIRST/LAST syntax",
435
- path: [
436
- ...indexPath,
437
- "terms",
438
- termIndex,
439
- "nulls"
440
- ]
441
- });
442
- const extension = index.dialect;
443
- if (extension?.dialect === mysqlSnapshotDialect.name) {
444
- const mysqlExtension = extension;
445
- if (mysqlExtension.algorithm !== void 0 && ![
446
- "default",
447
- "inplace",
448
- "copy"
449
- ].includes(String(mysqlExtension.algorithm))) diagnostics.push({
450
- code: "unsupported-dialect-option",
451
- message: "MySQL index algorithm is invalid",
452
- path: [
453
- ...indexPath,
454
- "dialect",
455
- "algorithm"
456
- ]
457
- });
458
- if (mysqlExtension.lock !== void 0 && ![
459
- "default",
460
- "none",
461
- "shared",
462
- "exclusive"
463
- ].includes(String(mysqlExtension.lock))) diagnostics.push({
464
- code: "unsupported-dialect-option",
465
- message: "MySQL index lock mode is invalid",
466
- path: [
467
- ...indexPath,
468
- "dialect",
469
- "lock"
470
- ]
471
- });
472
- if (mysqlExtension.using !== void 0 && ![
473
- "btree",
474
- "hash",
475
- "rtree"
476
- ].includes(String(mysqlExtension.using))) diagnostics.push({
477
- code: "unsupported-dialect-option",
478
- message: "MySQL index access method is invalid",
479
- path: [
480
- ...indexPath,
481
- "dialect",
482
- "using"
483
- ]
484
- });
485
- if (mysqlExtension.parser !== void 0 && (typeof mysqlExtension.parser !== "string" || mysqlExtension.parser.trim().length === 0)) diagnostics.push({
486
- code: "unsupported-dialect-option",
487
- message: "MySQL index parser must be a non-empty string",
488
- path: [
489
- ...indexPath,
490
- "dialect",
491
- "parser"
492
- ]
493
- });
494
- }
495
- }
496
- }
497
- function validateMysqlAutoIncrement(columnId, definition, metadata, columnPath, diagnostics) {
498
- if (definition.nullable) diagnostics.push({
499
- code: "unsupported-dialect-option",
500
- message: "MySQL AUTO_INCREMENT columns must be non-nullable",
501
- path: [...columnPath, "nullable"]
502
- });
503
- if (definition.generatedColumn !== void 0) diagnostics.push({
504
- code: "unsupported-dialect-option",
505
- message: "MySQL AUTO_INCREMENT columns cannot be generated columns",
506
- path: [...columnPath, "generatedColumn"]
507
- });
508
- const declaration = mysqlDeclaration(definition.storage);
509
- if (declaration === void 0 || !isMysqlIntegerDeclaration(declaration)) diagnostics.push({
510
- code: "unsupported-dialect-option",
511
- message: "MySQL AUTO_INCREMENT requires an integer-family physical storage declaration",
512
- path: [...columnPath, "storage"]
513
- });
514
- if (!hasMysqlAutoIncrementKey(columnId, metadata)) diagnostics.push({
515
- code: "unsupported-dialect-option",
516
- message: "MySQL AUTO_INCREMENT columns must be the first column of a primary, unique, or ordinary index key",
517
- path: [
518
- ...columnPath,
519
- "identity",
520
- "dialect",
521
- "autoIncrement"
522
- ]
523
- });
524
- }
525
- function mysqlDeclaration(storage) {
526
- if (storage === void 0) return;
527
- return storage.kind === "native" ? storage.type : mysqlStorageTypes[storage.type];
528
- }
529
- function isMysqlIntegerDeclaration(declaration) {
530
- const base = declaration.trim().toUpperCase().split(/\s+/u)[0] ?? "";
531
- return /^(?:TINYINT|SMALLINT|MEDIUMINT|INT|INTEGER|BIGINT)(?:\(\d+\))?$/u.test(base);
532
- }
533
- function hasMysqlAutoIncrementKey(columnId, metadata) {
534
- for (const constraint of Object.values(metadata.constraints)) if ((constraint.kind === "primary-key" || constraint.kind === "unique" || constraint.kind === "unique-constraint") && isColumnReference(constraint.columns[0]) && constraint.columns[0].fieldName === columnId) return true;
535
- for (const index of Object.values(metadata.indexes)) {
536
- const first = index.terms[0];
537
- const expression = isOrderTerm(first) ? first.expression : first;
538
- if (isColumnReference(expression) && expression.fieldName === columnId) return true;
539
- }
540
- return false;
541
- }
542
- function validateMysqlName(name, path, kind, diagnostics) {
543
- if (!isValidSchemaObjectName(name) || name.length === 0) diagnostics.push({
544
- code: "invalid-schema",
545
- message: `${kind} name "${name}" is not a valid unqualified identifier`,
546
- path
547
- });
548
- if ([...name].length > 64) diagnostics.push({
549
- code: "unsupported-dialect-option",
550
- message: `${kind} name exceeds MySQL's 64-character identifier limit`,
551
- path
552
- });
553
- }
554
- function addScopedName(names, name, path, kind, diagnostics) {
555
- const previousPath = names.get(name);
556
- if (previousPath !== void 0) {
557
- diagnostics.push({
558
- code: "invalid-schema",
559
- message: `MySQL ${kind} name "${name}" collides with another ${kind}`,
560
- path,
561
- relatedPaths: [previousPath]
562
- });
563
- return;
564
- }
565
- names.set(name, path);
566
- }
567
- function appendMetadataDiagnostics(diagnostics, issues) {
568
- for (const issue of issues) {
569
- if (issue.code === "dialect-mismatch") continue;
570
- diagnostics.push({
571
- code: issue.code === "unsupported-dialect-option" ? "unsupported-dialect-option" : "invalid-schema",
572
- message: issue.message,
573
- path: issue.path,
574
- ...issue.relatedPaths === void 0 ? {} : { relatedPaths: issue.relatedPaths }
575
- });
576
- }
577
- }
578
- function isOrderTerm(value) {
579
- return typeof value === "object" && value !== null && "orderKind" in value && value.orderKind === "term" && "expression" in value;
580
- }
581
- function compareIds(left, right) {
582
- return left < right ? -1 : left > right ? 1 : 0;
583
- }
584
- //#endregion
585
- export { tryCreateMysqlSchemaSnapshot as a, postgresSnapshotAdapter as c, mysqlSnapshotDialect as i, postgresSnapshotDialect as l, mysqlSchemaDialect as n, createPostgresSchemaSnapshot as o, mysqlSnapshotAdapter as r, postgresSchemaDialect as s, createMysqlSchemaSnapshot as t, tryCreatePostgresSchemaSnapshot as u };