diff --git a/backend/services/identity-service/prisma/seed.ts b/backend/services/identity-service/prisma/seed.ts index 79819311..517ec033 100644 --- a/backend/services/identity-service/prisma/seed.ts +++ b/backend/services/identity-service/prisma/seed.ts @@ -49,6 +49,13 @@ const SYSTEM_ACCOUNTS = [ referralCode: 'POOL0004', status: 'SYSTEM', }, + { + userId: BigInt(5), + accountSequence: 'S0000000005', // GENESIS种子用户 + nickname: 'GENESIS种子用户', + referralCode: 'GENESIS', + status: 'SYSTEM', + }, ]; async function main() { @@ -114,7 +121,7 @@ async function main() { console.log('Database seeded successfully!'); console.log(`- Initialized account sequence generator for date ${dateKey}`); - console.log(`- Created ${SYSTEM_ACCOUNTS.length} system accounts (S0000000001-S0000000004)`); + console.log(`- Created ${SYSTEM_ACCOUNTS.length} system accounts (S0000000001-S0000000005)`); console.log(`- Created ${ADMIN_ACCOUNTS.length} admin accounts`); } diff --git a/backend/services/referral-service/package.json b/backend/services/referral-service/package.json index fd769f33..9f3a10f2 100644 --- a/backend/services/referral-service/package.json +++ b/backend/services/referral-service/package.json @@ -26,7 +26,8 @@ "prisma:generate": "prisma generate", "prisma:migrate": "prisma migrate dev", "prisma:migrate:prod": "prisma migrate deploy", - "prisma:studio": "prisma studio" + "prisma:studio": "prisma studio", + "prisma:seed": "ts-node prisma/seed.ts" }, "dependencies": { "@nestjs/axios": "^3.0.0", diff --git a/backend/services/referral-service/prisma/seed.ts b/backend/services/referral-service/prisma/seed.ts new file mode 100644 index 00000000..af8387e5 --- /dev/null +++ b/backend/services/referral-service/prisma/seed.ts @@ -0,0 +1,67 @@ +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(); + });