rwadurian/backend/services/referral-service/prisma/seed.ts

68 lines
1.9 KiB
TypeScript

import { PrismaClient } from '@prisma/client';
const prisma = new PrismaClient();
// ============================================
// 系统种子用户
// 用于为未来的注册用户提供初始推荐码
// ============================================
const SEED_USER = {
userId: BigInt(25129999999), // 从 accountSequence 去掉 D 前缀
accountSequence: 'D25129999999', // 种子用户 (特殊序号,区别于真实用户)
myReferralCode: 'SEED01',
usedReferralCode: null, // 根节点无推荐人
referrerId: null, // 根节点
rootUserId: null,
ancestorPath: [], // 空数组 = 根节点
depth: 0, // 深度 0 = 根节点
directReferralCount: 0,
activeDirectCount: 0,
};
async function main() {
console.log('Seeding referral-service database...');
// 创建种子用户推荐关系
await prisma.referralRelationship.upsert({
where: { userId: SEED_USER.userId },
update: SEED_USER,
create: SEED_USER,
});
console.log(' - Created seed user referral relationship (userId=5, code=SEED01)');
// 创建种子用户的团队统计
await prisma.teamStatistics.upsert({
where: { userId: SEED_USER.userId },
update: {},
create: {
userId: SEED_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 seed user team statistics');
console.log('Database seeded successfully!');
console.log('- Created 1 seed user (SEED01) for initial referrals');
}
main()
.catch((e) => {
console.error(e);
process.exit(1);
})
.finally(async () => {
await prisma.$disconnect();
});