Spaces:
Paused
Paused
Download scripts/seed_cloud_data.py from 3SCError404/nexus: direct link, hf CLI and curl.
- Browser
- Download file 2.25 kB
-
https://huggingface.co/spaces/3SCError404/nexus/resolve/main/scripts/seed_cloud_data.py
- Command line
-
hf download hf://spaces/3SCError404/nexus/scripts/seed_cloud_data.py
-
curl -L -o seed_cloud_data.py https://huggingface.co/spaces/3SCError404/nexus/resolve/main/scripts/seed_cloud_data.py
2.25 kB
| import asyncio | |
| import sys | |
| import os | |
| from sqlalchemy import select | |
| # Add project root to path | |
| sys.path.append(os.getcwd()) | |
| from core.config import get_settings | |
| from core.database import async_session_factory | |
| from core.security import get_password_hash | |
| from models.workspace import Workspace | |
| from models.user import User, UserRole | |
| async def seed_cloud_data(): | |
| """ | |
| Seeds initial data into a database after Alembic migrations have run. | |
| 1. Creates 'Snowball HQ' default workspace. | |
| 2. Creates 'Nexus Admin' administrator account. | |
| """ | |
| settings = get_settings() | |
| print("\n--- NEXUS: CLOUD DATA SEEDING ---") | |
| print(f"Target: {settings.async_database_url.split('@')[-1]}") | |
| async with async_session_factory() as session: | |
| # Check if workspace exists | |
| result = await session.execute(select(Workspace).limit(1)) | |
| existing_workspace = result.scalars().first() | |
| if not existing_workspace: | |
| print("[1/2] Creating 'Snowball HQ' default workspace...") | |
| new_ws = Workspace( | |
| name="Snowball HQ", | |
| branding={"primary": "#1E40AF", "logo": "/logo.png"} | |
| ) | |
| session.add(new_ws) | |
| await session.flush() # Get the ID | |
| # Create Admin User | |
| print("[2/2] Creating 'Nexus Admin' credentials...") | |
| admin_user = User( | |
| workspace_id=new_ws.id, | |
| email="admin@nexus.ai", | |
| full_name="Nexus System Admin", | |
| role=UserRole.SC_ADMIN, | |
| hashed_password=get_password_hash("NexusAdmin2024!"), # Default - should be changed | |
| is_active=True | |
| ) | |
| session.add(admin_user) | |
| await session.commit() | |
| print("\n✅ Seeding COMPLETE.") | |
| print(f"✅ Initial Workspace ID: {new_ws.id}") | |
| print("✅ Admin Account created: admin@nexus.ai") | |
| else: | |
| print("Skipping seed: Workspace already exists.") | |
| print("\n--- NEXT STEPS ---") | |
| print("1. Switch your .env to the Pooler URL (Port 6543).") | |
| print("2. Deploy your Docker image to Hugging Face Spaces.\n") | |
| if __name__ == "__main__": | |
| asyncio.run(seed_cloud_data()) | |