Alchemical Hands in the Hypnerotomachia Poliphili

Marginalia, Scholarship & Reception

← All Scripts

Timeline Migration

migrate_timeline.py — 41 lines

Adds category, medium, location, image_ref, confidence columns to timeline_events table.

1"""Add new columns to timeline_events for the Timeline tab.
2
3Adds: category, medium, location, image_ref, confidence.
4Idempotent.
5"""
6
7import sqlite3
8from pathlib import Path
9
10BASE_DIR = Path(__file__).resolve().parent.parent
11DB_PATH = BASE_DIR / "db" / "hp.db"
12
13NEW_COLUMNS = [
14    ("category", "TEXT"),
15    ("medium", "TEXT"),
16    ("location", "TEXT"),
17    ("image_ref", "TEXT"),
18    ("confidence", "TEXT DEFAULT 'MEDIUM'"),
19]
20
21
22def main():
23    conn = sqlite3.connect(DB_PATH)
24    cur = conn.cursor()
25    cur.execute("PRAGMA table_info(timeline_events)")
26    existing = {r[1] for r in cur.fetchall()}
27
28    added = 0
29    for col, ctype in NEW_COLUMNS:
30        if col not in existing:
31            cur.execute(f"ALTER TABLE timeline_events ADD COLUMN {col} {ctype}")
32            print(f"  Added: {col}")
33            added += 1
34
35    conn.commit()
36    conn.close()
37    print(f"Done. Added {added} columns.")
38
39
40if __name__ == "__main__":
41    main()