/** * 创建测试用户脚本 * 运行: node prisma/seed-test-user.js */ const { PrismaClient } = require('@prisma/client'); const prisma = new PrismaClient(); async function main() { console.log('🚀 开始创建测试用户...'); // 检查是否已存在测试用户 const existingUser = await prisma.user.findFirst({ where: { OR: [ { phone: 'test' }, { id: 1 }, ], }, }); if (existingUser) { console.log('✅ 测试用户已存在:', existingUser); // 更新为超级VIP const updated = await prisma.user.update({ where: { id: existingUser.id }, data: { phone: '13812341234', nickname: '测试超级用户', memberLevel: 99, // 超级VIP memberExpireAt: new Date('2099-12-31'), // 永久有效 }, }); console.log('✅ 已更新为超级VIP:', updated); } else { // 创建新用户 const user = await prisma.user.create({ data: { id: 1, phone: '13812341234', nickname: '测试超级用户', avatar: '', memberLevel: 99, // 超级VIP memberExpireAt: new Date('2099-12-31'), // 永久有效 dailyUsage: 0, lastUsageDate: '', }, }); console.log('✅ 测试用户创建成功:', user); } // 创建用户偏好 const preference = await prisma.userPreference.upsert({ where: { userId: 1 }, update: {}, create: { userId: 1, playSpeed: 1.0, quality: 'high', theme: 'light', }, }); console.log('✅ 用户偏好创建成功:', preference); console.log('\n🎉 测试用户设置完成!'); console.log(' 用户ID: 1'); console.log(' 手机号: test'); console.log(' 会员等级: 99 (超级VIP)'); console.log(' 有效期: 永久'); } main() .catch((e) => { console.error('❌ 创建失败:', e); process.exit(1); }) .finally(async () => { await prisma.$disconnect(); });