
- Set up project structure with FastAPI and SQLAlchemy - Create Todo model, schemas, and CRUD operations - Add API endpoints for todo operations (create, read, update, delete) - Set up Alembic for database migrations - Add health check endpoint - Update README with detailed instructions generated with BackendIM... (backend.im)
22 lines
591 B
Python
22 lines
591 B
Python
from sqlalchemy import create_engine
|
|
from sqlalchemy.ext.declarative import declarative_base
|
|
from sqlalchemy.orm import sessionmaker
|
|
from pathlib import Path
|
|
|
|
DB_DIR = Path("/app") / "storage" / "db"
|
|
DB_DIR.mkdir(parents=True, exist_ok=True)
|
|
|
|
SQLALCHEMY_DATABASE_URL = f"sqlite:///{DB_DIR}/db.sqlite"
|
|
|
|
engine = create_engine(
|
|
SQLALCHEMY_DATABASE_URL,
|
|
connect_args={"check_same_thread": False}
|
|
)
|
|
|
|
SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine)
|
|
|
|
Base = declarative_base()
|
|
|
|
def init_db():
|
|
from app import models
|
|
Base.metadata.create_all(bind=engine) |