add sqlmodel + alembic + setup models skeleton to slowly enable transition towards a db

This commit is contained in:
Viktor Barzin 2025-06-03 20:00:30 +00:00
parent 8c646a5322
commit 0d3393ed94
No known key found for this signature in database
GPG key ID: 4056458DBDBF8863
11 changed files with 697 additions and 1 deletions

14
crawler/database.py Normal file
View file

@ -0,0 +1,14 @@
from sqlmodel import create_engine, SQLModel
from sqlalchemy.orm import sessionmaker
# PostgreSQL example (or use "sqlite:///database.db" for SQLite)
# DATABASE_URL = "postgresql://user:password@localhost/db_name"
DATABASE_URL = "sqlite:///data/wrongmove.db"
engine = create_engine(DATABASE_URL, echo=True) # `echo=True` for debug logs
SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine)
def init_db():
"""Create all tables (only for development; use migrations in production)."""
SQLModel.metadata.create_all(engine)