Files
Avtex/scripts/init_admin.cjs
T

50 lines
1.3 KiB
JavaScript

const { PrismaClient } = require('@prisma/client')
const { PrismaPg } = require('@prisma/adapter-pg')
const { Pool } = require('pg')
// Создаем соединение через pg (как того требует Driver Adapter в Prisma 7)
const connectionString = process.env.DATABASE_URL
const pool = new Pool({ connectionString })
const adapter = new PrismaPg(pool)
const prisma = new PrismaClient({ adapter })
async function main() {
const userId = 'GqbpMyUW0NaxjIy5nvCiXCiQu9t2' // Твой UID из лога
console.log('🚀 Initializing admin using Driver Adapter for UID:', userId)
const user = await prisma.user.upsert({
where: { id: userId },
update: {
role: 'admin'
},
create: {
id: userId,
email: 'admin@xflow.kz',
username: 'alex_admin',
password: 'firebase_auth',
role: 'admin',
profile: {
create: {
displayName: 'Alex Admin',
bio: 'XFlow Infrastructure Creator',
joinedAt: new Date()
}
}
}
})
console.log('✅ Success! Admin user created/updated:', user.username)
}
main()
.catch((e) => {
console.error('❌ Error initializing admin:', e)
process.exit(1)
})
.finally(async () => {
await prisma.$disconnect()
await pool.end()
})