diff --git a/src/main/java/auctiora/DatabaseService.java b/src/main/java/auctiora/DatabaseService.java index d36d9f9..4dc32a6 100644 --- a/src/main/java/auctiora/DatabaseService.java +++ b/src/main/java/auctiora/DatabaseService.java @@ -252,8 +252,40 @@ public class DatabaseService { // Table might not exist yet, which is fine log.debug("Could not check lots table schema: " + e.getMessage()); } + + // Check images table for missing columns and migrate + try (var rs = stmt.executeQuery("PRAGMA table_info(images)")) { + var hasLabels = false; + var hasLocalPath = false; + var hasProcessedAt = false; + + while (rs.next()) { + var colName = rs.getString("name"); + switch (colName) { + case "labels" -> hasLabels = true; + case "local_path" -> hasLocalPath = true; + case "processed_at" -> hasProcessedAt = true; + } + } + + if (!hasLabels) { + log.info("Migrating schema: Adding 'labels' column to images table"); + stmt.execute("ALTER TABLE images ADD COLUMN labels TEXT"); + } + if (!hasLocalPath) { + log.info("Migrating schema: Adding 'local_path' column to images table"); + stmt.execute("ALTER TABLE images ADD COLUMN local_path TEXT"); + } + if (!hasProcessedAt) { + log.info("Migrating schema: Adding 'processed_at' column to images table"); + stmt.execute("ALTER TABLE images ADD COLUMN processed_at INTEGER"); + } + } catch (SQLException e) { + // Table might not exist yet, which is fine + log.debug("Could not check images table schema: " + e.getMessage()); + } } - + /** * Inserts or updates an auction record (typically called by external scraper) */