
- Set up project structure with FastAPI application - Implement SQLAlchemy models for users, services, projects, team members, contacts - Create API endpoints for website functionality - Implement JWT authentication system with user roles - Add file upload functionality for media - Configure CORS and health check endpoints - Add database migrations with Alembic - Create comprehensive README with setup instructions
49 lines
1.6 KiB
Python
49 lines
1.6 KiB
Python
import logging
|
|
|
|
|
|
from app import crud, schemas
|
|
from app.core.config import settings
|
|
from app.db.session import SessionLocal
|
|
|
|
logging.basicConfig(level=logging.INFO)
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
def init_db() -> None:
|
|
"""
|
|
Initialize the database with a superuser if needed.
|
|
"""
|
|
db = SessionLocal()
|
|
try:
|
|
# Check if admin email and password are set
|
|
if settings.ADMIN_EMAIL and settings.ADMIN_PASSWORD:
|
|
# Check if superuser exists
|
|
user = crud.user.get_by_email(db, email=settings.ADMIN_EMAIL)
|
|
if not user:
|
|
user_in = schemas.UserCreate(
|
|
email=settings.ADMIN_EMAIL,
|
|
password=settings.ADMIN_PASSWORD,
|
|
full_name="Admin",
|
|
is_superuser=True,
|
|
)
|
|
user = crud.user.create(db, obj_in=user_in)
|
|
logger.info(f"Admin user created with email: {settings.ADMIN_EMAIL}")
|
|
else:
|
|
logger.info(f"Admin user already exists with email: {settings.ADMIN_EMAIL}")
|
|
else:
|
|
logger.warning(
|
|
"Admin user not created. "
|
|
"Set ADMIN_EMAIL and ADMIN_PASSWORD environment variables."
|
|
)
|
|
|
|
# Initialize settings if they don't exist
|
|
settings_obj = crud.settings.get_settings(db)
|
|
logger.info(f"Settings initialized with site name: {settings_obj.site_name}")
|
|
finally:
|
|
db.close()
|
|
|
|
|
|
if __name__ == "__main__":
|
|
logger.info("Creating initial data")
|
|
init_db()
|
|
logger.info("Initial data created") |