Document typedefs better. Fix tables deletion schema sync issue.

This commit is contained in:
2026-04-05 09:03:47 +01:00
parent 01b96d788e
commit 259a684136
14 changed files with 869 additions and 104 deletions
+21
View File
@@ -9,6 +9,7 @@ import type {
BUN_SQLITE_TableSchemaType,
} from "../../types";
import { AppData } from "../../data/app-data";
import { readLiveSchema } from "../../functions/live-schema";
// Schema Manager Class
class SQLiteSchemaManager {
@@ -95,12 +96,32 @@ class SQLiteSchemaManager {
existingTables: string[],
schemaTables: string[],
): Promise<void> {
console.log(`Cleaning up tables ...`);
const tablesToDrop = existingTables.filter(
(t) =>
!schemaTables.includes(t) &&
!schemaTables.find((scT) => t.startsWith(scT + "_")),
);
const currentSchema = readLiveSchema();
if (currentSchema?.tables?.[0]) {
for (let i = 0; i < currentSchema.tables.length; i++) {
const table = currentSchema.tables[i];
if (!table?.tableName) continue;
const does_table_exist = schemaTables.find(
(t) => t == table.tableName,
);
if (!does_table_exist) {
tablesToDrop.push(table.tableName);
}
}
}
for (const tableName of tablesToDrop) {
console.log(`Dropping table: ${tableName}`);
this.db.run(`DROP TABLE IF EXISTS "${tableName}"`);