Automated Action 1d54b4ec09 Implement user authentication service with FastAPI
- Set up project structure and dependencies
- Create SQLAlchemy database models
- Set up Alembic for database migrations
- Implement user registration and login endpoints
- Add JWT token authentication
- Create middleware for protected routes
- Add health check endpoint
- Update README with documentation

generated with BackendIM... (backend.im)
2025-05-13 16:59:17 +00:00

31 lines
734 B
Python

from sqlalchemy import create_engine
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import sessionmaker
from pathlib import Path
# Create database directory
DB_DIR = Path("/app") / "storage" / "db"
DB_DIR.mkdir(parents=True, exist_ok=True)
# Database URL
SQLALCHEMY_DATABASE_URL = f"sqlite:///{DB_DIR}/db.sqlite"
# Create SQLAlchemy engine
engine = create_engine(
SQLALCHEMY_DATABASE_URL,
connect_args={"check_same_thread": False}
)
# Create SessionLocal class
SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine)
# Create Base class
Base = declarative_base()
# Dependency
def get_db():
db = SessionLocal()
try:
yield db
finally:
db.close()