47 lines
1.1 KiB
TypeScript
47 lines
1.1 KiB
TypeScript
/**
|
|
* 平台管理员种子脚本
|
|
* 创建 SUPER_ADMIN 角色的平台管理员账号
|
|
*
|
|
* 用法: npx tsx prisma/seed-platform-admin.ts
|
|
*/
|
|
import { PrismaClient } from '@prisma/client'
|
|
import bcrypt from 'bcryptjs'
|
|
|
|
const prisma = new PrismaClient()
|
|
|
|
async function main() {
|
|
const phone = '13800000000'
|
|
const existing = await prisma.user.findUnique({ where: { phone } })
|
|
|
|
if (existing) {
|
|
console.log(`平台管理员已存在: ${phone},跳过创建`)
|
|
return
|
|
}
|
|
|
|
const passwordHash = await bcrypt.hash('admin123456', 10)
|
|
const admin = await prisma.user.create({
|
|
data: {
|
|
name: '平台超级管理员',
|
|
phone,
|
|
passwordHash,
|
|
role: 'SUPER_ADMIN',
|
|
orgId: null,
|
|
},
|
|
})
|
|
|
|
console.log('===== 平台管理员创建成功 =====')
|
|
console.log(`姓名: ${admin.name}`)
|
|
console.log(`手机号: ${admin.phone}`)
|
|
console.log(`密码: admin123456`)
|
|
console.log(`角色: SUPER_ADMIN`)
|
|
}
|
|
|
|
main()
|
|
.catch((e) => {
|
|
console.error(e)
|
|
process.exit(1)
|
|
})
|
|
.finally(async () => {
|
|
await prisma.$disconnect()
|
|
})
|