-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdb.py
More file actions
36 lines (27 loc) · 926 Bytes
/
Copy pathdb.py
File metadata and controls
36 lines (27 loc) · 926 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
"""
Database configuration for SQLite (testing & development)
"""
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker
# Use SQLite for immediate testing - swap to PostgreSQL in production
DATABASE_URL = "sqlite:///./mijn_api_dev.db"
engine = create_engine(
DATABASE_URL,
connect_args={"check_same_thread": False}
)
SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine)
def get_db():
db = SessionLocal()
try:
yield db
finally:
db.close()
"""Create all tables (development only; use Alembic for production)."""
from models_phase1 import Base
Base.metadata.create_all(bind=engine)
logger.info("Database tables initialized")
def drop_db():
"""Drop all tables (dangerous! development only)."""
from models_phase1 import Base
Base.metadata.drop_all(bind=engine)
logger.warning("All database tables dropped")