import { PrismaClient } from '@prisma/client' import { PrismaPg } from '@prisma/adapter-pg' import { Pool } from 'pg' import { config } from 'dotenv' config() // Load .env file const pool = new Pool({ connectionString: process.env.DATABASE_URL }) const adapter = new PrismaPg(pool) const prisma = new PrismaClient({ adapter }) async function createAdminUser(email: string, displayName: string) { console.log(`Creating admin user: ${email}`) // Create or update the user const user = await prisma.user.upsert({ where: { email }, update: { displayName, isActive: true, }, create: { email, displayName, isActive: true, }, }) console.log(`āœ… User created/updated: ${user.id}`) // Find the Admin role const adminRole = await prisma.role.findUnique({ where: { name: 'Admin' }, }) if (!adminRole) { console.error('āŒ Admin role not found. Run seed first: npx prisma db seed') process.exit(1) } // Assign Admin role to user await prisma.userRole.upsert({ where: { userId_roleId: { userId: user.id, roleId: adminRole.id, }, }, update: {}, create: { userId: user.id, roleId: adminRole.id, }, }) console.log(`āœ… Admin role assigned to ${email}`) console.log('\nšŸŽ‰ Admin user setup complete!') console.log(` Email: ${email}`) console.log(` User ID: ${user.id}`) } const email = process.argv[2] || 'lorentz@wulfconsulting.com' const displayName = process.argv[3] || 'Lorentz' createAdminUser(email, displayName) .catch((e) => { console.error('āŒ Failed:', e) process.exit(1) }) .finally(async () => { await prisma.$disconnect() await pool.end() })