- New demo_requests table (SQLAlchemy model + Alembic-ready) - Public POST /api/demo-requests endpoint for the TapTrack website form - Super-admin GET/PUT/DELETE endpoints to manage leads - DemoRequestsPage.vue with stats row, filterable table, status updates, notes modal - Sidebar nav item and route registered
40 lines
1.5 KiB
Python
40 lines
1.5 KiB
Python
"""Seed the database with a default super admin account."""
|
|
import asyncio
|
|
import os
|
|
import sys
|
|
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
|
|
|
|
from sqlalchemy.ext.asyncio import create_async_engine, async_sessionmaker
|
|
from sqlalchemy import select
|
|
from app.database import Base
|
|
# Import all models so Base.metadata has the complete schema
|
|
from app.models import user, school, license, sms, billing, ticket, audit, announcement, email_log, report, demo_request # noqa
|
|
from app.models.user import HubUser, UserRole
|
|
from app.auth.password import hash_password
|
|
|
|
DATABASE_URL = os.getenv("DATABASE_URL", "postgresql+asyncpg://postgres:postgres@db:5432/taptrack_hub")
|
|
|
|
async def seed():
|
|
engine = create_async_engine(DATABASE_URL)
|
|
async with engine.begin() as conn:
|
|
await conn.run_sync(Base.metadata.create_all)
|
|
session_factory = async_sessionmaker(engine, expire_on_commit=False)
|
|
async with session_factory() as db:
|
|
existing = (await db.execute(select(HubUser).where(HubUser.role == UserRole.super_admin))).scalar_one_or_none()
|
|
if existing:
|
|
print(f"Super admin already exists: {existing.email}")
|
|
return
|
|
admin = HubUser(
|
|
email="admin@taptrack.io",
|
|
full_name="TapTrack Admin",
|
|
hashed_password=hash_password("admin123!"),
|
|
role=UserRole.super_admin,
|
|
)
|
|
db.add(admin)
|
|
await db.commit()
|
|
print(f"Created super admin: admin@taptrack.io / admin123!")
|
|
await engine.dispose()
|
|
|
|
if __name__ == "__main__":
|
|
asyncio.run(seed())
|