Automated Action f207cc3c64 Create RESTful API service with FastAPI and SQLite
- Set up project structure with FastAPI and dependency files
- Configure SQLAlchemy with SQLite database
- Implement user authentication using JWT tokens
- Create comprehensive API routes for user management
- Add health check endpoint for application monitoring
- Set up Alembic for database migrations
- Add detailed documentation in README.md
2025-06-16 14:56:03 +00:00

27 lines
679 B
Python

from sqlalchemy.orm import Session
from app.core.security import get_password_hash
from app.models.user import User
def init_db(db: Session) -> None:
"""
Initialize the database with a superuser if one doesn't exist.
"""
# Check if there are any users in the database
user = db.query(User).first()
if not user:
# Create a superuser
superuser = User(
email="admin@example.com",
hashed_password=get_password_hash("adminpassword"),
full_name="Admin User",
is_active=True,
is_superuser=True,
)
db.add(superuser)
db.commit()
db.refresh(superuser)