Files
veridian/db/schema.ts
T
2026-01-11 05:04:29 -06:00

43 lines
1.9 KiB
TypeScript

import { integer, pgTable, text, boolean, timestamp } from "drizzle-orm/pg-core";
import { uuidv7 } from "uuidv7";
import { user } from "./auth/auth.schema";
export * from "./auth/auth.schema";
export const agents = pgTable("agents", {
id: text("id").primaryKey().$defaultFn(() => 'agents_' + uuidv7()),
userId: text("user_id").references(() => user.id).notNull(),
name: text("name").notNull(),
systemPrompt: text("system_prompt").notNull(),
imageUrl: text("image_url")
});
export const topics = pgTable("topics", {
id: text("id").primaryKey().$defaultFn(() => 'topics_' + uuidv7()),
userId: text("user_id").references(() => user.id).notNull(),
agentId: text("agent_id").references(() => agents.id).notNull(),
name: text("name").notNull()
});
export const generations = pgTable("generations", {
id: text("id").primaryKey(),
userId: text("user_id").references(() => user.id).notNull(),
topicId: text("topic_id").references(() => topics.id).notNull(),
// nullable, because we insert into generations when we start a new generation,
// and once the generation is complete we insert the complete generation into messages
// but its currently needed to be able to fetch an entire message from its generation
// if necessary
messageId: text("message_id").references(() => messages.id),
createdAt: timestamp("created_at").notNull().defaultNow()
});
export const messages = pgTable("messages", {
id: text("id").primaryKey().$defaultFn(() => 'messages_' + uuidv7()),
userId: text("user_id").references(() => user.id).notNull(),
topicId: text("topic_id").references(() => topics.id).notNull(),
isUser: boolean("is_user").notNull(),
content: text("content").notNull(),
model: text("model"),
tokensGenerated: integer("tokens_generated"),
tokensUsedThinking: integer("tokens_used_thinking"),
createdAt: timestamp("created_at").notNull().defaultNow()
});