89 lines
2.2 KiB
TypeScript
89 lines
2.2 KiB
TypeScript
import { PrismaClient } from '@prisma/client';
|
|||
|
|
|
||
|
|
const prisma = new PrismaClient();
|
||
|
|
|
||
|
|
async function main() {
|
||
|
|
console.log('开始填充种子数据...');
|
||
|
|
|
||
|
|
// 创建默认 LLM 配置
|
||
|
|
const defaultLlmConfig = await prisma.llmConfig.create({
|
||
|
|
data: {
|
||
|
|
name: '默认配置',
|
||
|
|
baseUrl: 'https://api.openai.com/v1',
|
||
|
|
model: 'gpt-4o-mini',
|
||
|
|
apiKey: 'your-api-key-here',
|
||
|
|
enabled: true,
|
||
|
|
},
|
||
|
|
});
|
||
|
|
console.log('✅ 创建默认 LLM 配置:', defaultLlmConfig.id);
|
||
|
|
|
||
|
|
// 创建示例数据源
|
||
|
|
const sampleSource = await prisma.source.create({
|
||
|
|
data: {
|
||
|
|
name: '示例新闻源',
|
||
|
|
type: 'api',
|
||
|
|
config: JSON.stringify({
|
||
|
|
url: 'https://api.example.com/news',
|
||
|
|
method: 'GET',
|
||
|
|
headers: {},
|
||
|
|
}),
|
||
|
|
cronExpression: '0 */6 * * *',
|
||
|
|
enabled: false,
|
||
|
|
},
|
||
|
|
});
|
||
|
|
console.log('✅ 创建示例数据源:', sampleSource.id);
|
||
|
|
|
||
|
|
// 创建示例推送渠道
|
||
|
|
const sampleChannel = await prisma.channel.create({
|
||
|
|
data: {
|
||
|
|
name: '示例邮箱',
|
||
|
|
type: 'email',
|
||
|
|
config: JSON.stringify({
|
||
|
|
smtpHost: 'smtp.example.com',
|
||
|
|
smtpPort: 587,
|
||
|
|
username: 'user@example.com',
|
||
|
|
password: 'password',
|
||
|
|
to: 'recipient@example.com',
|
||
|
|
}),
|
||
|
|
enabled: false,
|
||
|
|
},
|
||
|
|
});
|
||
|
|
console.log('✅ 创建示例推送渠道:', sampleChannel.id);
|
||
|
|
|
||
|
|
// 创建示例主题
|
||
|
|
const sampleTopic = await prisma.topic.create({
|
||
|
|
data: {
|
||
|
|
name: '示例主题',
|
||
|
|
description: '这是一个示例主题,用于演示功能',
|
||
|
|
processMode: 'summary',
|
||
|
|
llmConfigId: defaultLlmConfig.id,
|
||
|
|
scheduleConfig: JSON.stringify({
|
||
|
|
cron: '0 9 * * *',
|
||
|
|
timezone: 'Asia/Shanghai',
|
||
|
|
}),
|
||
|
|
enabled: false,
|
||
|
|
topicSources: {
|
||
|
|
create: {
|
||
|
|
sourceId: sampleSource.id,
|
||
|
|
},
|
||
|
|
},
|
||
|
|
topicChannels: {
|
||
|
|
create: {
|
||
|
|
channelId: sampleChannel.id,
|
||
|
|
},
|
||
|
|
},
|
||
|
|
},
|
||
|
|
});
|
||
|
|
console.log('✅ 创建示例主题:', sampleTopic.id);
|
||
|
|
|
||
|
|
console.log('\n✨ 种子数据填充完成!');
|
||
|
|
}
|
||
|
|
|
||
|
|
main()
|
||
|
|
.catch((e) => {
|
||
|
|
console.error('❌ 种子数据填充失败:', e);
|
||
|
|
process.exit(1);
|
||
|
|
})
|
||
|
|
.finally(async () => {
|
||
|
|
await prisma.$disconnect();
|
||
|
|
});
|