Spaces:
Running

microfunnel-api / backend /scripts /create_superuser.py
axeronis
feat: standardize tariff names (unlimited to enterprise)
e55469f
Raw History Blame Contribute Delete
1.88 kB
import asyncio
import sys
import os
# Add parent dir to path
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
from sqlmodel import select
from app.core.database import async_session_maker
from app.models.user import User, UserRole
from app.models.tenant import Tenant
from app.core.security import get_password_hash
async def create_superuser():
email = "axeroni.s2@gmail.com"
password = "admin" # Default password
print(f"Creating superuser: {email}")
async with async_session_maker() as session:
# Check if user exists
statement = select(User).where(User.email == email)
result = await session.execute(statement)
user = result.first()
if user:
print(f"User {email} already exists.")
return
# Create Tenant
print("Creating default tenant...")
tenant = Tenant(
name="Admin Tenant",
business_name="MicroFunnel Admin",
subscription_plan="enterprise"
)
session.add(tenant)
await session.commit()
await session.refresh(tenant)
# Create User
print("Creating user...")
user = User(
email=email,
hashed_password=get_password_hash(password),
full_name="Super Admin",
tenant_id=tenant.id,
role=UserRole.OWNER,
is_active=True,
is_superuser=True,
is_verified=True
)
session.add(user)
await session.commit()
print(f"Superuser created successfully!")
print(f"Email: {email}")
print(f"Password: {password}")
if __name__ == "__main__":
if sys.platform == 'win32':
asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy())
asyncio.run(create_superuser())