31 lines
713 B
Python
31 lines
713 B
Python
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()}")
|