Remove table.isVector feature altogether. All vector features are handled per column
This commit is contained in:
Vendored
+3
-1
@@ -26,7 +26,9 @@ export default async function DbSQL({ sql, values }) {
|
||||
const singleRaw = res.single_res;
|
||||
return {
|
||||
...res,
|
||||
success: true,
|
||||
success: isSelect
|
||||
? Boolean(single_res) || Boolean(payload?.[0])
|
||||
: true,
|
||||
payload,
|
||||
single_res,
|
||||
debug: {
|
||||
|
||||
Vendored
+1
-1
@@ -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));
|
||||
}
|
||||
}
|
||||
|
||||
Vendored
+1
-2
@@ -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;
|
||||
|
||||
Vendored
+1
-44
@@ -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({
|
||||
|
||||
Vendored
-1
@@ -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: [
|
||||
|
||||
Vendored
-3
@@ -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;
|
||||
|
||||
Vendored
-2
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user