seed-test-user.js 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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. nickname: '测试超级用户',
  25. memberLevel: 99, // 超级VIP
  26. memberExpireAt: new Date('2099-12-31'), // 永久有效
  27. },
  28. });
  29. console.log('✅ 已更新为超级VIP:', updated);
  30. } else {
  31. // 创建新用户
  32. const user = await prisma.user.create({
  33. data: {
  34. id: 1,
  35. phone: 'test',
  36. nickname: '测试超级用户',
  37. avatar: '',
  38. memberLevel: 99, // 超级VIP
  39. memberExpireAt: new Date('2099-12-31'), // 永久有效
  40. dailyUsage: 0,
  41. lastUsageDate: '',
  42. },
  43. });
  44. console.log('✅ 测试用户创建成功:', user);
  45. }
  46. // 创建用户偏好
  47. const preference = await prisma.userPreference.upsert({
  48. where: { userId: 1 },
  49. update: {},
  50. create: {
  51. userId: 1,
  52. playSpeed: 1.0,
  53. quality: 'high',
  54. theme: 'light',
  55. },
  56. });
  57. console.log('✅ 用户偏好创建成功:', preference);
  58. console.log('\n🎉 测试用户设置完成!');
  59. console.log(' 用户ID: 1');
  60. console.log(' 手机号: test');
  61. console.log(' 会员等级: 99 (超级VIP)');
  62. console.log(' 有效期: 永久');
  63. }
  64. main()
  65. .catch((e) => {
  66. console.error('❌ 创建失败:', e);
  67. process.exit(1);
  68. })
  69. .finally(async () => {
  70. await prisma.$disconnect();
  71. });