chore: mqsrv backend
This commit is contained in:
90
prisma/seed.ts
Normal file
90
prisma/seed.ts
Normal file
@@ -0,0 +1,90 @@
|
||||
import { PrismaClient } from '@prisma/client';
|
||||
import crypto from 'crypto';
|
||||
|
||||
const prisma = new PrismaClient();
|
||||
|
||||
/**
|
||||
* 生成 VIP 卡密
|
||||
*/
|
||||
function generateCardKey(days: number): string {
|
||||
const prefix = `VIP${days}`;
|
||||
const segments = [];
|
||||
for (let i = 0; i < 4; i++) {
|
||||
segments.push(crypto.randomBytes(2).toString('hex').toUpperCase());
|
||||
}
|
||||
return `${prefix}-${segments.join('-')}`;
|
||||
}
|
||||
|
||||
async function main() {
|
||||
console.log('🌱 开始种子数据初始化...');
|
||||
|
||||
// ============================================
|
||||
// 创建分类
|
||||
// ============================================
|
||||
const categories = [
|
||||
// 烽火地带
|
||||
{ name: '突击步枪', type: 'SCHEME' },
|
||||
{ name: '冲锋枪', type: 'SCHEME' },
|
||||
{ name: '狙击步枪', type: 'SCHEME' },
|
||||
{ name: '轻机枪', type: 'SCHEME' },
|
||||
{ name: '霰弹枪', type: 'SCHEME' },
|
||||
{ name: '手枪', type: 'SCHEME' },
|
||||
|
||||
// 全面战场
|
||||
{ name: '突击步枪', type: 'SCHEME_AOB' },
|
||||
{ name: '冲锋枪', type: 'SCHEME_AOB' },
|
||||
{ name: '狙击步枪', type: 'SCHEME_AOB' },
|
||||
{ name: '轻机枪', type: 'SCHEME_AOB' },
|
||||
{ name: '霰弹枪', type: 'SCHEME_AOB' },
|
||||
|
||||
// 滤镜
|
||||
{ name: '烽火地带', type: 'FILTER' },
|
||||
{ name: '全面战场', type: 'FILTER' },
|
||||
{ name: '通用', type: 'FILTER' },
|
||||
];
|
||||
|
||||
for (const cat of categories) {
|
||||
await prisma.category.create({
|
||||
data: cat,
|
||||
}).catch(() => {}); // 忽略重复错误
|
||||
}
|
||||
console.log(`✅ 创建 ${categories.length} 个分类`);
|
||||
|
||||
// ============================================
|
||||
// 生成 VIP 卡密
|
||||
// ============================================
|
||||
const cardConfigs = [
|
||||
{ type: 'MONTH', days: 30, count: 100 },
|
||||
{ type: 'QUARTER', days: 90, count: 50 },
|
||||
{ type: 'YEAR', days: 365, count: 20 },
|
||||
];
|
||||
|
||||
let totalCards = 0;
|
||||
for (const config of cardConfigs) {
|
||||
const cards = [];
|
||||
for (let i = 0; i < config.count; i++) {
|
||||
cards.push({
|
||||
cardKey: generateCardKey(config.days),
|
||||
cardType: config.type,
|
||||
days: config.days,
|
||||
});
|
||||
}
|
||||
|
||||
await prisma.vipCard.createMany({ data: cards, skipDuplicates: true });
|
||||
totalCards += config.count;
|
||||
console.log(`✅ 生成 ${config.type} 卡密 ${config.count} 张`);
|
||||
}
|
||||
|
||||
console.log(`\n🎉 种子数据初始化完成!`);
|
||||
console.log(` - 分类:${categories.length} 个`);
|
||||
console.log(` - VIP 卡密:${totalCards} 张`);
|
||||
}
|
||||
|
||||
main()
|
||||
.catch((e) => {
|
||||
console.error('❌ 种子数据初始化失败:', e);
|
||||
process.exit(1);
|
||||
})
|
||||
.finally(async () => {
|
||||
await prisma.$disconnect();
|
||||
});
|
||||
Reference in New Issue
Block a user