Files
AIclinicalresearch/backend/prisma/seed.ts
HaHafeng 5579ffa78e feat(backend): add batch processing and review tasks modules
- Add Prisma migrations for batch processing tables
- Add Prisma migrations for review tasks tables
- Add seed data for testing
- Add prompt templates for review (editorial, methodology)
- Add CloseAI configuration guide
- Add database validation scripts
2025-11-16 15:43:04 +08:00

110 lines
2.1 KiB
TypeScript

/**
* 数据库种子数据脚本
* 用于初始化开发环境的测试用户
*/
import { PrismaClient } from '@prisma/client';
const prisma = new PrismaClient();
async function main() {
console.log('🌱 开始初始化数据库种子数据...');
// 创建测试用户
const mockUser = await prisma.user.upsert({
where: { id: 'user-mock-001' },
update: {},
create: {
id: 'user-mock-001',
email: 'test@example.com',
password: '$2b$12$LQv3c1yqBWVHxkd0LHAkCOYz6TtxMQJqhN8/LewY5GyYIkYvKx7ES', // password: "password123"
name: '测试用户',
role: 'user',
status: 'active',
kbQuota: 3,
kbUsed: 0,
isTrial: true,
trialEndsAt: new Date(Date.now() + 30 * 24 * 60 * 60 * 1000), // 30天后
},
});
console.log('✅ 测试用户创建成功:', {
id: mockUser.id,
email: mockUser.email,
name: mockUser.name,
});
// 可选:创建管理员用户
const adminUser = await prisma.user.upsert({
where: { email: 'admin@example.com' },
update: {},
create: {
id: 'user-admin-001',
email: 'admin@example.com',
password: '$2b$12$LQv3c1yqBWVHxkd0LHAkCOYz6TtxMQJqhN8/LewY5GyYIkYvKx7ES', // password: "password123"
name: '管理员',
role: 'admin',
status: 'active',
kbQuota: 10,
kbUsed: 0,
isTrial: false,
},
});
console.log('✅ 管理员用户创建成功:', {
id: adminUser.id,
email: adminUser.email,
name: adminUser.name,
});
console.log('\n🎉 数据库种子数据初始化完成!\n');
console.log('📝 测试账号信息:');
console.log(' 邮箱: test@example.com');
console.log(' 密码: password123');
console.log(' 用户ID: user-mock-001\n');
console.log('📝 管理员账号信息:');
console.log(' 邮箱: admin@example.com');
console.log(' 密码: password123');
console.log(' 用户ID: user-admin-001\n');
}
main()
.catch((e) => {
console.error('❌ 初始化种子数据失败:', e);
process.exit(1);
})
.finally(async () => {
await prisma.$disconnect();
});