uql-orm 0.96.1 → 0.98.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.
- package/dist/dialect/abstractSqlDialect.d.ts +1 -7
- package/dist/dialect/abstractSqlDialect.js +1 -9
- package/dist/dialect/mysqlLikeSqlDialect.d.ts +2 -0
- package/dist/dialect/mysqlLikeSqlDialect.js +4 -1
- package/dist/dialect/pgLikeSqlDialect.js +0 -1
- package/dist/migrate/acquireQuerierForMigrations.d.ts +4 -8
- package/dist/migrate/acquireQuerierForMigrations.js +10 -18
- package/dist/migrate/builder/columnBuilder.d.ts +1 -2
- package/dist/migrate/builder/columnBuilder.js +3 -10
- package/dist/migrate/builder/migrationBuilder.d.ts +6 -26
- package/dist/migrate/builder/migrationBuilder.js +21 -78
- package/dist/migrate/builder/tableBuilder.js +2 -3
- package/dist/migrate/builder/types.d.ts +59 -120
- package/dist/migrate/cli-config.d.ts +1 -0
- package/dist/migrate/cli-config.js +11 -26
- package/dist/migrate/cli.d.ts +0 -13
- package/dist/migrate/cli.js +55 -118
- package/dist/migrate/codegen/entityCodeGenerator.d.ts +7 -61
- package/dist/migrate/codegen/entityCodeGenerator.js +53 -174
- package/dist/migrate/codegen/fieldOptionsSource.d.ts +1 -3
- package/dist/migrate/codegen/fieldOptionsSource.js +3 -11
- package/dist/migrate/codegen/index.d.ts +2 -7
- package/dist/migrate/codegen/index.js +2 -8
- package/dist/migrate/codegen/migrationFile.d.ts +1 -8
- package/dist/migrate/codegen/migrationFile.js +9 -13
- package/dist/migrate/ddl/defaultSql.d.ts +2 -1
- package/dist/migrate/ddl/defaultSql.js +1 -3
- package/dist/migrate/ddl/indexCapabilities.d.ts +18 -0
- package/dist/migrate/ddl/indexCapabilities.js +60 -0
- package/dist/migrate/ddl/indexDdl.d.ts +11 -24
- package/dist/migrate/ddl/indexDdl.js +22 -28
- package/dist/migrate/ddl/mssqlIndexDdl.d.ts +1 -7
- package/dist/migrate/ddl/mssqlIndexDdl.js +1 -7
- package/dist/migrate/ddl/mssqlTableDdl.d.ts +6 -9
- package/dist/migrate/ddl/mssqlTableDdl.js +14 -17
- package/dist/migrate/ddl/mysqlIndexDdl.d.ts +0 -21
- package/dist/migrate/ddl/mysqlIndexDdl.js +4 -48
- package/dist/migrate/ddl/mysqlTableDdl.d.ts +6 -5
- package/dist/migrate/ddl/mysqlTableDdl.js +15 -10
- package/dist/migrate/ddl/pgIndexDdl.d.ts +0 -10
- package/dist/migrate/ddl/pgIndexDdl.js +5 -44
- package/dist/migrate/ddl/pgTableDdl.d.ts +6 -2
- package/dist/migrate/ddl/pgTableDdl.js +17 -1
- package/dist/migrate/ddl/sqliteIndexDdl.js +2 -7
- package/dist/migrate/ddl/tableDdl.d.ts +43 -24
- package/dist/migrate/ddl/tableDdl.js +56 -37
- package/dist/migrate/ddl/tableRebuild.d.ts +2 -1
- package/dist/migrate/drift/driftDetector.d.ts +29 -32
- package/dist/migrate/drift/driftDetector.js +155 -205
- package/dist/migrate/drift/index.d.ts +1 -6
- package/dist/migrate/drift/index.js +1 -6
- package/dist/migrate/generator/definitionToNode.d.ts +2 -2
- package/dist/migrate/generator/definitionToNode.js +6 -5
- package/dist/migrate/introspection/abstractSqlSchemaIntrospector.d.ts +56 -77
- package/dist/migrate/introspection/abstractSqlSchemaIntrospector.js +75 -98
- package/dist/migrate/introspection/mssqlIntrospector.d.ts +10 -43
- package/dist/migrate/introspection/mssqlIntrospector.js +52 -77
- package/dist/migrate/introspection/mysqlIntrospector.d.ts +21 -37
- package/dist/migrate/introspection/mysqlIntrospector.js +75 -56
- package/dist/migrate/introspection/postgresIntrospector.d.ts +15 -60
- package/dist/migrate/introspection/postgresIntrospector.js +74 -77
- package/dist/migrate/introspection/sqliteIntrospector.d.ts +19 -53
- package/dist/migrate/introspection/sqliteIntrospector.js +73 -119
- package/dist/migrate/introspection/tableSchemaAST.d.ts +13 -0
- package/dist/migrate/introspection/tableSchemaAST.js +85 -0
- package/dist/migrate/migrationTarget.js +10 -2
- package/dist/migrate/migrator.d.ts +9 -44
- package/dist/migrate/migrator.js +72 -150
- package/dist/migrate/schemaChange.d.ts +8 -5
- package/dist/migrate/schemaChange.js +25 -8
- package/dist/migrate/schemaGenerator.d.ts +35 -109
- package/dist/migrate/schemaGenerator.js +179 -353
- package/dist/migrate/storage/databaseStorage.d.ts +2 -1
- package/dist/migrate/storage/databaseStorage.js +3 -2
- package/dist/migrate/storage/jsonStorage.d.ts +1 -2
- package/dist/migrate/storage/jsonStorage.js +11 -20
- package/dist/migrate/triggerSql.d.ts +7 -9
- package/dist/migrate/triggerSql.js +17 -18
- package/dist/mongo/index.d.ts +0 -1
- package/dist/mongo/index.js +0 -1
- package/dist/mongo/mongoDialect.js +0 -1
- package/dist/mongo/mongoIntrospector.d.ts +1 -6
- package/dist/mongo/mongoIntrospector.js +7 -18
- package/dist/mongo/mongoSchemaGenerator.d.ts +7 -26
- package/dist/mongo/mongoSchemaGenerator.js +51 -75
- package/dist/mssql/mssqlDialect.js +0 -1
- package/dist/schema/canonicalType.d.ts +15 -19
- package/dist/schema/canonicalType.js +20 -43
- package/dist/schema/dependencyGraph.d.ts +2 -3
- package/dist/schema/dependencyGraph.js +0 -4
- package/dist/schema/indexDifferences.js +2 -2
- package/dist/schema/schemaAST.d.ts +1 -1
- package/dist/schema/schemaAST.js +5 -12
- package/dist/schema/schemaASTBuilder.d.ts +5 -6
- package/dist/schema/schemaASTBuilder.js +17 -18
- package/dist/schema/schemaASTDiffer.d.ts +4 -5
- package/dist/schema/schemaASTDiffer.js +40 -73
- package/dist/schema/types.d.ts +24 -54
- package/dist/sqlite/localSqliteQuerierPool.d.ts +16 -2
- package/dist/sqlite/localSqliteQuerierPool.js +20 -4
- package/dist/sqlite/nodeSqliteQuerierPool.js +2 -2
- package/dist/sqlite/sqliteDialect.js +0 -1
- package/dist/sqlite/sqliteQuerierPool.js +3 -3
- package/dist/type/dialect.d.ts +0 -2
- package/dist/type/migration.d.ts +13 -73
- package/dist/util/ddlExpression.util.d.ts +13 -2
- package/dist/util/ddlExpression.util.js +27 -4
- package/dist/util/sql.util.d.ts +2 -12
- package/dist/util/sql.util.js +9 -18
- package/package.json +1 -1
- package/skills/uql-orm/SKILL.md +1 -1
- package/dist/migrate/introspection/baseSqlIntrospector.d.ts +0 -36
- package/dist/migrate/introspection/baseSqlIntrospector.js +0 -133
- package/dist/schema/index.d.ts +0 -2
- package/dist/schema/index.js +0 -1
- package/dist/sqlite/sqlitePragmas.d.ts +0 -3
- package/dist/sqlite/sqlitePragmas.js +0 -15
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { jsonTypeMode } from '../../dialect/jsonSql.js';
|
|
2
|
-
import { INDEX_TYPES } from '../../schema/types.js';
|
|
3
2
|
import { INDEX_FEATURE_LABELS, } from '../../type/index.js';
|
|
3
|
+
import { indexDistance, unsupportedVectorMetric } from '../../type/vector.js';
|
|
4
4
|
import { fulltextConfig, getKeys } from '../../util/index.js';
|
|
5
5
|
import { UqlUsageError } from '../../util/uqlError.js';
|
|
6
|
+
import { INDEX_CAPABILITIES } from './indexCapabilities.js';
|
|
6
7
|
/**
|
|
7
8
|
* What in an index asks for each feature. A `Record` over the feature union rather than a list, so a
|
|
8
9
|
* feature added to {@link INDEX_FEATURE_LABELS} cannot reach a dialect without the test that decides
|
|
@@ -38,12 +39,16 @@ export function assertIndexFeatures(index, features, dialectName) {
|
|
|
38
39
|
*/
|
|
39
40
|
export class IndexDdl {
|
|
40
41
|
dialect;
|
|
42
|
+
/** What this engine's `CREATE INDEX` can say. */
|
|
43
|
+
capabilities;
|
|
41
44
|
constructor(dialect) {
|
|
42
45
|
this.dialect = dialect;
|
|
46
|
+
this.capabilities = INDEX_CAPABILITIES[dialect.dialectName];
|
|
43
47
|
}
|
|
44
48
|
getCreateIndexStatement(tableName, index, opts = {}) {
|
|
45
|
-
|
|
46
|
-
|
|
49
|
+
const { types, features, hints } = this.capabilities;
|
|
50
|
+
assertIndexType(index, types, this.dialect.dialectName, hints);
|
|
51
|
+
assertIndexFeatures(index, features, this.dialect.dialectName);
|
|
47
52
|
const unique = index.unique ? 'UNIQUE ' : '';
|
|
48
53
|
const ifNotExists = (opts.ifNotExists ?? this.dialect.features.indexIfNotExists) ? 'IF NOT EXISTS ' : '';
|
|
49
54
|
const columns = this.indexTarget(index);
|
|
@@ -55,33 +60,13 @@ export class IndexDdl {
|
|
|
55
60
|
settleStatements(_tableName, _index) {
|
|
56
61
|
return [];
|
|
57
62
|
}
|
|
58
|
-
/**
|
|
59
|
-
* Index features this dialect can express. Everything here is supported by at least one engine and
|
|
60
|
-
* refused by at least one other, so an index asking for a missing one is rejected rather than
|
|
61
|
-
* emitted: each of them is a hard error at the server, not a slower plan.
|
|
62
|
-
*/
|
|
63
|
-
indexFeatures = new Set([
|
|
64
|
-
'expression',
|
|
65
|
-
'partial',
|
|
66
|
-
'jsonPath',
|
|
67
|
-
]);
|
|
68
|
-
/**
|
|
69
|
-
* Index types this dialect's `CREATE INDEX` takes. SQLite's grammar has no `USING` clause, so every
|
|
70
|
-
* type builds the plain index it has there, which is what lets an entity written for Postgres
|
|
71
|
-
* migrate unchanged. An engine that would reject a type narrows this, and the type is refused.
|
|
72
|
-
*/
|
|
73
|
-
indexTypes = new Set(INDEX_TYPES);
|
|
74
|
-
/** What to declare instead of a type this dialect lacks, appended to its refusal. */
|
|
75
|
-
indexTypeHints = new Map();
|
|
76
|
-
/**
|
|
77
|
-
* Index types this dialect spells as a keyword of their own (`FULLTEXT INDEX`, `VECTOR INDEX`)
|
|
78
|
-
* rather than as an access method after the table. One table drives both, so a type that is a
|
|
79
|
-
* keyword here can never also leak out as a ` USING` clause the engine has no word for.
|
|
80
|
-
*/
|
|
81
|
-
indexTypeKeywords = new Map();
|
|
82
63
|
/** The keyword an index type replaces `INDEX` with, or `INDEX` for the types that do not. */
|
|
83
64
|
indexKeyword(index) {
|
|
84
|
-
return (index.type && this.
|
|
65
|
+
return (index.type && this.capabilities.keywords.get(index.type)) || 'INDEX';
|
|
66
|
+
}
|
|
67
|
+
/** ` USING <type>`, or nothing for no type or one spelled as its own keyword. */
|
|
68
|
+
usingType(index) {
|
|
69
|
+
return index.type && !this.capabilities.keywords.has(index.type) ? ` USING ${index.type}` : '';
|
|
85
70
|
}
|
|
86
71
|
/** What the index is over, between the parentheses: a fulltext one's columns as a search matches them, else its entries. */
|
|
87
72
|
indexTarget(index) {
|
|
@@ -128,6 +113,15 @@ export class IndexDdl {
|
|
|
128
113
|
indexInclude(_index) {
|
|
129
114
|
return '';
|
|
130
115
|
}
|
|
116
|
+
/** The metric this engine's vector index names for the index's distance, refusing a distance it has none for. */
|
|
117
|
+
indexMetric(index) {
|
|
118
|
+
const distance = indexDistance(index);
|
|
119
|
+
const metric = this.dialect.vectorMetrics.get(distance)?.index;
|
|
120
|
+
if (!metric) {
|
|
121
|
+
throw unsupportedVectorMetric(this.dialect.dialectName, distance, index.name);
|
|
122
|
+
}
|
|
123
|
+
return metric;
|
|
124
|
+
}
|
|
131
125
|
/** ` USING <method>`, which SQLite's grammar has no place for at all. */
|
|
132
126
|
indexAccessMethod(_index) {
|
|
133
127
|
return '';
|
|
@@ -1,13 +1,7 @@
|
|
|
1
1
|
import type { IndexSchema } from '../../type/index.js';
|
|
2
2
|
import { IndexDdl } from './indexDdl.js';
|
|
3
|
-
/**
|
|
4
|
-
* SQL Server's `CREATE INDEX` is the portable form minus what 2025 rejects: an expression (Msg 16216),
|
|
5
|
-
* the subquery a JSON path compiles to (Msg 1046), and any type but the plain rowstore B-tree, since
|
|
6
|
-
* the index built in its place fails on a `VECTOR` or `nvarchar(max)` column (Msg 1978).
|
|
7
|
-
*/
|
|
3
|
+
/** SQL Server's `CREATE INDEX`, the portable form less what 2025 rejects, which its capabilities state. */
|
|
8
4
|
export declare class MsSqlIndexDdl extends IndexDdl {
|
|
9
|
-
protected readonly indexFeatures: Set<"expression" | "include" | "jsonArray" | "jsonPath" | "nullsOrder" | "opsClass" | "partial" | "prefixLength">;
|
|
10
|
-
protected readonly indexTypes: Set<"brin" | "btree" | "fulltext" | "gin" | "gist" | "hash" | "hnsw" | "ivfflat" | "vector" | "vectorSearch">;
|
|
11
5
|
/** T-SQL has no `IF NOT EXISTS` on an index, so the create is guarded by a lookup in the same statement. */
|
|
12
6
|
getCreateIndexStatement(tableName: string, index: IndexSchema, opts?: {
|
|
13
7
|
ifNotExists?: boolean;
|
|
@@ -1,12 +1,6 @@
|
|
|
1
1
|
import { IndexDdl } from './indexDdl.js';
|
|
2
|
-
/**
|
|
3
|
-
* SQL Server's `CREATE INDEX` is the portable form minus what 2025 rejects: an expression (Msg 16216),
|
|
4
|
-
* the subquery a JSON path compiles to (Msg 1046), and any type but the plain rowstore B-tree, since
|
|
5
|
-
* the index built in its place fails on a `VECTOR` or `nvarchar(max)` column (Msg 1978).
|
|
6
|
-
*/
|
|
2
|
+
/** SQL Server's `CREATE INDEX`, the portable form less what 2025 rejects, which its capabilities state. */
|
|
7
3
|
export class MsSqlIndexDdl extends IndexDdl {
|
|
8
|
-
indexFeatures = new Set(['partial']);
|
|
9
|
-
indexTypes = new Set(['btree']);
|
|
10
4
|
/** T-SQL has no `IF NOT EXISTS` on an index, so the create is guarded by a lookup in the same statement. */
|
|
11
5
|
getCreateIndexStatement(tableName, index, opts = {}) {
|
|
12
6
|
const create = super.getCreateIndexStatement(tableName, index, { ifNotExists: false });
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import type
|
|
2
|
-
import { TableDdl } from './tableDdl.js';
|
|
1
|
+
import { type ColumnAlteration, TableDdl } from './tableDdl.js';
|
|
3
2
|
/**
|
|
4
3
|
* SQL Server keeps a column's `DEFAULT`, `CHECK` and `UNIQUE` as constraints under names it picks, and
|
|
5
4
|
* refuses to drop or retype the column past one or past an index over it, so they go first - looked up
|
|
@@ -9,20 +8,18 @@ export declare class MsSqlTableDdl extends TableDdl {
|
|
|
9
8
|
/** T-SQL has no `IF NOT EXISTS` on a table, so the create is guarded by a lookup in the same statement. */
|
|
10
9
|
createTable(target: string, ifNotExists: boolean): string;
|
|
11
10
|
/** T-SQL rejects the optional `COLUMN` keyword after `ADD`. */
|
|
12
|
-
addColumn(table: string, definition: string): string;
|
|
11
|
+
protected addColumn(table: string, definition: string): string;
|
|
13
12
|
/** Its constraints and indexes go with the column, as they do on every other engine. */
|
|
14
13
|
dropColumn(table: string, column: string): string[];
|
|
15
14
|
/**
|
|
16
|
-
* `ALTER COLUMN` takes the type and nullability alone, so the default is dropped and
|
|
17
|
-
* constraint of its own. A `CHECK` or `UNIQUE` stays, and the server refuses a retype it blocks.
|
|
15
|
+
* A statement per column: `ALTER COLUMN` takes the type and nullability alone, so the default is dropped and
|
|
16
|
+
* added back as a constraint of its own. A `CHECK` or `UNIQUE` stays, and the server refuses a retype it blocks.
|
|
18
17
|
*/
|
|
19
|
-
|
|
20
|
-
/** One column an `ALTER COLUMN`, each with the batch {@link alterColumn} writes. */
|
|
21
|
-
alterColumns(table: string, alterations: readonly Alteration<ColumnSchema>[]): string[];
|
|
18
|
+
alterColumns(table: string, alterations: readonly ColumnAlteration[]): string[];
|
|
22
19
|
renameColumn(table: string, oldName: string, newName: string): string;
|
|
23
20
|
renameTable(oldName: string, newName: string): string;
|
|
24
21
|
dropIndex(table: string, index: string): string;
|
|
25
|
-
storedGeneratedColumn(_type: string, expression: string): string;
|
|
22
|
+
protected storedGeneratedColumn(_type: string, expression: string): string;
|
|
26
23
|
/** One statement, so a split on `;` cannot part the lookup from the `EXEC` it feeds. */
|
|
27
24
|
private dropPinning;
|
|
28
25
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { escapeSingleQuotes } from '../../util/sqlLiteral.js';
|
|
2
|
-
import { dropIndexOnTable,
|
|
2
|
+
import { dropIndexOnTable, TableDdl } from './tableDdl.js';
|
|
3
3
|
/** What pins column `c`, the `sys.columns` row {@link MsSqlTableDdl} reads: each constraint, then each index, by kind. */
|
|
4
4
|
const PINNED_BY = {
|
|
5
5
|
default: /*sql*/ `SELECT d.name, 0 AS is_index FROM sys.default_constraints d
|
|
@@ -34,24 +34,21 @@ export class MsSqlTableDdl extends TableDdl {
|
|
|
34
34
|
return [this.dropPinning(table, column, Object.values(PINNED_BY)), ...super.dropColumn(table, column)];
|
|
35
35
|
}
|
|
36
36
|
/**
|
|
37
|
-
* `ALTER COLUMN` takes the type and nullability alone, so the default is dropped and
|
|
38
|
-
* constraint of its own. A `CHECK` or `UNIQUE` stays, and the server refuses a retype it blocks.
|
|
37
|
+
* A statement per column: `ALTER COLUMN` takes the type and nullability alone, so the default is dropped and
|
|
38
|
+
* added back as a constraint of its own. A `CHECK` or `UNIQUE` stays, and the server refuses a retype it blocks.
|
|
39
39
|
*/
|
|
40
|
-
alterColumn(table, column) {
|
|
41
|
-
const target = this.dialect.escapeId(table);
|
|
42
|
-
const name = this.dialect.escapeId(column.name);
|
|
43
|
-
const statements = [
|
|
44
|
-
this.dropPinning(table, column.name, [PINNED_BY.default]),
|
|
45
|
-
/*sql*/ `ALTER TABLE ${target} ALTER COLUMN ${name} ${sizedType(column)} ${column.nullable ? 'NULL' : 'NOT NULL'};`,
|
|
46
|
-
];
|
|
47
|
-
if (column.defaultValue !== undefined) {
|
|
48
|
-
statements.push(/*sql*/ `ALTER TABLE ${target} ADD${this.defaultClause(column)} FOR ${name};`);
|
|
49
|
-
}
|
|
50
|
-
return statements;
|
|
51
|
-
}
|
|
52
|
-
/** One column an `ALTER COLUMN`, each with the batch {@link alterColumn} writes. */
|
|
53
40
|
alterColumns(table, alterations) {
|
|
54
|
-
|
|
41
|
+
const target = this.dialect.escapeId(table);
|
|
42
|
+
return alterations.flatMap(({ to: column }) => {
|
|
43
|
+
const name = this.dialect.escapeId(column.name);
|
|
44
|
+
return [
|
|
45
|
+
this.dropPinning(table, column.name, [PINNED_BY.default]),
|
|
46
|
+
/*sql*/ `ALTER TABLE ${target} ALTER COLUMN ${name} ${column.type} ${column.nullable ? 'NULL' : 'NOT NULL'};`,
|
|
47
|
+
...(column.defaultValue === undefined
|
|
48
|
+
? []
|
|
49
|
+
: [/*sql*/ `ALTER TABLE ${target} ADD${this.defaultClause(column)} FOR ${name};`]),
|
|
50
|
+
];
|
|
51
|
+
});
|
|
55
52
|
}
|
|
56
53
|
renameColumn(table, oldName, newName) {
|
|
57
54
|
const qualified = `${this.dialect.escapeId(table)}.${this.dialect.escapeId(oldName)}`;
|
|
@@ -1,11 +1,7 @@
|
|
|
1
|
-
import type { IndexType } from '../../schema/types.js';
|
|
2
1
|
import type { IndexColumnSchema, IndexJsonPath, IndexSchema } from '../../type/index.js';
|
|
3
2
|
import { IndexDdl } from './indexDdl.js';
|
|
4
3
|
/** `CREATE INDEX ... (cols) USING btree`, plus the types this family spells as a keyword instead. */
|
|
5
4
|
export declare class MysqlLikeIndexDdl extends IndexDdl {
|
|
6
|
-
protected readonly indexFeatures: Set<"expression" | "include" | "jsonArray" | "jsonPath" | "nullsOrder" | "opsClass" | "partial" | "prefixLength">;
|
|
7
|
-
protected readonly indexTypes: ReadonlySet<IndexType>;
|
|
8
|
-
protected readonly indexTypeKeywords: ReadonlyMap<IndexType, string>;
|
|
9
5
|
/**
|
|
10
6
|
* InnoDB fills a fulltext index added beside another on a loaded table only once the table is optimized:
|
|
11
7
|
* until then MariaDB scores it 0 and MySQL can fail a `MATCH` over it (MySQL 26.7, MariaDB 12.3).
|
|
@@ -15,7 +11,6 @@ export declare class MysqlLikeIndexDdl extends IndexDdl {
|
|
|
15
11
|
protected indexTuning(index: IndexSchema): string;
|
|
16
12
|
}
|
|
17
13
|
export declare class MySqlIndexDdl extends MysqlLikeIndexDdl {
|
|
18
|
-
protected readonly indexFeatures: Set<"expression" | "include" | "jsonArray" | "jsonPath" | "nullsOrder" | "opsClass" | "partial" | "prefixLength">;
|
|
19
14
|
/**
|
|
20
15
|
* A number as the query reads it. A string as `CHAR(n)` in the collation `->>` returns, which the
|
|
21
16
|
* planner strips back to the bare `->>` a query compares; any other collation leaves it unused. A
|
|
@@ -28,24 +23,8 @@ export declare class MySqlIndexDdl extends MysqlLikeIndexDdl {
|
|
|
28
23
|
* `JSON_CONTAINS(col, ?)` is matched against. A `path` indexes the array at that path instead.
|
|
29
24
|
*/
|
|
30
25
|
protected indexColumnTarget(entry: IndexColumnSchema): string;
|
|
31
|
-
/**
|
|
32
|
-
* MySQL 26.7 has `VECTOR` columns and `STRING_TO_VECTOR`, but no distance function outside
|
|
33
|
-
* HeatWave, hence no vector index to build: `USING hnsw` is a syntax error, `VECTOR INDEX` MariaDB's.
|
|
34
|
-
*/
|
|
35
|
-
protected readonly indexTypeHints: Map<"brin" | "btree" | "fulltext" | "gin" | "gist" | "hash" | "hnsw" | "ivfflat" | "vector" | "vectorSearch", string>;
|
|
36
26
|
}
|
|
37
27
|
export declare class MariaIndexDdl extends MysqlLikeIndexDdl {
|
|
38
|
-
/**
|
|
39
|
-
* MariaDB has no functional indexes: `CREATE INDEX ... ((lower(col)))` is a syntax error even on
|
|
40
|
-
* 12.3, where the documented workaround is a generated column. So it keeps the prefix lengths the
|
|
41
|
-
* family shares and drops expressions - and with them both JSON index forms, which are expressions.
|
|
42
|
-
*/
|
|
43
|
-
protected readonly indexFeatures: Set<"expression" | "include" | "jsonArray" | "jsonPath" | "nullsOrder" | "opsClass" | "partial" | "prefixLength">;
|
|
44
|
-
/** The family's, plus a vector index of its own: `CREATE VECTOR INDEX ... ON t (col)`, 11.7+. */
|
|
45
|
-
protected readonly indexTypeKeywords: ReadonlyMap<IndexType, string>;
|
|
46
|
-
protected readonly indexTypes: Set<"brin" | "btree" | "fulltext" | "gin" | "gist" | "hash" | "hnsw" | "ivfflat" | "vector" | "vectorSearch">;
|
|
47
|
-
/** pgvector's names are not access methods it has; `vector` is its own keyword above. */
|
|
48
|
-
protected readonly indexTypeHints: Map<"brin" | "btree" | "fulltext" | "gin" | "gist" | "hash" | "hnsw" | "ivfflat" | "vector" | "vectorSearch", string>;
|
|
49
28
|
/**
|
|
50
29
|
* `M=n DISTANCE=metric`, trailing its `CREATE VECTOR INDEX`. The metric names are MariaDB's own
|
|
51
30
|
* (`euclidean`, not `l2`), stated even for the default distance, cosine, since MariaDB's own is
|
|
@@ -1,17 +1,9 @@
|
|
|
1
1
|
import { jsonTypeMode } from '../../dialect/jsonSql.js';
|
|
2
|
-
import {
|
|
2
|
+
import { isVectorIndexType } from '../../type/vector.js';
|
|
3
3
|
import { UqlUsageError } from '../../util/uqlError.js';
|
|
4
4
|
import { IndexDdl } from './indexDdl.js';
|
|
5
|
-
/**
|
|
6
|
-
* A full-text index is its own keyword here (`CREATE FULLTEXT INDEX ... (cols)`); `USING fulltext` is
|
|
7
|
-
* a syntax error, so it is the keyword that changes rather than the access method.
|
|
8
|
-
*/
|
|
9
|
-
const MYSQL_LIKE_INDEX_KEYWORDS = new Map([['fulltext', 'FULLTEXT INDEX']]);
|
|
10
5
|
/** `CREATE INDEX ... (cols) USING btree`, plus the types this family spells as a keyword instead. */
|
|
11
6
|
export class MysqlLikeIndexDdl extends IndexDdl {
|
|
12
|
-
indexFeatures = new Set(['expression', 'prefixLength']);
|
|
13
|
-
indexTypes = new Set(['btree', 'hash', 'fulltext']);
|
|
14
|
-
indexTypeKeywords = MYSQL_LIKE_INDEX_KEYWORDS;
|
|
15
7
|
/**
|
|
16
8
|
* InnoDB fills a fulltext index added beside another on a loaded table only once the table is optimized:
|
|
17
9
|
* until then MariaDB scores it 0 and MySQL can fail a `MATCH` over it (MySQL 26.7, MariaDB 12.3).
|
|
@@ -21,16 +13,10 @@ export class MysqlLikeIndexDdl extends IndexDdl {
|
|
|
21
13
|
}
|
|
22
14
|
/** ` USING btree|hash` trails the columns: between the table and them, it is a syntax error here. */
|
|
23
15
|
indexTuning(index) {
|
|
24
|
-
return
|
|
16
|
+
return this.usingType(index);
|
|
25
17
|
}
|
|
26
18
|
}
|
|
27
19
|
export class MySqlIndexDdl extends MysqlLikeIndexDdl {
|
|
28
|
-
indexFeatures = new Set([
|
|
29
|
-
'expression',
|
|
30
|
-
'prefixLength',
|
|
31
|
-
'jsonPath',
|
|
32
|
-
'jsonArray',
|
|
33
|
-
]);
|
|
34
20
|
/**
|
|
35
21
|
* A number as the query reads it. A string as `CHAR(n)` in the collation `->>` returns, which the
|
|
36
22
|
* planner strips back to the bare `->>` a query compares; any other collation leaves it unused. A
|
|
@@ -64,46 +50,16 @@ export class MySqlIndexDdl extends MysqlLikeIndexDdl {
|
|
|
64
50
|
const source = json.path ? this.dialect.jsonPathExpr(column, json.path, 'json') : column;
|
|
65
51
|
return `(CAST(${source} AS ${arrayCastType(json)} ARRAY))`;
|
|
66
52
|
}
|
|
67
|
-
/**
|
|
68
|
-
* MySQL 26.7 has `VECTOR` columns and `STRING_TO_VECTOR`, but no distance function outside
|
|
69
|
-
* HeatWave, hence no vector index to build: `USING hnsw` is a syntax error, `VECTOR INDEX` MariaDB's.
|
|
70
|
-
*/
|
|
71
|
-
indexTypeHints = new Map(VECTOR_INDEX_TYPES.map((type) => [type, '. Vector search on MySQL needs HeatWave']));
|
|
72
53
|
}
|
|
73
54
|
export class MariaIndexDdl extends MysqlLikeIndexDdl {
|
|
74
|
-
/**
|
|
75
|
-
* MariaDB has no functional indexes: `CREATE INDEX ... ((lower(col)))` is a syntax error even on
|
|
76
|
-
* 12.3, where the documented workaround is a generated column. So it keeps the prefix lengths the
|
|
77
|
-
* family shares and drops expressions - and with them both JSON index forms, which are expressions.
|
|
78
|
-
*/
|
|
79
|
-
indexFeatures = new Set(['prefixLength']);
|
|
80
|
-
/** The family's, plus a vector index of its own: `CREATE VECTOR INDEX ... ON t (col)`, 11.7+. */
|
|
81
|
-
indexTypeKeywords = new Map([
|
|
82
|
-
...MYSQL_LIKE_INDEX_KEYWORDS,
|
|
83
|
-
['vector', 'VECTOR INDEX'],
|
|
84
|
-
]);
|
|
85
|
-
indexTypes = new Set(['btree', 'hash', 'fulltext', 'vector']);
|
|
86
|
-
/** pgvector's names are not access methods it has; `vector` is its own keyword above. */
|
|
87
|
-
indexTypeHints = new Map([
|
|
88
|
-
['hnsw', "; declare type: 'vector' instead"],
|
|
89
|
-
['ivfflat', "; declare type: 'vector' instead"],
|
|
90
|
-
]);
|
|
91
55
|
/**
|
|
92
56
|
* `M=n DISTANCE=metric`, trailing its `CREATE VECTOR INDEX`. The metric names are MariaDB's own
|
|
93
57
|
* (`euclidean`, not `l2`), stated even for the default distance, cosine, since MariaDB's own is
|
|
94
58
|
* euclidean; and an unsupported one throws rather than silently building on euclidean.
|
|
95
59
|
*/
|
|
96
60
|
indexTuning(index) {
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
const distance = indexDistance(index);
|
|
100
|
-
const metric = this.dialect.vectorMetrics.get(distance)?.index;
|
|
101
|
-
if (!metric) {
|
|
102
|
-
throw unsupportedVectorMetric(this.dialect.dialectName, distance, index.name);
|
|
103
|
-
}
|
|
104
|
-
tuning += ` DISTANCE=${metric}`;
|
|
105
|
-
}
|
|
106
|
-
return tuning;
|
|
61
|
+
const tuning = super.indexTuning(index) + (index.m === undefined ? '' : ` M=${index.m}`);
|
|
62
|
+
return isVectorIndexType(index.type) ? `${tuning} DISTANCE=${this.indexMetric(index)}` : tuning;
|
|
107
63
|
}
|
|
108
64
|
}
|
|
109
65
|
/**
|
|
@@ -1,17 +1,18 @@
|
|
|
1
1
|
import type { ColumnSchema } from '../../type/index.js';
|
|
2
2
|
import { TableDdl } from './tableDdl.js';
|
|
3
|
-
/** Table DDL for the MySQL family: `MODIFY COLUMN`, and dedicated clauses to drop a
|
|
3
|
+
/** Table DDL for the MySQL family: `MODIFY COLUMN`, inline comments, and dedicated clauses to drop a key. */
|
|
4
4
|
export declare class MySqlTableDdl extends TableDdl {
|
|
5
|
-
|
|
5
|
+
tableSuffix(comment?: string): string;
|
|
6
|
+
protected columnComment(comment?: string): string;
|
|
6
7
|
/**
|
|
7
8
|
* MySQL fills existing rows with a zero when it adds a required column that has no default. So the column
|
|
8
9
|
* is added nullable and then made required, which fails on those rows as it does on other engines.
|
|
9
10
|
*/
|
|
10
|
-
addColumnStatements(table: string, column: ColumnSchema,
|
|
11
|
-
protected alterClauses(
|
|
11
|
+
addColumnStatements(table: string, column: ColumnSchema, constraints?: string): string[];
|
|
12
|
+
protected alterClauses(column: ColumnSchema): string[];
|
|
12
13
|
/** Ignores `schema`: MySQL reads it from the table name, which is already qualified. */
|
|
13
14
|
dropIndex(table: string, index: string): string;
|
|
14
15
|
dropForeignKey(table: string, constraint: string): string;
|
|
15
16
|
/** MySQL always names the primary key `PRIMARY`, so it is dropped without a name. */
|
|
16
|
-
dropPrimaryKey(
|
|
17
|
+
protected dropPrimaryKey(): string;
|
|
17
18
|
}
|
|
@@ -1,23 +1,28 @@
|
|
|
1
1
|
import { lacksValue } from '../schemaChange.js';
|
|
2
2
|
import { dropIndexOnTable, TableDdl } from './tableDdl.js';
|
|
3
|
-
/** Table DDL for the MySQL family: `MODIFY COLUMN`, and dedicated clauses to drop a
|
|
3
|
+
/** Table DDL for the MySQL family: `MODIFY COLUMN`, inline comments, and dedicated clauses to drop a key. */
|
|
4
4
|
export class MySqlTableDdl extends TableDdl {
|
|
5
|
-
|
|
5
|
+
tableSuffix(comment) {
|
|
6
|
+
return ` ENGINE=InnoDB DEFAULT CHARSET=utf8mb4${comment ? ` COMMENT=${this.dialect.escape(comment)}` : ''}`;
|
|
7
|
+
}
|
|
8
|
+
columnComment(comment) {
|
|
9
|
+
return comment ? ` COMMENT ${this.dialect.escape(comment)}` : '';
|
|
10
|
+
}
|
|
6
11
|
/**
|
|
7
12
|
* MySQL fills existing rows with a zero when it adds a required column that has no default. So the column
|
|
8
13
|
* is added nullable and then made required, which fails on those rows as it does on other engines.
|
|
9
14
|
*/
|
|
10
|
-
addColumnStatements(table, column,
|
|
15
|
+
addColumnStatements(table, column, constraints = '') {
|
|
11
16
|
if (!lacksValue(column)) {
|
|
12
|
-
return super.addColumnStatements(table, column,
|
|
17
|
+
return super.addColumnStatements(table, column, constraints);
|
|
13
18
|
}
|
|
14
19
|
return [
|
|
15
|
-
this.addColumn(table,
|
|
16
|
-
...this.
|
|
20
|
+
this.addColumn(table, this.columnDefinition({ ...column, nullable: true }) + constraints),
|
|
21
|
+
...this.alterColumns(table, [{ to: column }]),
|
|
17
22
|
];
|
|
18
23
|
}
|
|
19
|
-
alterClauses(
|
|
20
|
-
return [`MODIFY COLUMN ${
|
|
24
|
+
alterClauses(column) {
|
|
25
|
+
return [`MODIFY COLUMN ${this.columnDefinition(column)}`];
|
|
21
26
|
}
|
|
22
27
|
/** Ignores `schema`: MySQL reads it from the table name, which is already qualified. */
|
|
23
28
|
dropIndex(table, index) {
|
|
@@ -27,7 +32,7 @@ export class MySqlTableDdl extends TableDdl {
|
|
|
27
32
|
return `ALTER TABLE ${this.dialect.escapeId(table)} DROP FOREIGN KEY ${this.dialect.escapeId(constraint)};`;
|
|
28
33
|
}
|
|
29
34
|
/** MySQL always names the primary key `PRIMARY`, so it is dropped without a name. */
|
|
30
|
-
dropPrimaryKey(
|
|
31
|
-
return
|
|
35
|
+
dropPrimaryKey() {
|
|
36
|
+
return 'DROP PRIMARY KEY';
|
|
32
37
|
}
|
|
33
38
|
}
|
|
@@ -2,9 +2,6 @@ import type { IndexColumnSchema, IndexSchema } from '../../type/index.js';
|
|
|
2
2
|
import { IndexDdl } from './indexDdl.js';
|
|
3
3
|
/** `CREATE INDEX ... USING hnsw ("embedding" vector_cosine_ops) WITH (m = ...)`, pgvector's form. */
|
|
4
4
|
export declare class PgIndexDdl extends IndexDdl {
|
|
5
|
-
/** Postgres 18's `pg_am`, with pgvector's two, and `fulltext`, which builds a `gin` one. */
|
|
6
|
-
protected readonly indexTypes: Set<"brin" | "btree" | "fulltext" | "gin" | "gist" | "hash" | "hnsw" | "ivfflat" | "vector" | "vectorSearch">;
|
|
7
|
-
protected readonly indexFeatures: Set<"expression" | "include" | "jsonArray" | "jsonPath" | "nullsOrder" | "opsClass" | "partial" | "prefixLength">;
|
|
8
5
|
/** pgvector's own index types; CockroachDB's native one widens this. */
|
|
9
6
|
protected isVectorIndex(index: IndexSchema): boolean;
|
|
10
7
|
protected indexAccessMethod(index: IndexSchema): string;
|
|
@@ -19,14 +16,7 @@ export declare class PgIndexDdl extends IndexDdl {
|
|
|
19
16
|
}
|
|
20
17
|
/** CockroachDB's native `CREATE VECTOR INDEX`, for `type: 'vector'`; it has neither `NULLS FIRST/LAST` nor `jsonb_path_ops`. */
|
|
21
18
|
export declare class CockroachIndexDdl extends PgIndexDdl {
|
|
22
|
-
protected readonly indexFeatures: Set<"expression" | "include" | "jsonArray" | "jsonPath" | "nullsOrder" | "opsClass" | "partial" | "prefixLength">;
|
|
23
|
-
/** v26.3 answers `hash` and `brin` "unimplemented", `ivfflat` "unrecognized"; `hnsw` builds its vector index. */
|
|
24
|
-
protected readonly indexTypes: Set<"brin" | "btree" | "fulltext" | "gin" | "gist" | "hash" | "hnsw" | "ivfflat" | "vector" | "vectorSearch">;
|
|
25
|
-
protected readonly indexTypeHints: Map<"brin" | "btree" | "fulltext" | "gin" | "gist" | "hash" | "hnsw" | "ivfflat" | "vector" | "vectorSearch", string>;
|
|
26
|
-
private isNativeVectorIndex;
|
|
27
19
|
protected isVectorIndex(index: IndexSchema): boolean;
|
|
28
|
-
protected indexKeyword(index: IndexSchema): string;
|
|
29
|
-
protected indexAccessMethod(index: IndexSchema): string;
|
|
30
20
|
/** Its build-time candidate list alone: pgvector's `WITH (m = 16)` answers "invalid storage parameter", `hnsw` included. */
|
|
31
21
|
protected indexTuning(index: IndexSchema): string;
|
|
32
22
|
}
|
|
@@ -1,27 +1,8 @@
|
|
|
1
|
-
import { indexDistance
|
|
1
|
+
import { indexDistance } from '../../type/vector.js';
|
|
2
2
|
import { UqlUsageError } from '../../util/uqlError.js';
|
|
3
3
|
import { IndexDdl } from './indexDdl.js';
|
|
4
4
|
/** `CREATE INDEX ... USING hnsw ("embedding" vector_cosine_ops) WITH (m = ...)`, pgvector's form. */
|
|
5
5
|
export class PgIndexDdl extends IndexDdl {
|
|
6
|
-
/** Postgres 18's `pg_am`, with pgvector's two, and `fulltext`, which builds a `gin` one. */
|
|
7
|
-
indexTypes = new Set([
|
|
8
|
-
'btree',
|
|
9
|
-
'hash',
|
|
10
|
-
'gin',
|
|
11
|
-
'gist',
|
|
12
|
-
'brin',
|
|
13
|
-
'hnsw',
|
|
14
|
-
'ivfflat',
|
|
15
|
-
'fulltext',
|
|
16
|
-
]);
|
|
17
|
-
indexFeatures = new Set([
|
|
18
|
-
'expression',
|
|
19
|
-
'partial',
|
|
20
|
-
'nullsOrder',
|
|
21
|
-
'opsClass',
|
|
22
|
-
'include',
|
|
23
|
-
'jsonPath',
|
|
24
|
-
]);
|
|
25
6
|
/** pgvector's own index types; CockroachDB's native one widens this. */
|
|
26
7
|
isVectorIndex(index) {
|
|
27
8
|
return index.type === 'hnsw' || index.type === 'ivfflat';
|
|
@@ -30,7 +11,7 @@ export class PgIndexDdl extends IndexDdl {
|
|
|
30
11
|
if (index.type === 'fulltext') {
|
|
31
12
|
return ' USING gin';
|
|
32
13
|
}
|
|
33
|
-
return
|
|
14
|
+
return this.usingType(index);
|
|
34
15
|
}
|
|
35
16
|
/**
|
|
36
17
|
* A vector index's operator class, `{type}_{metric}_ops` (`halfvec_cosine_ops`), refusing a metric it
|
|
@@ -41,15 +22,10 @@ export class PgIndexDdl extends IndexDdl {
|
|
|
41
22
|
if (!this.isVectorIndex(index)) {
|
|
42
23
|
return entry.opsClass ? ` ${entry.opsClass}` : '';
|
|
43
24
|
}
|
|
44
|
-
const distance = indexDistance(index);
|
|
45
|
-
const metric = this.dialect.vectorMetrics.get(distance)?.index;
|
|
46
|
-
if (!metric) {
|
|
47
|
-
throw unsupportedVectorMetric(this.dialect.dialectName, distance, index.name);
|
|
48
|
-
}
|
|
49
25
|
const vectorType = this.dialect.supportedVectorType(index.vectorType ?? 'vector');
|
|
50
|
-
const opsClass = `${vectorType}_${
|
|
26
|
+
const opsClass = `${vectorType}_${this.indexMetric(index)}_ops`;
|
|
51
27
|
// IVFFlat has neither a sparsevec nor an L1 operator class; HNSW has all of them (pgvector 0.8.2).
|
|
52
|
-
if (index.type === 'ivfflat' && (vectorType === 'sparsevec' ||
|
|
28
|
+
if (index.type === 'ivfflat' && (vectorType === 'sparsevec' || indexDistance(index) === 'l1')) {
|
|
53
29
|
throw new UqlUsageError(`ivfflat has no ${opsClass} operator class (index "${index.name}"); use hnsw`);
|
|
54
30
|
}
|
|
55
31
|
return ` ${opsClass}`;
|
|
@@ -75,23 +51,8 @@ export class PgIndexDdl extends IndexDdl {
|
|
|
75
51
|
}
|
|
76
52
|
/** CockroachDB's native `CREATE VECTOR INDEX`, for `type: 'vector'`; it has neither `NULLS FIRST/LAST` nor `jsonb_path_ops`. */
|
|
77
53
|
export class CockroachIndexDdl extends PgIndexDdl {
|
|
78
|
-
indexFeatures = new Set(['expression', 'partial', 'include', 'jsonPath']);
|
|
79
|
-
/** v26.3 answers `hash` and `brin` "unimplemented", `ivfflat` "unrecognized"; `hnsw` builds its vector index. */
|
|
80
|
-
indexTypes = new Set(['btree', 'gin', 'gist', 'hnsw', 'vector', 'fulltext']);
|
|
81
|
-
indexTypeHints = new Map([
|
|
82
|
-
['ivfflat', "; declare type: 'vector' instead"],
|
|
83
|
-
]);
|
|
84
|
-
isNativeVectorIndex(index) {
|
|
85
|
-
return index.type === 'vector';
|
|
86
|
-
}
|
|
87
54
|
isVectorIndex(index) {
|
|
88
|
-
return
|
|
89
|
-
}
|
|
90
|
-
indexKeyword(index) {
|
|
91
|
-
return this.isNativeVectorIndex(index) ? 'VECTOR INDEX' : super.indexKeyword(index);
|
|
92
|
-
}
|
|
93
|
-
indexAccessMethod(index) {
|
|
94
|
-
return this.isNativeVectorIndex(index) ? '' : super.indexAccessMethod(index);
|
|
55
|
+
return index.type === 'vector' || super.isVectorIndex(index);
|
|
95
56
|
}
|
|
96
57
|
/** Its build-time candidate list alone: pgvector's `WITH (m = 16)` answers "invalid storage parameter", `hnsw` included. */
|
|
97
58
|
indexTuning(index) {
|
|
@@ -1,11 +1,15 @@
|
|
|
1
1
|
import type { ColumnSchema } from '../../type/index.js';
|
|
2
|
-
import { TableDdl } from './tableDdl.js';
|
|
2
|
+
import { type Commented, TableDdl } from './tableDdl.js';
|
|
3
3
|
/** Table DDL for the Postgres family, which alters each part of a column in a separate clause. */
|
|
4
4
|
export declare class PgTableDdl extends TableDdl {
|
|
5
5
|
/** A clause for each part that differs from `from`, the column as it was, or for every part without it. */
|
|
6
|
-
protected alterClauses(column: ColumnSchema,
|
|
6
|
+
protected alterClauses(column: ColumnSchema, from?: ColumnSchema): string[];
|
|
7
|
+
/** `COMMENT ON`, a statement of its own for the table and for each column. */
|
|
8
|
+
commentStatements(table: string, comment: string | undefined, columns: readonly Commented[]): string[];
|
|
7
9
|
}
|
|
8
10
|
/** CockroachDB refuses a rewriting retype beside any other clause, and changes a schema online anyway. */
|
|
9
11
|
export declare class CockroachTableDdl extends PgTableDdl {
|
|
10
12
|
protected alterTable(table: string, clauses: readonly string[]): string[];
|
|
13
|
+
/** In one statement: a `schema_locked` table, its default, drops a key only beside the key replacing it. */
|
|
14
|
+
protected keyChange(table: string, drop?: string, add?: string): [string[], string[]];
|
|
11
15
|
}
|
|
@@ -3,7 +3,7 @@ import { TableDdl } from './tableDdl.js';
|
|
|
3
3
|
/** Table DDL for the Postgres family, which alters each part of a column in a separate clause. */
|
|
4
4
|
export class PgTableDdl extends TableDdl {
|
|
5
5
|
/** A clause for each part that differs from `from`, the column as it was, or for every part without it. */
|
|
6
|
-
alterClauses(column,
|
|
6
|
+
alterClauses(column, from) {
|
|
7
7
|
const name = this.dialect.escapeId(column.name);
|
|
8
8
|
const alter = `ALTER COLUMN ${name}`;
|
|
9
9
|
return [
|
|
@@ -14,10 +14,26 @@ export class PgTableDdl extends TableDdl {
|
|
|
14
14
|
(column.defaultValue === undefined ? `${alter} DROP DEFAULT` : `${alter} SET${this.defaultClause(column)}`),
|
|
15
15
|
].filter((clause) => clause !== false);
|
|
16
16
|
}
|
|
17
|
+
/** `COMMENT ON`, a statement of its own for the table and for each column. */
|
|
18
|
+
commentStatements(table, comment, columns) {
|
|
19
|
+
const target = this.dialect.escapeId(table);
|
|
20
|
+
return [
|
|
21
|
+
...(comment ? [`COMMENT ON TABLE ${target} IS ${this.dialect.escape(comment)};`] : []),
|
|
22
|
+
...columns.flatMap((column) => column.comment
|
|
23
|
+
? [
|
|
24
|
+
`COMMENT ON COLUMN ${target}.${this.dialect.escapeId(column.name)} IS ${this.dialect.escape(column.comment)};`,
|
|
25
|
+
]
|
|
26
|
+
: []),
|
|
27
|
+
];
|
|
28
|
+
}
|
|
17
29
|
}
|
|
18
30
|
/** CockroachDB refuses a rewriting retype beside any other clause, and changes a schema online anyway. */
|
|
19
31
|
export class CockroachTableDdl extends PgTableDdl {
|
|
20
32
|
alterTable(table, clauses) {
|
|
21
33
|
return clauses.flatMap((clause) => super.alterTable(table, [clause]));
|
|
22
34
|
}
|
|
35
|
+
/** In one statement: a `schema_locked` table, its default, drops a key only beside the key replacing it. */
|
|
36
|
+
keyChange(table, drop, add) {
|
|
37
|
+
return drop && add ? [[], super.alterTable(table, [drop, add])] : super.keyChange(table, drop, add);
|
|
38
|
+
}
|
|
23
39
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { isVectorIndexType } from '../../type/vector.js';
|
|
2
2
|
import { UqlUsageError } from '../../util/uqlError.js';
|
|
3
3
|
import { IndexDdl } from './indexDdl.js';
|
|
4
4
|
/**
|
|
@@ -21,15 +21,10 @@ export class SqliteIndexDdl extends IndexDdl {
|
|
|
21
21
|
}
|
|
22
22
|
/** The metric libSQL's index names, or `undefined` where the index is no vector index or the engine has none. */
|
|
23
23
|
vectorIndexMetric(index) {
|
|
24
|
-
const { vectorMetrics, dialectName } = this.dialect;
|
|
25
24
|
if (!isVectorIndexType(index.type) || !this.dialect.hasVectorIndex()) {
|
|
26
25
|
return undefined;
|
|
27
26
|
}
|
|
28
|
-
const
|
|
29
|
-
const metric = vectorMetrics.get(distance)?.index;
|
|
30
|
-
if (!metric) {
|
|
31
|
-
throw unsupportedVectorMetric(dialectName, distance, index.name);
|
|
32
|
-
}
|
|
27
|
+
const metric = this.indexMetric(index);
|
|
33
28
|
// Its tables are named after the index, unquoted: any other name fails with "unable to initialize diskann".
|
|
34
29
|
if (!/^\w+$/.test(index.name) || index.entries.length !== 1) {
|
|
35
30
|
throw new UqlUsageError(`libSQL names a vector index only by letters, digits and underscores, over one column (index "${index.name}")`);
|