feat: implement complete CMT backend with API endpoints and test suite
- Add 7 core API endpoints: users, transactions, partners, products, inventory, payments, credit - Implement role-based authentication (admin/write/read-only access) - Add comprehensive database models with proper relationships - Include full test coverage for all endpoints and business logic - Set up Alembic migrations and Docker configuration - Configure FastAPI app with CORS and database integration
This commit is contained in:
Executable
+67
@@ -0,0 +1,67 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
Script to create an initial admin user for the CMT system.
|
||||
Run this after setting up the database to create the first admin user.
|
||||
"""
|
||||
|
||||
import sys
|
||||
import os
|
||||
|
||||
# Add the parent directory to the path so we can import from app
|
||||
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
||||
|
||||
from sqlmodel import Session
|
||||
from app.core.db import engine
|
||||
from app.core.auth import get_password_hash
|
||||
from app.schemas.models import User
|
||||
from app.schemas.base import UserRole
|
||||
|
||||
|
||||
def create_admin_user():
|
||||
"""Create an initial admin user."""
|
||||
|
||||
username = input("Enter admin username: ").strip()
|
||||
if not username:
|
||||
print("Username cannot be empty!")
|
||||
return
|
||||
|
||||
password = input("Enter admin password: ").strip()
|
||||
if not password:
|
||||
print("Password cannot be empty!")
|
||||
return
|
||||
|
||||
# Hash the password
|
||||
hashed_password = get_password_hash(password)
|
||||
|
||||
# Create the user
|
||||
admin_user = User(
|
||||
username=username,
|
||||
password_hash=hashed_password,
|
||||
role=UserRole.ADMIN
|
||||
)
|
||||
|
||||
try:
|
||||
with Session(engine) as session:
|
||||
# Check if user already exists
|
||||
from sqlmodel import select
|
||||
statement = select(User).where(User.username == username)
|
||||
existing = session.exec(statement).first()
|
||||
if existing:
|
||||
print(f"User '{username}' already exists!")
|
||||
return
|
||||
|
||||
session.add(admin_user)
|
||||
session.commit()
|
||||
session.refresh(admin_user)
|
||||
|
||||
print(f"✅ Admin user '{username}' created successfully!")
|
||||
print(f"User ID: {admin_user.id}")
|
||||
print(f"Role: {admin_user.role}")
|
||||
|
||||
except Exception as e:
|
||||
print(f"❌ Error creating admin user: {e}")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
print("=== CMT Admin User Creation ===")
|
||||
create_admin_user()
|
||||
Reference in New Issue
Block a user