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

@ -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<void> {
try {
console.log("🔄 Starting feed category migration...");