import { PrismaClient, ProjectStatus, LinkType } from '@prisma/client' const prisma = new PrismaClient() async function main() { console.log('Starting seed...') // 创建标签 const tags = await Promise.all([ prisma.tag.upsert({ where: { slug: 'code-assistant' }, update: {}, create: { name: '代码助手', nameEn: 'Code Assistant', slug: 'code-assistant' } }), prisma.tag.upsert({ where: { slug: 'image-generation' }, update: {}, create: { name: '图像生成', nameEn: 'Image Generation', slug: 'image-generation' } }), prisma.tag.upsert({ where: { slug: 'data-analysis' }, update: {}, create: { name: '数据分析', nameEn: 'Data Analysis', slug: 'data-analysis' } }), prisma.tag.upsert({ where: { slug: 'chatbot' }, update: {}, create: { name: '对话AI', nameEn: 'Chatbot', slug: 'chatbot' } }), prisma.tag.upsert({ where: { slug: 'automation' }, update: {}, create: { name: '自动化', nameEn: 'Automation', slug: 'automation' } }) ]) console.log(`Created ${tags.length} tags`) // 创建项目 const projects = [ { name: 'Claude', nameEn: 'Claude', slug: 'claude', description: 'Anthropic 开发的 AI 助手,擅长分析、写作和编程任务。', descriptionEn: 'AI assistant by Anthropic, excels at analysis, writing, and coding.', content: 'Claude 是由 Anthropic 开发的下一代 AI 助手。它基于 Constitutional AI 方法训练,强调安全性、诚实性和有用性。', contentEn: 'Claude is a next-generation AI assistant developed by Anthropic. Trained using Constitutional AI methods.', tagSlugs: ['code-assistant', 'chatbot'], links: [ { type: LinkType.WEBSITE, url: 'https://www.anthropic.com/claude', title: 'Official Website' }, { type: LinkType.GITHUB, url: 'https://github.com/anthropics', title: 'GitHub' } ] }, { name: 'ChatGPT', nameEn: 'ChatGPT', slug: 'chatgpt', description: 'OpenAI 开发的大型语言模型,支持对话、写作、编程等多种任务。', descriptionEn: 'Large language model by OpenAI, supports conversation, writing, coding, etc.', tagSlugs: ['chatbot', 'code-assistant'], links: [ { type: LinkType.WEBSITE, url: 'https://chat.openai.com', title: 'Official Website' }, { type: LinkType.GITHUB, url: 'https://github.com/openai', title: 'GitHub' } ] }, { name: 'Midjourney', nameEn: 'Midjourney', slug: 'midjourney', description: '强大的 AI 图像生成工具,通过文字描述创建精美图像。', descriptionEn: 'Powerful AI image generation tool that creates stunning images from text descriptions.', tagSlugs: ['image-generation'], links: [ { type: LinkType.WEBSITE, url: 'https://www.midjourney.com', title: 'Official Website' } ] }, { name: 'Stable Diffusion', nameEn: 'Stable Diffusion', slug: 'stable-diffusion', description: '开源的图像生成模型,支持本地部署和自定义训练。', descriptionEn: 'Open-source image generation model, supports local deployment and custom training.', tagSlugs: ['image-generation'], links: [ { type: LinkType.WEBSITE, url: 'https://stability.ai', title: 'Official Website' }, { type: LinkType.GITHUB, url: 'https://github.com/Stability-AI', title: 'GitHub' } ] }, { name: 'n8n', nameEn: 'n8n', slug: 'n8n', description: '开源的工作流自动化工具,通过可视化界面连接各种服务和 API。', descriptionEn: 'Open-source workflow automation tool that connects various services and APIs via visual interface.', tagSlugs: ['automation'], links: [ { type: LinkType.WEBSITE, url: 'https://n8n.io', title: 'Official Website' }, { type: LinkType.GITHUB, url: 'https://github.com/n8n-io/n8n', title: 'GitHub' } ] } ] for (const projectData of projects) { const { tagSlugs, links, ...rest } = projectData const projectTags = tags.filter(t => tagSlugs.includes(t.slug)) const project = await prisma.project.upsert({ where: { slug: rest.slug }, update: {}, create: { ...rest, status: ProjectStatus.ACTIVE, source: 'manual', links: { create: links } } }) // Create ProjectTag connections manually since it's an explicit join table for (const tag of projectTags) { await prisma.projectTag.upsert({ where: { projectId_tagId: { projectId: project.id, tagId: tag.id } }, update: {}, create: { projectId: project.id, tagId: tag.id } }) } } console.log(`Created ${projects.length} projects`) console.log('Seed completed successfully!') } main() .catch((e) => { console.error('Error seeding database:', e) process.exit(1) }) .finally(async () => { await prisma.$disconnect() })