""" Seed a fresh dev database with a usable set of users. Pre-prod data is fake; after the JSONB→relational cutover the schema is built from the SQLAlchemy models on startup (Base.metadata.create_all). This script inserts a handful of approved users so the app is exercisable without going through Supabase sign-up for every role. NOTE: these users have RANDOM uuids (not real Supabase identities). They're for backend smoke tests / local poking. Real users are provisioned just-in-time on their first authenticated request (auth.py), keyed on their Supabase auth.uid(). Usage (from backend/, with env loaded): python scripts/seed_dev.py python scripts/seed_dev.py --wipe # delete existing seed rows first """ import argparse import asyncio import sys import uuid from datetime import UTC, datetime from pathlib import Path BACKEND_ROOT = Path(__file__).resolve().parent.parent if str(BACKEND_ROOT) not in sys.path: sys.path.insert(0, str(BACKEND_ROOT)) from sqlalchemy import delete, select from app.database import close_db, connect_db, get_session from app.models import User SEED_USERS = [ {"email": "admin@accujuris.dev", "name": "Dev Admin", "role": "admin"}, { "email": "translator@accujuris.dev", "name": "Dev Translator", "role": "translator", }, { "email": "legal@accujuris.dev", "name": "Dev Legal Expert", "role": "legal_expert", }, {"email": "submitter@accujuris.dev", "name": "Dev Submitter", "role": "submitter"}, ] async def _run(wipe: bool) -> int: await connect_db() try: async with get_session() as session: if wipe: emails = [u["email"] for u in SEED_USERS] await session.execute(delete(User).where(User.email.in_(emails))) for spec in SEED_USERS: existing = ( await session.execute( select(User).where(User.email == spec["email"]) ) ).scalar_one_or_none() if existing: print(f" exists: {spec['email']} ({existing.role})") continue uid = uuid.uuid4() session.add( User( id=uid, supabase_uid=str(uid), email=spec["email"], name=spec["name"], role=spec["role"], is_approved=True, is_permanent=(spec["role"] != "submitter"), free_submissions_left=2, created_at=datetime.now(UTC), ) ) print(f" seeded: {spec['email']} ({spec['role']}) id={uid}") print("Seed complete.") return 0 finally: await close_db() def main() -> None: parser = argparse.ArgumentParser(description="Seed dev users.") parser.add_argument( "--wipe", action="store_true", help="delete existing seed rows first" ) args = parser.parse_args() sys.exit(asyncio.run(_run(args.wipe))) if __name__ == "__main__": main()