chore: baseline before agreements
This commit is contained in:
@@ -0,0 +1,3 @@
|
||||
# Database initialization
|
||||
# This file is now just a placeholder to avoid circular imports
|
||||
# The actual initialization is done in main.py
|
||||
@@ -0,0 +1,28 @@
|
||||
from sqlalchemy import create_engine
|
||||
from sqlalchemy.ext.declarative import declarative_base
|
||||
from sqlalchemy.orm import sessionmaker
|
||||
from pathlib import Path
|
||||
|
||||
# Keep SQLite anchored to the project, independent of the process working directory.
|
||||
DATABASE_PATH = Path(__file__).resolve().with_name("work_tracker.db")
|
||||
DATABASE_PATH.parent.mkdir(parents=True, exist_ok=True)
|
||||
|
||||
# SQLAlchemy accepts an absolute SQLite URL in this form on Windows and Unix.
|
||||
DATABASE_URL = f"sqlite:///{DATABASE_PATH.as_posix()}"
|
||||
|
||||
# Create engine
|
||||
engine = create_engine(DATABASE_URL, connect_args={"check_same_thread": False})
|
||||
|
||||
# Create session
|
||||
SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine)
|
||||
|
||||
# Base class for models
|
||||
Base = declarative_base()
|
||||
|
||||
# Dependency to get database session
|
||||
def get_db():
|
||||
db = SessionLocal()
|
||||
try:
|
||||
yield db
|
||||
finally:
|
||||
db.close()
|
||||
Reference in New Issue
Block a user