This commit is contained in:
2025-06-08 18:32:42 +09:00
parent 5255ced0a0
commit dc01ac4380
2 changed files with 37 additions and 4 deletions

View File

@ -86,6 +86,31 @@ class BatchScheduler {
try { try {
console.log("🔄 Running scheduled batch process..."); 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); await batchProcess(this.currentAbortController.signal);
console.log("✅ Scheduled batch process completed"); console.log("✅ Scheduled batch process completed");
} catch (error) { } catch (error) {

View File

@ -107,7 +107,7 @@ function extractDomain(url: string): string | null {
} }
// Initialize database with proper error handling // Initialize database with proper error handling
async function initializeDatabase(): Database { function initializeDatabase(): Database {
// Ensure data directory exists // Ensure data directory exists
if (!fs.existsSync(config.paths.dataDir)) { if (!fs.existsSync(config.paths.dataDir)) {
fs.mkdirSync(config.paths.dataDir, { recursive: true }); fs.mkdirSync(config.paths.dataDir, { recursive: true });
@ -205,12 +205,20 @@ async function initializeDatabase(): Database {
// Perform database integrity checks and fixes // Perform database integrity checks and fixes
performDatabaseIntegrityFixes(db); 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; return db;
} }
const db = await initializeDatabase(); const db = initializeDatabase();
export interface Feed { export interface Feed {
id: string; id: string;
@ -1126,7 +1134,7 @@ export async function updateFeedRequestStatus(
} }
// Migration function to classify existing feeds without categories // Migration function to classify existing feeds without categories
export async function migrateFeedsWithCategories(db: Database): void { export async function migrateFeedsWithCategories(): Promise<void> {
try { try {
console.log("🔄 Starting feed category migration..."); console.log("🔄 Starting feed category migration...");