48 lines
1.3 KiB
JavaScript
48 lines
1.3 KiB
JavaScript
const { PrismaClient } = require('@prisma/client')
|
|
const { PrismaPg } = require('@prisma/adapter-pg')
|
|
const { Pool } = require('pg')
|
|
|
|
const connectionString = "postgresql://admin:secure_master_pass@localhost:5432/xflow_crm_db"
|
|
const pool = new Pool({ connectionString })
|
|
const adapter = new PrismaPg(pool)
|
|
const prisma = new PrismaClient({ adapter })
|
|
|
|
async function main() {
|
|
const admins = ["ormix16@gmail.com", "almalexyz@gmail.com"]
|
|
|
|
for (const email of admins) {
|
|
const username = email.split('@')[0]
|
|
console.log(`🔧 Setting prefix as username for: ${email}...`)
|
|
|
|
const user = await prisma.user.upsert({
|
|
where: { email },
|
|
update: {
|
|
username: username,
|
|
role: 'admin'
|
|
},
|
|
create: {
|
|
id: `admin-init-${Math.random().toString(36).slice(2, 7)}`,
|
|
email: email,
|
|
username: username,
|
|
password: 'managed-auth',
|
|
role: 'admin',
|
|
profile: {
|
|
create: {
|
|
displayName: username,
|
|
avatar: `https://api.dicebear.com/7.x/avataaars/svg?seed=${username}`
|
|
}
|
|
}
|
|
}
|
|
})
|
|
|
|
console.log(`✅ ${email} updated. URL will be: /profile/${user.username}`)
|
|
}
|
|
}
|
|
|
|
main()
|
|
.catch(console.error)
|
|
.finally(async () => {
|
|
await prisma.$disconnect()
|
|
await pool.end()
|
|
})
|