Remove table.isVector feature altogether. All vector features are handled per column
This commit is contained in:
@@ -30,7 +30,7 @@ export default async function createTable({
|
||||
primaryKeys.push(field.fieldName);
|
||||
}
|
||||
|
||||
if (field.foreignKey && !table.isVector) {
|
||||
if (field.foreignKey) {
|
||||
foreignKeys.push(
|
||||
buildForeignKeyConstraint(field, table.tableName),
|
||||
);
|
||||
|
||||
@@ -26,8 +26,7 @@ async function checkIfTableExists({
|
||||
}
|
||||
|
||||
/**
|
||||
* Full table rebuild. For `isVector` tables this drops and recreates in place
|
||||
* (preserving rows when possible). For regular tables it uses a temp-table swap.
|
||||
* Full table rebuild using a temp-table swap (preserving rows when possible).
|
||||
*/
|
||||
export default async function recreateTable({
|
||||
table,
|
||||
@@ -46,58 +45,6 @@ export default async function recreateTable({
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Vector tables: drop + recreate + reinsert (MariaDB VECTOR INDEX / dim
|
||||
* changes are not reliably alterable in place).
|
||||
*/
|
||||
if (table.isVector) {
|
||||
console.log(`Recreating vector table: ${table.tableName}`);
|
||||
|
||||
const existingRows = await querySchemaRows<Record<string, any>>({
|
||||
query: `SELECT * FROM ${MariaDBQuoteGen(table.tableName)}`,
|
||||
config,
|
||||
});
|
||||
|
||||
await runSchemaQuery({ query: `SET FOREIGN_KEY_CHECKS = 0`, config });
|
||||
try {
|
||||
await runSchemaQuery({
|
||||
query: `DROP TABLE IF EXISTS ${MariaDBQuoteGen(table.tableName)}`,
|
||||
config,
|
||||
});
|
||||
await createTable({ table, config });
|
||||
} finally {
|
||||
await runSchemaQuery({ query: `SET FOREIGN_KEY_CHECKS = 1`, config });
|
||||
}
|
||||
|
||||
if (existingRows.length > 0) {
|
||||
const schemaFieldNames = new Set(
|
||||
(table.fields || [])
|
||||
.map((f) => f.fieldName)
|
||||
.filter((n): n is string => Boolean(n)),
|
||||
);
|
||||
|
||||
for (const row of existingRows) {
|
||||
const columns = Object.keys(row).filter((c) =>
|
||||
schemaFieldNames.has(c),
|
||||
);
|
||||
if (columns.length === 0) continue;
|
||||
|
||||
const placeholders = columns.map(() => "?").join(", ");
|
||||
const columnList = columns
|
||||
.map((c) => MariaDBQuoteGen(c))
|
||||
.join(", ");
|
||||
|
||||
await runSchemaQuery({
|
||||
query: `INSERT INTO ${MariaDBQuoteGen(table.tableName)} (${columnList}) VALUES (${placeholders})`,
|
||||
values: columns.map((c) => row[c] ?? null),
|
||||
config,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
const tempTableName = `${table.tableName}_temp_${Date.now()}`;
|
||||
const backupOldTableName = `${table.tableName}_old_${Date.now()}`;
|
||||
const existingColumns = await getTableColumns({
|
||||
|
||||
@@ -41,8 +41,6 @@ export default function resolveTable(
|
||||
tableName: table.tableName,
|
||||
tableDescription: table.tableDescription || parentTable.tableDescription,
|
||||
collation: table.collation || parentTable.collation,
|
||||
isVector:
|
||||
table.isVector !== undefined ? table.isVector : parentTable.isVector,
|
||||
fields: Array.from(mergedFieldsMap.values()),
|
||||
indexes: _.uniqBy(
|
||||
[...(parentTable.indexes || []), ...(table.indexes || [])],
|
||||
|
||||
@@ -57,10 +57,6 @@ function rulesMatch(
|
||||
export function grabDesiredForeignKeys(
|
||||
table: BUN_MARIADB_TableSchemaType,
|
||||
): DesiredForeignKey[] {
|
||||
if (table.isVector) {
|
||||
return [];
|
||||
}
|
||||
|
||||
const desired: DesiredForeignKey[] = [];
|
||||
|
||||
for (const field of table.fields || []) {
|
||||
|
||||
@@ -14,7 +14,6 @@ function isVectorIndexDef(
|
||||
table: BUN_MARIADB_TableSchemaType,
|
||||
): boolean {
|
||||
if (index.indexType === "VECTOR") return true;
|
||||
if (table.isVector) return true;
|
||||
|
||||
const firstFieldName = index.indexTableFields?.[0];
|
||||
if (!firstFieldName) return false;
|
||||
@@ -97,8 +96,7 @@ async function createIndex({
|
||||
.map((field) => MariaDBQuoteGen(field))
|
||||
.join(", ");
|
||||
const typeUpper = index.indexType?.toUpperCase();
|
||||
const isSpecialType =
|
||||
typeUpper === "FULLTEXT" || typeUpper === "SPATIAL";
|
||||
const isSpecialType = typeUpper === "FULLTEXT" || typeUpper === "SPATIAL";
|
||||
const indexPrefix = isSpecialType ? `${typeUpper} ` : "";
|
||||
const indexSuffix =
|
||||
!isSpecialType && (typeUpper === "BTREE" || typeUpper === "HASH")
|
||||
@@ -199,11 +197,7 @@ export default async function syncIndexes({
|
||||
const columnsMatch =
|
||||
details.columns.length === schemaColumns.length &&
|
||||
details.columns.every((col, idx) => col === schemaColumns[idx]);
|
||||
const typeMatch = indexTypesMatch(
|
||||
details.type,
|
||||
schemaIndex,
|
||||
table,
|
||||
);
|
||||
const typeMatch = indexTypesMatch(details.type, schemaIndex, table);
|
||||
|
||||
if (!columnsMatch || !typeMatch) {
|
||||
console.log(`Recreating changed index: ${indexName}`);
|
||||
|
||||
Reference in New Issue
Block a user