import type { InferSelectModel } from "drizzle-orm"; import { boolean, json, pgTable, primaryKey, text, timestamp, uuid, varchar, } from "drizzle-orm/pg-core"; export const user = pgTable("User", { id: uuid("id").primaryKey().notNull().defaultRandom(), email: varchar("email", { length: 64 }).notNull(), password: varchar("password", { length: 64 }), name: text("name"), emailVerified: boolean("emailVerified").notNull().default(false), image: text("image"), isAnonymous: boolean("isAnonymous").notNull().default(false), createdAt: timestamp("createdAt").notNull().defaultNow(), updatedAt: timestamp("updatedAt").notNull().defaultNow(), }); export type User = InferSelectModel; export const chat = pgTable("Chat", { id: uuid("id").primaryKey().notNull().defaultRandom(), createdAt: timestamp("createdAt").notNull(), title: text("title").notNull(), userId: uuid("userId") .notNull() .references(() => user.id), visibility: varchar("visibility", { enum: ["public", "private"] }) .notNull() .default("private"), }); export type Chat = InferSelectModel; export const message = pgTable("Message_v2", { id: uuid("id").primaryKey().notNull().defaultRandom(), chatId: uuid("chatId") .notNull() .references(() => chat.id), role: varchar("role").notNull(), parts: json("parts").notNull(), attachments: json("attachments").notNull(), createdAt: timestamp("createdAt").notNull(), }); export type DBMessage = InferSelectModel; export const vote = pgTable( "Vote_v2", { chatId: uuid("chatId") .notNull() .references(() => chat.id), messageId: uuid("messageId") .notNull() .references(() => message.id), isUpvoted: boolean("isUpvoted").notNull(), }, (table) => ({ pk: primaryKey({ columns: [table.chatId, table.messageId] }), }) ); export type Vote = InferSelectModel;