clear-db.js•1.44 kB
#!/usr/bin/env bun
import { Database } from 'bun:sqlite';
import path from 'path';
import os from 'os';
import fs from 'fs';
// Database file path - using the same path as the main application
const DB_DIR = process.env.DB_DIR || path.join(os.homedir(), '.mcp-rss-crawler');
const DB_FILE = process.env.DB_FILE || path.join(DB_DIR, 'feeds.db');
const logFile = path.join(process.cwd(), 'clear-db-log.txt');
const log = (message) => {
console.log(message);
fs.appendFileSync(logFile, message + '\n');
};
log(`Opening database at ${DB_FILE}`);
// Open the database
const db = new Database(DB_FILE);
// Begin transaction
db.transaction(() => {
// Clear the articles table
const articlesDeleted = db.prepare('DELETE FROM articles').run();
log(`Deleted ${articlesDeleted.changes} records from articles table`);
// Clear the items table (related to feeds)
const itemsDeleted = db.prepare('DELETE FROM items').run();
log(`Deleted ${itemsDeleted.changes} records from items table`);
// Clear the categories table (related to items)
const categoriesDeleted = db.prepare('DELETE FROM categories').run();
log(`Deleted ${categoriesDeleted.changes} records from categories table`);
// Clear the feeds table
const feedsDeleted = db.prepare('DELETE FROM feeds').run();
log(`Deleted ${feedsDeleted.changes} records from feeds table`);
})();
// Close the database
db.close();
log('Database cleared successfully');