68 lines
1.9 KiB
TypeScript
68 lines
1.9 KiB
TypeScript
import { PrismaClient } from '@prisma/client';
|
||
|
||
const prisma = new PrismaClient();
|
||
|
||
// ============================================
|
||
// 系统种子用户
|
||
// 用于为未来的注册用户提供初始推荐码
|
||
// ============================================
|
||
const SEED_USER = {
|
||
userId: BigInt(5),
|
||
accountSequence: 'D25122100000', // 种子用户 (序号0,真实用户从1开始)
|
||
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();
|
||
});
|