-- Restore original schema, retaining only the current insight per file.
CREATE TABLE photo_insights_old (
    id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
    file_path TEXT NOT NULL UNIQUE,
    title TEXT NOT NULL,
    summary TEXT NOT NULL,
    generated_at BIGINT NOT NULL,
    model_version TEXT NOT NULL
);

INSERT INTO photo_insights_old (id, file_path, title, summary, generated_at, model_version)
    SELECT id, file_path, title, summary, generated_at, model_version
    FROM photo_insights
    WHERE is_current = 1;

DROP TABLE photo_insights;
ALTER TABLE photo_insights_old RENAME TO photo_insights;

CREATE INDEX IF NOT EXISTS idx_photo_insights_path ON photo_insights(file_path);
