Update
This commit is contained in:
@ -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) {
|
||||||
|
@ -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...");
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user