Something went wrong. Try again.
[READ-ONLY] Mirror of https://github.com/openstatusHQ/openstatus. ๐ซ Status page with uptime monitoring & API monitoring as code ๐ซ openstatus.dev
bun drizzle-orm monitoring monitoring-as-code nextjs observability on-call open-source shadcn-ui status-page statuspage synthetic-monitoring tinybird turso uptime uptime-checker uptime-monitor
Something went wrong. Try again.
1.6 kB ยท 47 lines
TypeScript
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748import { index, integer, sqliteTable, text } from "drizzle-orm/sqlite-core";
import { user } from "../users";import { workspace } from "../workspaces";import type { ChatStoredMessage } from "./messages";
/** * Surrogate-PK row per dashboard chat conversation. Many rows per * (workspace, user). Bounded by application logic on insert * (`MAX_CHAT_SESSIONS_PER_USER`); per-row payload bounded by * `MAX_CHAT_MESSAGES` and a tool-result compaction policy in the service * layer. */export const chatSession = sqliteTable( "chat_session", { id: integer("id").primaryKey({ autoIncrement: true }), workspaceId: integer("workspace_id") .notNull() .references(() => workspace.id, { onDelete: "cascade" }), userId: integer("user_id") .notNull() .references(() => user.id, { onDelete: "cascade" }), title: text("title").notNull(), messages: text("messages", { mode: "json" }) .$type<ChatStoredMessage[]>() .notNull(), createdAt: integer("created_at", { mode: "timestamp_ms" }) .notNull() .$defaultFn(() => new Date()), updatedAt: integer("updated_at", { mode: "timestamp_ms" }) .notNull() .$defaultFn(() => new Date()), }, (t) => [ // Sidebar / picker query: list a user's conversations newest first. // Also covers the cap-enforcement query ("oldest row for this pair"). index("chat_session_workspace_user_updated_idx").on( t.workspaceId, t.userId, t.updatedAt, ), ],);
export type ChatSessionRow = typeof chatSession.$inferSelect;export type NewChatSessionRow = typeof chatSession.$inferInsert;