Initial open-source release

This commit is contained in:
Will Chen
2025-04-11 09:37:05 -07:00
commit 43f67e0739
208 changed files with 45476 additions and 0 deletions

58
src/db/schema.ts Normal file
View File

@@ -0,0 +1,58 @@
import { sql } from "drizzle-orm";
import { integer, sqliteTable, text } from "drizzle-orm/sqlite-core";
import { relations } from "drizzle-orm";
export const apps = sqliteTable("apps", {
id: integer("id").primaryKey({ autoIncrement: true }),
name: text("name").notNull(),
path: text("path").notNull(),
createdAt: integer("created_at", { mode: "timestamp" })
.notNull()
.default(sql`(unixepoch())`),
updatedAt: integer("updated_at", { mode: "timestamp" })
.notNull()
.default(sql`(unixepoch())`),
});
export const chats = sqliteTable("chats", {
id: integer("id").primaryKey({ autoIncrement: true }),
appId: integer("app_id")
.notNull()
.references(() => apps.id, { onDelete: "cascade" }),
title: text("title"),
createdAt: integer("created_at", { mode: "timestamp" })
.notNull()
.default(sql`(unixepoch())`),
});
export const messages = sqliteTable("messages", {
id: integer("id").primaryKey({ autoIncrement: true }),
chatId: integer("chat_id")
.notNull()
.references(() => chats.id, { onDelete: "cascade" }),
role: text("role", { enum: ["user", "assistant"] }).notNull(),
content: text("content").notNull(),
createdAt: integer("created_at", { mode: "timestamp" })
.notNull()
.default(sql`(unixepoch())`),
});
// Define relations
export const appsRelations = relations(apps, ({ many }) => ({
chats: many(chats),
}));
export const chatsRelations = relations(chats, ({ many, one }) => ({
messages: many(messages),
app: one(apps, {
fields: [chats.appId],
references: [apps.id],
}),
}));
export const messagesRelations = relations(messages, ({ one }) => ({
chat: one(chats, {
fields: [messages.chatId],
references: [chats.id],
}),
}));