import { PrismaClient } from '@prisma/client'; const prisma = new PrismaClient(); // ============================================ // GENESIS 系统种子用户 // 用于为未来的注册用户提供初始推荐码 // ============================================ const GENESIS_USER = { userId: BigInt(5), accountSequence: 'S0000000005', myReferralCode: 'GENESIS', usedReferralCode: null, // 根节点无推荐人 referrerId: null, // 根节点 rootUserId: null, ancestorPath: [], // 空数组 = 根节点 depth: 0, // 深度 0 = 根节点 directReferralCount: 0, activeDirectCount: 0, }; async function main() { console.log('Seeding referral-service database...'); // 创建 GENESIS 推荐关系 await prisma.referralRelationship.upsert({ where: { userId: GENESIS_USER.userId }, update: GENESIS_USER, create: GENESIS_USER, }); console.log(' - Created GENESIS referral relationship (userId=5, code=GENESIS)'); // 创建 GENESIS 的团队统计 await prisma.teamStatistics.upsert({ where: { userId: GENESIS_USER.userId }, update: {}, create: { userId: GENESIS_USER.userId, directReferralCount: 0, totalTeamCount: 0, selfPlantingCount: 0, selfPlantingAmount: 0, directPlantingCount: 0, totalTeamPlantingCount: 0, totalTeamPlantingAmount: 0, maxSingleTeamPlantingCount: 0, effectivePlantingCountForRanking: 0, ownProvinceTeamCount: 0, ownCityTeamCount: 0, provinceTeamPercentage: 0, cityTeamPercentage: 0, }, }); console.log(' - Created GENESIS team statistics'); console.log('Database seeded successfully!'); console.log('- Created 1 GENESIS seed user for initial referrals'); } main() .catch((e) => { console.error(e); process.exit(1); }) .finally(async () => { await prisma.$disconnect(); });