import { PrismaClient } from '@prisma/client' const prisma = new PrismaClient() async function main() { console.log('🌱 开始初始化数据库...') // 创建示例用户 const user = await prisma.user.upsert({ where: { email: 'admin@promptforge.com' }, update: {}, create: { email: 'admin@promptforge.com', name: 'PromptForge Admin', avatar: 'https://avatars.githubusercontent.com/u/1234567?v=4', }, }) console.log('✅ 创建用户:', user.email) // 创建示例模板 const templates = [ { title: 'API设计文档生成器', description: '生成完整的API设计文档,包含端点、参数、响应格式等', category: 'programming', tags: JSON.stringify(['api', 'documentation', 'backend']), role: '你是一位资深软件架构师,拥有丰富的API设计经验。', task: '我的任务是生成一个关于{{topic}}的API设计文档。', context: '这个API将用于{{useCase}}场景,需要支持{{features}}功能。', constraints: JSON.stringify([ { id: '1', text: '使用RESTful设计原则', category: 'quality' }, { id: '2', text: '包含完整的错误处理', category: 'safety' }, { id: '3', text: '提供OpenAPI 3.0规范', category: 'format' }, ]), outputFormat: 'markdown', variables: JSON.stringify([ { name: 'topic', type: 'text', required: true, description: 'API主题' }, { name: 'useCase', type: 'text', required: true, description: '使用场景' }, { name: 'features', type: 'text', required: false, description: '核心功能' }, ]), examples: JSON.stringify([ { input: { topic: '用户管理', useCase: '电商平台', features: '注册、登录、信息修改' }, output: '# 用户管理 API 设计文档\n\n## 概述\n用户管理API提供完整的用户账户管理功能...' } ]), authorId: user.id, isPublic: true, isFeatured: true, usageCount: 156, rating: 4.8, ratingCount: 23, }, { title: '营销文案优化器', description: '优化营销文案,提升转化率和用户 engagement', category: 'marketing', tags: JSON.stringify(['marketing', 'copywriting', 'conversion']), role: '你是一位经验丰富的营销文案专家,擅长AIDA模型和情感营销。', task: '请优化以下营销文案,使其更具吸引力和转化力:{{originalCopy}}', context: '目标受众是{{targetAudience}},产品是{{product}},主要卖点是{{valueProposition}}。', constraints: JSON.stringify([ { id: '1', text: '保持品牌调性一致', category: 'quality' }, { id: '2', text: '包含明确的行动号召', category: 'format' }, { id: '3', text: '字数控制在{{wordLimit}}字以内', category: 'performance' }, ]), outputFormat: 'plain-text', variables: JSON.stringify([ { name: 'originalCopy', type: 'text', required: true, description: '原始文案' }, { name: 'targetAudience', type: 'text', required: true, description: '目标受众' }, { name: 'product', type: 'text', required: true, description: '产品名称' }, { name: 'valueProposition', type: 'text', required: true, description: '价值主张' }, { name: 'wordLimit', type: 'number', required: false, defaultValue: 200, description: '字数限制' }, ]), examples: JSON.stringify([ { input: { originalCopy: '我们的产品很好用', targetAudience: '年轻白领', product: '智能办公助手', valueProposition: '提升工作效率50%' }, output: '🚀 告别加班!智能办公助手让年轻白领工作效率提升50%,每天节省2小时,享受生活!立即体验 →' } ]), authorId: user.id, isPublic: true, isFeatured: true, usageCount: 89, rating: 4.6, ratingCount: 15, }, { title: '技术文档翻译器', description: '将技术文档翻译成多种语言,保持专业性和准确性', category: 'translation', tags: JSON.stringify(['translation', 'technical', 'documentation']), role: '你是一位专业的技术文档翻译专家,精通多种语言和技术术语。', task: '请将以下技术文档翻译成{{targetLanguage}}:{{originalText}}', context: '这是一份{{documentType}}文档,目标读者是{{audienceLevel}}。', constraints: JSON.stringify([ { id: '1', text: '保持技术术语的准确性', category: 'quality' }, { id: '2', text: '使用{{targetLanguage}}的专业表达', category: 'style' }, { id: '3', text: '保持原文的格式结构', category: 'format' }, ]), outputFormat: 'markdown', variables: JSON.stringify([ { name: 'originalText', type: 'text', required: true, description: '原文内容' }, { name: 'targetLanguage', type: 'select', required: true, description: '目标语言', options: ['英语', '日语', '韩语', '法语', '德语', '西班牙语'] }, { name: 'documentType', type: 'text', required: true, description: '文档类型' }, { name: 'audienceLevel', type: 'select', required: true, description: '读者水平', options: ['初学者', '中级', '高级', '专家'] }, ]), examples: JSON.stringify([ { input: { originalText: 'API 接口返回 JSON 格式数据', targetLanguage: '英语', documentType: 'API文档', audienceLevel: '中级' }, output: 'The API endpoint returns data in JSON format' } ]), authorId: user.id, isPublic: true, isFeatured: false, usageCount: 67, rating: 4.7, ratingCount: 12, } ] for (const templateData of templates) { const template = await prisma.template.upsert({ where: { title: templateData.title }, update: {}, create: templateData, }) console.log('✅ 创建模板:', template.title) } // 创建系统配置 const configs = [ { key: 'site_name', value: 'PromptForge', type: 'string' }, { key: 'site_description', value: '专为大模型提示词系统优化的平台', type: 'string' }, { key: 'max_templates_per_user', value: '100', type: 'number' }, { key: 'enable_registration', value: 'true', type: 'boolean' }, ] for (const config of configs) { await prisma.systemConfig.upsert({ where: { key: config.key }, update: {}, create: config, }) console.log('✅ 创建配置:', config.key) } console.log('🎉 数据库初始化完成!') } main() .catch((e) => { console.error('❌ 数据库初始化失败:', e) process.exit(1) }) .finally(async () => { await prisma.$disconnect() })