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
+14
View File
@@ -3,6 +3,7 @@ import { Database } from "bun:sqlite";
import _ from "lodash";
import DbClient from ".";
import { AppData } from "../../data/app-data";
import { readLiveSchema } from "../../functions/live-schema";
// Schema Manager Class
class SQLiteSchemaManager {
db;
@@ -60,8 +61,21 @@ class SQLiteSchemaManager {
* Drop tables that are no longer in the schema
*/
async dropRemovedTables(existingTables, schemaTables) {
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}"`);