second commit

This commit is contained in:
2025-09-06 08:28:47 +08:00
parent eed68bbd8c
commit 1efcef6e10
86 changed files with 27153 additions and 0 deletions

123
prisma/schema.prisma Normal file
View File

@@ -0,0 +1,123 @@
// This is your Prisma schema file,
// learn more about it in the docs: https://pris.ly/d/prisma-schema
generator client {
provider = "prisma-client-js"
}
datasource db {
provider = "mysql"
url = env("DATABASE_URL")
}
// 用户表
model User {
id String @id @default(cuid())
email String @unique
name String?
avatar String?
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
// 关联关系
templates Template[]
favorites Favorite[]
comments Comment[]
@@map("users")
}
// 提示词模板表
model Template {
id String @id @default(cuid())
title String
description String?
category String
tags String // JSON 格式存储标签数组
role String
task String
context String?
constraints String // JSON 格式存储约束数组
outputFormat String
variables String // JSON 格式存储变量数组
examples String? // JSON 格式存储示例数组
// 元数据
authorId String
author User @relation(fields: [authorId], references: [id], onDelete: Cascade)
isPublic Boolean @default(true)
isFeatured Boolean @default(false)
// 统计信息
usageCount Int @default(0)
rating Float @default(0)
ratingCount Int @default(0)
// 时间戳
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
// 关联关系
favorites Favorite[]
comments Comment[]
tests Test[]
@@map("templates")
}
// 收藏表
model Favorite {
id String @id @default(cuid())
userId String
templateId String
createdAt DateTime @default(now())
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
template Template @relation(fields: [templateId], references: [id], onDelete: Cascade)
@@unique([userId, templateId])
@@map("favorites")
}
// 评论表
model Comment {
id String @id @default(cuid())
content String
rating Int? // 1-5 星评分
userId String
templateId String
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
template Template @relation(fields: [templateId], references: [id], onDelete: Cascade)
@@map("comments")
}
// 测试记录表
model Test {
id String @id @default(cuid())
templateId String
input String // JSON 格式存储输入变量
output String? // 测试输出结果
model String // 使用的模型
parameters String // JSON 格式存储模型参数
status String // success, error, pending
duration Int? // 执行时间(毫秒)
createdAt DateTime @default(now())
template Template @relation(fields: [templateId], references: [id], onDelete: Cascade)
@@map("tests")
}
// 系统配置表
model SystemConfig {
id String @id @default(cuid())
key String @unique
value String
type String @default("string") // string, number, boolean, json
@@map("system_configs")
}

170
prisma/seed.ts Normal file
View File

@@ -0,0 +1,170 @@
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()
})