Skip to content

Commit 6496d9a

Browse files
authored
fix #2: read DATABASE_URL from env variable instead of hardcoded pyscure.db
1 parent 2474681 commit 6496d9a

1 file changed

Lines changed: 8 additions & 3 deletions

File tree

backend/database.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,16 @@
22
from sqlalchemy.ext.declarative import declarative_base
33
from sqlalchemy.orm import sessionmaker
44
import datetime
5+
import os
56

6-
# SQLite for development, easy to switch to PostgreSQL later
7-
DATABASE_URL = "sqlite:///./pyscure.db"
7+
# Fix #2: Read DATABASE_URL from environment variable (set in docker-compose.yml)
8+
# Falls back to security_logs.db for local development
9+
DATABASE_URL = os.getenv("DATABASE_URL", "sqlite:///./security_logs.db")
810

9-
engine = create_engine(DATABASE_URL, connect_args={"check_same_thread": False})
11+
# SQLite requires check_same_thread=False; ignored safely for other DBs
12+
connect_args = {"check_same_thread": False} if DATABASE_URL.startswith("sqlite") else {}
13+
14+
engine = create_engine(DATABASE_URL, connect_args=connect_args)
1015
SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine)
1116

1217
Base = declarative_base()

0 commit comments

Comments
 (0)