Files
AIclinicalresearch/backend/prisma/seed.ts
HaHafeng e3e7e028e8 feat(platform): Complete platform infrastructure implementation and verification
Platform Infrastructure - 8 Core Modules Completed:
- Storage Service (LocalAdapter + OSSAdapter stub)
- Logging System (Winston + JSON format)
- Cache Service (MemoryCache + Redis stub)
- Async Job Queue (MemoryQueue + DatabaseQueue stub)
- Health Check Endpoints (liveness/readiness/detailed)
- Database Connection Pool (with Serverless optimization)
- Environment Configuration Management
- Monitoring Metrics (DB connections/memory/API)

Key Features:
- Adapter Pattern for zero-code environment switching
- Full backward compatibility with legacy modules
- 100% test coverage (all 8 modules verified)
- Complete documentation (11 docs updated)

Technical Improvements:
- Fixed duplicate /health route registration issue
- Fixed TypeScript interface export (export type)
- Installed winston dependency
- Added structured logging with context support
- Implemented graceful shutdown for Serverless
- Added connection pool optimization for SAE

Documentation Updates:
- Platform infrastructure planning (04-骞冲彴鍩虹璁炬柦瑙勫垝.md)
- Implementation report (2025-11-17-骞冲彴鍩虹璁炬柦瀹炴柦瀹屾垚鎶ュ憡.md)
- Verification report (2025-11-17-骞冲彴鍩虹璁炬柦楠岃瘉鎶ュ憡.md)
- Git commit guidelines (06-Git鎻愪氦瑙勮寖.md) - Added commit frequency rules
- Updated 3 core architecture documents

Code Statistics:
- New code: 2,532 lines
- New files: 22
- Updated files: 130+
- Test pass rate: 100% (8/8 modules)

Deployment Readiness:
- Local environment: 鉁?Ready
- Cloud environment: 馃攧 Needs OSS/Redis dependencies

Next Steps:
- Ready to start ASL module development
- Can directly use storage/logger/cache/jobQueue

Tested: Local verification 100% passed
Related: #Platform-Infrastructure
2025-11-18 08:00:41 +08:00

112 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();
});