From 544baffba2f48e92ba1003f60e9ed404fa4071b0 Mon Sep 17 00:00:00 2001 From: Kirill Date: Wed, 7 Oct 2026 14:18:47 +0300 Subject: [PATCH] feat(db): Added DB --- db/InitDB.py | 30 ++++++++++++++++++++++++++++++ db/__init__.py | 0 2 files changed, 30 insertions(+) create mode 100644 db/InitDB.py create mode 100644 db/__init__.py 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