provozni zaloha

This commit is contained in:
lachtan
2026-06-24 08:11:12 +02:00
parent 9295dba19f
commit 1db3ec4756
97 changed files with 7698 additions and 817 deletions

View File

@@ -49,6 +49,7 @@ CREATE TABLE IF NOT EXISTS schedule_random (
days_filter TEXT,
from_date TEXT,
until_date TEXT,
period TEXT NOT NULL DEFAULT 'day' CHECK(period IN ('day', 'week')),
CHECK(window_start < window_end)
);
@@ -79,9 +80,21 @@ def get_db(path: Path) -> sqlite3.Connection:
conn.execute("PRAGMA journal_mode = WAL")
conn.execute("PRAGMA foreign_keys = ON")
conn.row_factory = sqlite3.Row
_migrate(conn)
return conn
def _migrate(conn: sqlite3.Connection) -> None:
"""Idempotently bring an existing DB up to the current schema.
init_db only runs on a missing file, so live DBs never see schema additions.
Each step is guarded to be a no-op once applied.
"""
columns = {row["name"] for row in conn.execute("PRAGMA table_info(schedule_random)")}
if columns and "period" not in columns:
conn.execute("ALTER TABLE schedule_random ADD COLUMN period TEXT NOT NULL DEFAULT 'day'")
def init_db(path: Path) -> None:
"""Create tables and indexes if they don't exist."""
path.parent.mkdir(parents=True, exist_ok=True)