
- Setup project structure with FastAPI application - Create database models with SQLAlchemy - Configure Alembic for database migrations - Implement CRUD operations for products, categories, suppliers - Add inventory transaction functionality - Implement user authentication with JWT - Add health check endpoint - Create comprehensive documentation
50 lines
1.4 KiB
Python
50 lines
1.4 KiB
Python
import logging
|
|
from app.db.session import SessionLocal
|
|
from app.db.base import Base
|
|
from app.db.session import engine
|
|
from app.crud import user
|
|
from app.schemas.user import UserCreate
|
|
import os
|
|
|
|
logging.basicConfig(level=logging.INFO)
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
def init_db() -> None:
|
|
db = SessionLocal()
|
|
try:
|
|
# Create tables if they don't exist
|
|
Base.metadata.create_all(bind=engine)
|
|
|
|
# Check if we already have users
|
|
user_obj = user.get_by_email(db, email="admin@example.com")
|
|
if not user_obj:
|
|
user_in = UserCreate(
|
|
email="admin@example.com",
|
|
username="admin",
|
|
password=os.environ.get("ADMIN_PASSWORD", "admin"),
|
|
full_name="System Administrator",
|
|
is_active=True,
|
|
)
|
|
user_obj = user.create(db, obj_in=user_in)
|
|
logger.info(f"Created initial admin user: {user_obj.email}")
|
|
|
|
# Make the admin a superuser
|
|
user_obj.is_superuser = True
|
|
db.add(user_obj)
|
|
db.commit()
|
|
logger.info(f"Made {user_obj.email} a superuser")
|
|
else:
|
|
logger.info(f"Admin user {user_obj.email} already exists")
|
|
finally:
|
|
db.close()
|
|
|
|
|
|
def main() -> None:
|
|
logger.info("Creating initial data")
|
|
init_db()
|
|
logger.info("Initial data created")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main() |