import { index, integer, sqliteTable, text, uniqueIndex } from "drizzle-orm/sqlite-core"; export const projects = sqliteTable("projects", { archivedAt: text("archived_at"), createdAt: text("created_at").notNull(), description: text("description").notNull().default(""), id: text("id").primaryKey(), name: text("name").notNull().unique(), status: text("status", { enum: ["active", "archived"] }) .notNull() .default("active"), updatedAt: text("updated_at").notNull(), }); export const providers = sqliteTable("providers", { apiKey: text("api_key").notNull(), baseUrl: text("base_url").notNull(), createdAt: text("created_at").notNull(), id: text("id").primaryKey(), name: text("name").notNull().unique(), type: text("type", { enum: ["anthropic", "openai", "openai-compatible"] }) .notNull() .default("openai-compatible"), updatedAt: text("updated_at").notNull(), }); export const models = sqliteTable( "models", { capabilities: text("capabilities").notNull(), contextLength: integer("context_length"), createdAt: text("created_at").notNull(), id: text("id").primaryKey(), maxOutputTokens: integer("max_output_tokens"), modelId: text("model_id").notNull(), name: text("name").notNull(), providerId: text("provider_id") .notNull() .references(() => providers.id), updatedAt: text("updated_at").notNull(), }, (table) => [ uniqueIndex("models_provider_id_model_id_unique").on(table.providerId, table.modelId), index("models_provider_id_idx").on(table.providerId), ], ); export const conversations = sqliteTable( "conversations", { createdAt: text("created_at").notNull(), id: text("id").primaryKey(), modelId: text("model_id") .notNull() .references(() => models.id), projectId: text("project_id") .notNull() .references(() => projects.id), title: text("title").notNull().default("新会话"), updatedAt: text("updated_at").notNull(), }, (table) => [index("conversations_project_id_idx").on(table.projectId)], ); export const messages = sqliteTable( "messages", { content: text("content").notNull().default(""), conversationId: text("conversation_id") .notNull() .references(() => conversations.id, { onDelete: "cascade" }), createdAt: text("created_at").notNull(), id: text("id").primaryKey(), parts: text("parts"), role: text("role", { enum: ["assistant", "system", "user"] }).notNull(), }, (table) => [index("messages_conversation_id_idx").on(table.conversationId)], ); export const schemaMigrations = sqliteTable("schema_migrations", { appliedAt: text("applied_at").notNull(), checksum: text("checksum").notNull(), id: text("id").primaryKey(), });