"""Initialize authentication database tables and default roles.""" import sys import asyncio from pathlib import Path # Add project root to path PROJECT_ROOT = Path(__file__).resolve().parent.parent sys.path.insert(0, str(PROJECT_ROOT)) from sqlmodel import SQLModel, create_engine from apps.auth.models import AuthUser, Role, Permission, UserRole from apps.auth.models.role import RolePermission from apps.auth.models.session import Session, PasswordResetToken def init_auth_database(): """Initialize authentication tables.""" # Create SQLite engine DATABASE_URL = "sqlite:///./yaz_care.db" engine = create_engine(DATABASE_URL, echo=False) # Create all tables SQLModel.metadata.create_all(engine) print("āœ… Authentication tables created successfully") # Initialize default roles and permissions from sqlmodel import Session as DBSession from apps.auth.services.rbac_service import RBACService with DBSession(engine) as session: rbac_service = RBACService(session) rbac_service.initialize_default_roles_and_permissions() print("āœ… Default roles and permissions initialized") # List created roles roles = rbac_service.list_roles() print(f"\nšŸ“‹ Created {len(roles)} roles:") for role in roles: perms = rbac_service.get_role_permissions(role.id) print(f" - {role.name}: {len(perms)} permissions") if __name__ == "__main__": init_auth_database()