Spaces:
3SCError404
/
Paused

File size: 2,253 Bytes
5eb4857
 
 
 
 
 
 
 
 
4405ca9
5eb4857
 
 
 
 
 
 
 
 
 
 
4405ca9
5eb4857
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4405ca9
5eb4857
4405ca9
5eb4857
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
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())