diff --git a/db/InitDB.py b/db/InitDB.py new file mode 100644 index 0000000..799c78d --- /dev/null +++ b/db/InitDB.py @@ -0,0 +1,30 @@ +import os +import sqlite3 +from pathlib import Path + +PROJECT_ROOT = Path(__file__).resolve().parent.parent + +DB_PATH = Path(os.environ.get("DB_PATH") or PROJECT_ROOT / "backend.db") + +SCHEMA = """ +CREATE TABLE IF NOT EXISTS requests ( + id TEXT PRIMARY KEY, + text TEXT NOT NULL, + file TEXT NOT NULL DEFAULT '[]', + status TEXT NOT NULL DEFAULT 'WAITING', + worker INTEGER NOT NULL DEFAULT 0, + result TEXT DEFAULT NULL +); +""" + + +def init_db() -> Path: + DB_PATH.parent.mkdir(parents=True, exist_ok=True) + with sqlite3.connect(DB_PATH) as conn: + conn.executescript(SCHEMA) + conn.commit() + return DB_PATH + + +if __name__ == "__main__": + print(f"DB initialized: {init_db()}") diff --git a/db/__init__.py b/db/__init__.py new file mode 100644 index 0000000..e69de29