From dc01ac43806f8bede2509955f85a5865150299c9 Mon Sep 17 00:00:00 2001 From: Satsuki Akiba Date: Sun, 8 Jun 2025 18:32:42 +0900 Subject: [PATCH] Update --- services/batch-scheduler.ts | 25 +++++++++++++++++++++++++ services/database.ts | 16 ++++++++++++---- 2 files changed, 37 insertions(+), 4 deletions(-) diff --git a/services/batch-scheduler.ts b/services/batch-scheduler.ts index edbdac8..0275198 100644 --- a/services/batch-scheduler.ts +++ b/services/batch-scheduler.ts @@ -86,6 +86,31 @@ class BatchScheduler { try { console.log("🔄 Running scheduled batch process..."); + // Run migration for feeds without categories (only once) + if (!this.migrationCompleted) { + try { + const { migrateFeedsWithCategories, getFeedCategoryMigrationStatus } = + await import("./database.js"); + const migrationStatus = await getFeedCategoryMigrationStatus(); + + if (!migrationStatus.migrationComplete) { + console.log("🔄 Running feed category migration..."); + await migrateFeedsWithCategories(); + this.migrationCompleted = true; + } else { + console.log("✅ Feed category migration already complete"); + this.migrationCompleted = true; + } + } catch (migrationError) { + console.error( + "❌ Error during feed category migration:", + migrationError, + ); + // Don't fail the entire batch process due to migration error + this.migrationCompleted = true; // Mark as completed to avoid retrying every batch + } + } + await batchProcess(this.currentAbortController.signal); console.log("✅ Scheduled batch process completed"); } catch (error) { diff --git a/services/database.ts b/services/database.ts index 54e03c0..ad1c9da 100644 --- a/services/database.ts +++ b/services/database.ts @@ -107,7 +107,7 @@ function extractDomain(url: string): string | null { } // Initialize database with proper error handling -async function initializeDatabase(): Database { +function initializeDatabase(): Database { // Ensure data directory exists if (!fs.existsSync(config.paths.dataDir)) { fs.mkdirSync(config.paths.dataDir, { recursive: true }); @@ -205,12 +205,20 @@ async function initializeDatabase(): Database { // Perform database integrity checks and fixes performDatabaseIntegrityFixes(db); - await migrateFeedsWithCategories(db); + // ALTER + // ALTER TABLE feeds ADD COLUMN category TEXT DEFAULT NULL; + // Ensure the category column exists + const infos = db.prepare("PRAGMA table_info(feeds);").all(); + const hasCategory = infos.some((col: any) => col.name === "category"); + + if (!hasCategory) { + db.exec("ALTER TABLE feeds ADD COLUMN category TEXT DEFAULT NULL;"); + } return db; } -const db = await initializeDatabase(); +const db = initializeDatabase(); export interface Feed { id: string; @@ -1126,7 +1134,7 @@ export async function updateFeedRequestStatus( } // Migration function to classify existing feeds without categories -export async function migrateFeedsWithCategories(db: Database): void { +export async function migrateFeedsWithCategories(): Promise { try { console.log("🔄 Starting feed category migration...");