continue scaffolding and refine the basic foundation
This commit is contained in:
+39
-21
@@ -1,43 +1,61 @@
|
||||
import { integer, pgTable, text, boolean, timestamp } from "drizzle-orm/pg-core";
|
||||
import { uuidv7 } from "uuidv7";
|
||||
import { integer, pgTable, text, boolean, timestamp, varchar } from "drizzle-orm/pg-core";
|
||||
import { nanoid } from "nanoid";
|
||||
import { user } from "./auth/auth.schema";
|
||||
import { relations } from "drizzle-orm";
|
||||
export * from "./auth/auth.schema";
|
||||
|
||||
export const agents = pgTable("agents", {
|
||||
id: text("id").primaryKey().$defaultFn(() => 'agents_' + uuidv7()),
|
||||
id: text("id").primaryKey().$defaultFn(() => 'agents_' + nanoid()),
|
||||
userId: text("user_id").references(() => user.id).notNull(),
|
||||
name: text("name").notNull(),
|
||||
systemPrompt: text("system_prompt").notNull(),
|
||||
systemPrompt: text("system_prompt"),
|
||||
imageUrl: text("image_url")
|
||||
});
|
||||
|
||||
export const topics = pgTable("topics", {
|
||||
id: text("id").primaryKey().$defaultFn(() => 'topics_' + uuidv7()),
|
||||
id: text("id").primaryKey().$defaultFn(() => 'topics_' + nanoid()),
|
||||
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),
|
||||
name: text("name").notNull(),
|
||||
createdAt: timestamp("created_at").notNull().defaultNow()
|
||||
});
|
||||
|
||||
export const messages = pgTable("messages", {
|
||||
id: text("id").primaryKey().$defaultFn(() => 'messages_' + uuidv7()),
|
||||
id: text("id").primaryKey().$defaultFn(() => 'messages_' + nanoid()),
|
||||
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(),
|
||||
isUser: boolean("is_user").notNull(),
|
||||
regeneratedFromId: text("regenerated_from_id").references((): any => messages.id),
|
||||
isRegenerated: boolean("is_regenerated").default(false),
|
||||
editedAt: timestamp("edited_at"),
|
||||
createdAt: timestamp("created_at").notNull().defaultNow()
|
||||
});
|
||||
|
||||
export const generations = pgTable("generations", {
|
||||
id: text("id").primaryKey().$defaultFn(() => 'generations_' + nanoid()),
|
||||
userId: text("user_id").references(() => user.id).notNull(),
|
||||
topicId: text("topic_id").references(() => topics.id).notNull(),
|
||||
status: varchar("status", { length: 20 }).notNull().default("pending"),
|
||||
messageId: text("message_id").references(() => messages.id),
|
||||
regeneratesFrom: text("regenerates_from").references(() => messages.id),
|
||||
model: text("model"),
|
||||
tokensGenerated: integer("tokens_generated"),
|
||||
tokensUsedThinking: integer("tokens_used_thinking"),
|
||||
createdAt: timestamp("created_at").notNull().defaultNow()
|
||||
});
|
||||
error: text("error"),
|
||||
createdAt: timestamp("created_at").notNull().defaultNow(),
|
||||
startedAt: timestamp("started_at"),
|
||||
completedAt: timestamp("completed_at")
|
||||
});
|
||||
|
||||
export const messagesRelations = relations(messages, ({ one, many }) => ({
|
||||
generations: many(generations),
|
||||
regeneratedFrom: one(messages, {
|
||||
fields: [messages.regeneratedFromId],
|
||||
references: [messages.id],
|
||||
relationName: 'regeneratedFrom'
|
||||
}),
|
||||
regenerations: many(messages, {
|
||||
relationName: 'regeneratedFrom'
|
||||
})
|
||||
}));
|
||||
Reference in New Issue
Block a user