import { sql } from "drizzle-orm"; import { index, integer, sqliteTable, text } from "drizzle-orm/sqlite-core"; export const attachments = sqliteTable( "attachments", { id: text("id").primaryKey(), ownerType: text("owner_type", { enum: ["ticket", "ticket_message", "bug"], }).notNull(), ownerId: integer("owner_id").notNull(), authorId: text("author_id"), fileName: text("file_name").notNull(), contentType: text("content_type").notNull(), size: integer("size").notNull(), bucket: text("bucket").notNull(), key: text("key").notNull(), url: text("url").notNull(), uploadedAt: integer("uploaded_at", { mode: "timestamp" }) .default(sql`(unixepoch())`) .notNull(), }, (t) => [ index("attachments_owner_idx").on(t.ownerType, t.ownerId), index("attachments_author_idx").on(t.authorId), ], ); export type Attachment = typeof attachments.$inferSelect;