Spaces:
Paused

yaz / scripts /setup /init_auth.py
anaselamr's picture
docs: Complete codebase organization - Sprint 36 major milestone
32469ef
Raw History Blame Contribute Delete
1.52 kB
"""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()