feat: Introduce is_deleted flag for items, add scripts for dummy data and thumbnail population, and refine item deletion and statistics.
This commit is contained in:
@@ -4,6 +4,22 @@ import { promises as fs } from "fs";
|
||||
|
||||
(async () => {
|
||||
console.log("Starting migration...");
|
||||
|
||||
// 1. Ensure column exists
|
||||
try {
|
||||
await db`select is_deleted from items limit 1`;
|
||||
console.log("Column 'is_deleted' already exists.");
|
||||
} catch (err) {
|
||||
if (err.message.includes('column "is_deleted" does not exist')) {
|
||||
console.log("Column 'is_deleted' missing. Adding it now...");
|
||||
await db`ALTER TABLE items ADD COLUMN is_deleted BOOLEAN DEFAULT FALSE`;
|
||||
console.log("Column added successfully.");
|
||||
} else {
|
||||
console.error("Unexpected error checking column:", err);
|
||||
process.exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
const items = await db`select id, dest from items where active = false`;
|
||||
console.log(`Found ${items.length} inactive items.`);
|
||||
|
||||
@@ -25,9 +41,9 @@ import { promises as fs } from "fs";
|
||||
pendingCount++;
|
||||
} catch {
|
||||
// Not in either? Broken.
|
||||
console.log(`Item ${item.id} (${item.dest}) missing from both locations.`);
|
||||
console.log(`Item ${item.id} (${item.dest}) missing from both locations. Deleting...`);
|
||||
await db`delete from items where id = ${item.id}`;
|
||||
brokenCount++;
|
||||
// Default is false, which effectively puts it in pending queue as 'broken'
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user