all repos — stealth-developers @ a78eed8b66665f02ed3de6a3c6749c475061b59e

pkgs/bot/src/database/schema/attachments.ts (view raw)

 1
 2
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
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;