Remove table.isVector feature altogether. All vector features are handled per column

This commit is contained in:
2026-08-05 11:01:58 +01:00
parent 000d40b4cb
commit 4f203ce4e7
18 changed files with 17 additions and 136 deletions
+1 -1
View File
@@ -15,7 +15,7 @@ export default async function createTable({ table, config, }) {
if (field.primaryKey && field.fieldName) {
primaryKeys.push(field.fieldName);
}
if (field.foreignKey && !table.isVector) {
if (field.foreignKey) {
foreignKeys.push(buildForeignKeyConstraint(field, table.tableName));
}
}
+1 -2
View File
@@ -1,7 +1,6 @@
import type { BUN_MARIADB_TableSchemaType, BunMariaDBConfig } from "../../types";
/**
* 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 function recreateTable({ table, config, }: {
table: BUN_MARIADB_TableSchemaType;
+1 -44
View File
@@ -13,8 +13,7 @@ async function checkIfTableExists({ tableName, config, }) {
return Boolean(rows[0]?.table_exists);
}
/**
* 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, config, }) {
const doesTableExist = await checkIfTableExists({
@@ -25,48 +24,6 @@ export default async function recreateTable({ table, config, }) {
await createTable({ table, config });
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({
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) => 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({
-1
View File
@@ -23,7 +23,6 @@ export default function resolveTable(table, db_schema) {
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 || [])], "indexName"),
uniqueConstraints: [
-3
View File
@@ -15,9 +15,6 @@ function rulesMatch(live, desired) {
ruleIsCascade(live.updateRule) === desired.cascadeUpdate);
}
export function grabDesiredForeignKeys(table) {
if (table.isVector) {
return [];
}
const desired = [];
for (const field of table.fields || []) {
const fk = field.foreignKey;
-2
View File
@@ -6,8 +6,6 @@ import { grabDesiredUniqueConstraints } from "./sync-unique-constraints";
function isVectorIndexDef(index, table) {
if (index.indexType === "VECTOR")
return true;
if (table.isVector)
return true;
const firstFieldName = index.indexTableFields?.[0];
if (!firstFieldName)
return false;