seed-test-user.js 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. /**
  2. * 创建测试用户脚本
  3. * 运行: node prisma/seed-test-user.js
  4. */
  5. const { PrismaClient } = require('@prisma/client');
  6. const prisma = new PrismaClient();
  7. async function main() {
  8. console.log('🚀 开始创建测试用户...');
  9. // 检查是否已存在测试用户
  10. const existingUser = await prisma.user.findFirst({
  11. where: {
  12. OR: [
  13. { phone: 'test' },
  14. { id: 1 },
  15. ],
  16. },
  17. });
  18. if (existingUser) {
  19. console.log('✅ 测试用户已存在:', existingUser);
  20. // 更新为超级VIP
  21. const updated = await prisma.user.update({
  22. where: { id: existingUser.id },
  23. data: {
  24. phone: '13812341234',
  25. nickname: '测试超级用户',
  26. memberLevel: 99, // 超级VIP
  27. memberExpireAt: new Date('2099-12-31'), // 永久有效
  28. },
  29. });
  30. console.log('✅ 已更新为超级VIP:', updated);
  31. } else {
  32. // 创建新用户
  33. const user = await prisma.user.create({
  34. data: {
  35. id: 1,
  36. phone: '13812341234',
  37. nickname: '测试超级用户',
  38. avatar: '',
  39. memberLevel: 99, // 超级VIP
  40. memberExpireAt: new Date('2099-12-31'), // 永久有效
  41. dailyUsage: 0,
  42. lastUsageDate: '',
  43. },
  44. });
  45. console.log('✅ 测试用户创建成功:', user);
  46. }
  47. // 创建用户偏好
  48. const preference = await prisma.userPreference.upsert({
  49. where: { userId: 1 },
  50. update: {},
  51. create: {
  52. userId: 1,
  53. playSpeed: 1.0,
  54. quality: 'high',
  55. theme: 'light',
  56. },
  57. });
  58. console.log('✅ 用户偏好创建成功:', preference);
  59. console.log('\n🎉 测试用户设置完成!');
  60. console.log(' 用户ID: 1');
  61. console.log(' 手机号: test');
  62. console.log(' 会员等级: 99 (超级VIP)');
  63. console.log(' 有效期: 永久');
  64. }
  65. main()
  66. .catch((e) => {
  67. console.error('❌ 创建失败:', e);
  68. process.exit(1);
  69. })
  70. .finally(async () => {
  71. await prisma.$disconnect();
  72. });