Automated Action aae9527254 Set up user authentication flow with FastAPI and SQLite
- Created user model with SQLAlchemy ORM
- Implemented authentication with JWT tokens (access and refresh tokens)
- Added password hashing with bcrypt
- Created API endpoints for registration, login, and user management
- Set up Alembic for database migrations
- Added health check endpoint
- Created role-based access control (standard users and superusers)
- Added comprehensive documentation
2025-06-10 15:58:57 +00:00

20 lines
653 B
Python

from sqlalchemy.orm import Session
from app.crud.user import create_user, get_user_by_email
from app.schemas.user import UserCreate
def init_db(db: Session) -> None:
"""Initialize the database with seed data if needed"""
# Create a superuser if no users exist
user = get_user_by_email(db, email="admin@example.com")
if not user:
user_in = UserCreate(
email="admin@example.com",
username="admin",
password="admin123", # This should be a secure password in production
full_name="Administrator",
is_superuser=True
)
create_user(db, obj_in=user_in)