"""Create a test user for the dev environment if it doesn't exist yet.""" import asyncio from sqlalchemy import select from app.core.security import hash_password from app.database import AsyncSessionLocal from app.models.user import User TEST_EMAIL = "test@example.com" TEST_PASSWORD = "Test123!" TEST_NAME = "Test User" async def seed() -> None: async with AsyncSessionLocal() as db: result = await db.execute(select(User).where(User.email == TEST_EMAIL)) existing = result.scalar_one_or_none() if existing: # Ensure the dev test user is always an admin if not existing.is_superuser: existing.is_superuser = True await db.commit() print(f"[seed] promoted test user to admin: {TEST_EMAIL}") else: print(f"[seed] test user already exists: {TEST_EMAIL}") return user = User( email=TEST_EMAIL, hashed_password=hash_password(TEST_PASSWORD), full_name=TEST_NAME, is_superuser=True, ) db.add(user) await db.commit() print(f"[seed] created test admin — email: {TEST_EMAIL} pwd: {TEST_PASSWORD}") if __name__ == "__main__": asyncio.run(seed())