chore: update usage database schema

This commit is contained in:
steven
2023-04-24 18:07:13 +08:00
parent a82308bd8b
commit 00e3040670
5 changed files with 115 additions and 87 deletions

View File

@ -1,70 +1,61 @@
import { PrismaClient, Prisma } from '@prisma/client'
import { PrismaClient, Prisma } from "@prisma/client";
import { v4 as uuidv4 } from "uuid";
const prisma = new PrismaClient()
const prisma = new PrismaClient();
const chatData: Prisma.ChatCreateInput[] = [
{
id: uuidv4(),
createdAt: new Date(),
ctx: {},
prompts: {
messages: {
create: [
{
id: uuidv4(),
createdAt: new Date(),
q: "Hello",
a: "What can I help you with today?",
role: "system",
content: "You are a bot",
upvote: true,
downvote: false,
},
{
id: uuidv4(),
createdAt: new Date(),
q: "How are you?",
a: "Fine, thank you, and you?",
role: "user",
content: "What can I help you with today?",
upvote: true,
downvote: false,
},
{
id: uuidv4(),
createdAt: new Date(),
role: "assistant",
content: "Hello",
upvote: true,
downvote: false,
},
],
},
},
{
id: uuidv4(),
createdAt: new Date(),
ctx: {},
prompts: {
create: [
{
id: uuidv4(),
createdAt: new Date(),
q: "Tell me a joke",
a: "What do you call a fake noodle? An Impasta.",
upvote: true,
downvote: false,
},
],
},
},
]
];
async function main() {
console.log(`Start seeding ...`)
console.log(`Start seeding ...`);
for (const c of chatData) {
const chat = await prisma.chat.create({
data: c,
})
console.log(`Created chat with id: ${chat.id}`)
});
console.log(`Created chat with id: ${chat.id}`);
}
console.log(`Seeding finished.`)
console.log(`Seeding finished.`);
}
main()
.then(async () => {
await prisma.$disconnect()
await prisma.$disconnect();
})
.catch(async (e) => {
console.error(e)
await prisma.$disconnect()
process.exit(1)
})
console.error(e);
await prisma.$disconnect();
process.exit(1);
});