42 lines
1.2 KiB
JavaScript
42 lines
1.2 KiB
JavaScript
// 临时脚本:清空用户表用于测试首位用户权限功能
|
||
const { PrismaClient } = require('@prisma/client')
|
||
|
||
const prisma = new PrismaClient()
|
||
|
||
async function main() {
|
||
try {
|
||
console.log('正在检查用户数量...')
|
||
const userCount = await prisma.user.count()
|
||
console.log(`当前用户数量: ${userCount}`)
|
||
|
||
if (userCount === 0) {
|
||
console.log('✓ 用户表已经是空的,无需清空')
|
||
return
|
||
}
|
||
|
||
console.log('正在清空用户表...')
|
||
// 使用 deleteMany 而不是 TRUNCATE,因为 Prisma 不支持 TRUNCATE
|
||
// 注意:这会级联删除相关的 materials 和 material_likes 记录
|
||
const result = await prisma.user.deleteMany({})
|
||
console.log(`✓ 已删除 ${result.count} 个用户`)
|
||
|
||
// 验证
|
||
const newCount = await prisma.user.count()
|
||
console.log(`清空后用户数量: ${newCount}`)
|
||
|
||
if (newCount === 0) {
|
||
console.log('✓ 用户表已成功清空,可以开始测试首位用户注册功能')
|
||
} else {
|
||
console.log('⚠ 警告: 用户表清空后仍有数据,请检查')
|
||
}
|
||
} catch (error) {
|
||
console.error('错误:', error)
|
||
process.exit(1)
|
||
} finally {
|
||
await prisma.$disconnect()
|
||
}
|
||
}
|
||
|
||
main()
|
||
|