|
|
@@ -33,7 +33,7 @@ def _get_conn() -> sqlite3.Connection:
|
|
|
|
|
|
|
|
|
def _init_db_sync() -> None:
|
|
|
- """Synchronous database initialization."""
|
|
|
+ """Synchronous database initialization with non-destructive migrations."""
|
|
|
DB_PATH.parent.mkdir(parents=True, exist_ok=True)
|
|
|
conn = _get_conn()
|
|
|
conn.executescript("""
|
|
|
@@ -42,7 +42,6 @@ def _init_db_sync() -> None:
|
|
|
name TEXT NOT NULL,
|
|
|
nickname TEXT UNIQUE,
|
|
|
birth_datetime TEXT NOT NULL,
|
|
|
- birthplace TEXT,
|
|
|
latitude REAL NOT NULL,
|
|
|
longitude REAL NOT NULL,
|
|
|
elevation REAL DEFAULT 0.0,
|
|
|
@@ -52,6 +51,10 @@ def _init_db_sync() -> None:
|
|
|
CREATE INDEX IF NOT EXISTS idx_persons_nickname ON persons(nickname);
|
|
|
CREATE INDEX IF NOT EXISTS idx_persons_name ON persons(name);
|
|
|
""")
|
|
|
+ # Non-destructive migrations (ALTER TABLE ADD COLUMN)
|
|
|
+ cols = [row[1] for row in conn.execute("PRAGMA table_info(persons)")]
|
|
|
+ if "birthplace" not in cols:
|
|
|
+ conn.execute("ALTER TABLE persons ADD COLUMN birthplace TEXT")
|
|
|
conn.commit()
|
|
|
conn.close()
|
|
|
|