
- Set up project structure with FastAPI and SQLite - Implement user authentication with JWT - Create database models for users, events, bets, and transactions - Add API endpoints for user management - Add API endpoints for events and betting functionality - Add wallet management for deposits and withdrawals - Configure Alembic for database migrations - Add linting with Ruff - Add documentation in README
30 lines
1.0 KiB
Python
30 lines
1.0 KiB
Python
import logging
|
|
|
|
from app.core.config import settings
|
|
from app.crud.user import create_user, get_user_by_email
|
|
from app.db.session import SessionLocal
|
|
from app.schemas.user import UserCreate
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
def init_db() -> None:
|
|
"""Initialize database with first superuser."""
|
|
db = SessionLocal()
|
|
try:
|
|
# Check if there's already a superuser
|
|
user = get_user_by_email(db, email=settings.FIRST_SUPERUSER_EMAIL)
|
|
if not user:
|
|
logger.info("Creating first superuser")
|
|
user_in = UserCreate(
|
|
email=settings.FIRST_SUPERUSER_EMAIL,
|
|
password=settings.FIRST_SUPERUSER_PASSWORD,
|
|
is_admin=True,
|
|
)
|
|
create_user(db, user=user_in)
|
|
logger.info(f"Superuser {settings.FIRST_SUPERUSER_EMAIL} created")
|
|
else:
|
|
logger.info(f"Superuser {settings.FIRST_SUPERUSER_EMAIL} already exists")
|
|
except Exception as e:
|
|
logger.error(f"Error creating superuser: {e}")
|
|
finally:
|
|
db.close() |