Spaces:
Paused
Paused
Download scripts/seed.py from 3SCError404/nexus: direct link, hf CLI and curl.
- Browser
- Download file 4.53 kB
-
https://huggingface.co/spaces/3SCError404/nexus/resolve/main/scripts/seed.py
- Command line
-
hf download hf://spaces/3SCError404/nexus/scripts/seed.py
-
curl -L -o seed.py https://huggingface.co/spaces/3SCError404/nexus/resolve/main/scripts/seed.py
4.53 kB
| """ | |
| Comprehensive Seed Script for Foundation Phase. | |
| Sets up: | |
| - 2 Workspaces (Acme Corp, Globex) | |
| - 4 Users (Admin, User per workspace) | |
| - 1 3SC Agent (Expert) | |
| - 5+ Tickets with varied status/priority | |
| - 10+ Messages including internal notes | |
| """ | |
| import asyncio | |
| from core.database import async_session_factory, init_db | |
| from core.security import get_password_hash | |
| from models.workspace import Workspace | |
| from models.user import User, UserRole | |
| from models.ticket import Ticket, TicketStatus, TicketPriority | |
| from models.message import Message | |
| async def seed_data(): | |
| print("--- Starting Comprehensive Seed ---") | |
| await init_db() | |
| async with async_session_factory() as session: | |
| # 0. Clear existing data (optional, but good for clean seed) | |
| # For this script we assume a fresh DB or handled by lifespan | |
| password = get_password_hash("password123") | |
| # 1. Workspaces | |
| ws1 = Workspace(name="Acme Corp") | |
| ws2 = Workspace(name="Globex") | |
| session.add_all([ws1, ws2]) | |
| await session.flush() | |
| # 2. Users | |
| users_data = [ | |
| {"email": "admin@acme.com", "full_name": "Acme Admin", "role": UserRole.CUSTOMER_ADMIN, "ws_id": ws1.id}, | |
| {"email": "user@acme.com", "full_name": "Acme User", "role": UserRole.CUSTOMER_USER, "ws_id": ws1.id}, | |
| {"email": "admin@globex.com", "full_name": "Globex Admin", "role": UserRole.CUSTOMER_ADMIN, "ws_id": ws2.id}, | |
| {"email": "agent@3sc.com", "full_name": "Expert Agent", "role": UserRole.SC_AGENT, "ws_id": ws1.id}, | |
| ] | |
| from models.user_workspace import UserWorkspace | |
| users = [] | |
| for u_data in users_data: | |
| user = User( | |
| email=u_data["email"], | |
| hashed_password=password, | |
| full_name=u_data["full_name"] | |
| ) | |
| session.add(user) | |
| await session.flush() | |
| # Create Link | |
| link = UserWorkspace( | |
| user_id=user.id, | |
| workspace_id=u_data["ws_id"], | |
| role=u_data["role"], | |
| is_primary=True | |
| ) | |
| session.add(link) | |
| users.append(user) | |
| await session.flush() | |
| u_acme_admin, u_acme_user, _, u_agent = users | |
| # 3. Tickets for Acme Corp | |
| tickets = [ | |
| Ticket( | |
| title="Login issue on mobile", | |
| description="Cannot login using the iOS app.", | |
| priority=TicketPriority.P1, | |
| status=TicketStatus.OPEN, | |
| workspace_id=ws1.id, | |
| created_by=u_acme_user.id | |
| ), | |
| Ticket( | |
| title="Missing invoice #442", | |
| description="I haven't received my last invoice.", | |
| priority=TicketPriority.P2, | |
| status=TicketStatus.ACKNOWLEDGED, | |
| workspace_id=ws1.id, | |
| created_by=u_acme_admin.id, | |
| assigned_to=u_agent.id | |
| ), | |
| Ticket( | |
| title="API Timeout", | |
| description="Getting 504 on the gateway.", | |
| priority=TicketPriority.P0, | |
| status=TicketStatus.IN_PROGRESS, | |
| workspace_id=ws1.id, | |
| created_by=u_acme_user.id, | |
| assigned_to=u_agent.id | |
| ), | |
| Ticket( | |
| title="Password Reset Bug", | |
| description="Link expires too fast.", | |
| priority=TicketPriority.P3, | |
| status=TicketStatus.RESOLVED, | |
| workspace_id=ws1.id, | |
| created_by=u_acme_user.id | |
| ), | |
| ] | |
| session.add_all(tickets) | |
| await session.flush() | |
| # 4. Messages | |
| t_api = tickets[2] | |
| messages = [ | |
| Message(ticket_id=t_api.id, sender_id=u_acme_user.id, content="This is urgent, my production is down!"), | |
| Message(ticket_id=t_api.id, sender_id=u_agent.id, content="I am looking into the gateway logs now.", is_internal=False), | |
| Message(ticket_id=t_api.id, sender_id=u_agent.id, content="Internal: Suspecting a resource leak in the auth-svc.", is_internal=True), | |
| ] | |
| session.add_all(messages) | |
| await session.commit() | |
| print("--- Seed Successful ---") | |
| print(f"Acme Workspace: {ws1.id}") | |
| print(f"Globex Workspace: {ws2.id}") | |
| if __name__ == "__main__": | |
| asyncio.run(seed_data()) | |