feat: add storage_objects schema for R2 tracking

This commit is contained in:
2026-05-09 12:44:49 +08:00
parent bb459b3146
commit f59ef61634
7 changed files with 3100 additions and 6 deletions
+1
View File
@@ -10,3 +10,4 @@ export * from "./savedGames"
export * from "./reports"
export * from "./community-suggestions"
export * from "./saved-filters"
export * from "./storage"
+34
View File
@@ -0,0 +1,34 @@
import {
boolean,
integer,
pgTable,
text,
timestamp,
index,
} from "drizzle-orm/pg-core"
import { user } from "./auth"
export const storageObjects = pgTable(
"storage_objects",
{
id: text("id")
.primaryKey()
.$defaultFn(() => crypto.randomUUID()),
key: text("key").notNull(),
bucket: text("bucket").notNull(),
size: integer("size").notNull(),
mimeType: text("mime_type").notNull(),
entityType: text("entity_type").notNull(), // "avatar" | "game_cover" | "hardware_image"
entityId: text("entity_id"), // user ID, game ID, or hardware slug
uploadedBy: text("uploaded_by")
.notNull()
.references(() => user.id, { onDelete: "cascade" }),
createdAt: timestamp("created_at").defaultNow().notNull(),
lastAccessedAt: timestamp("last_accessed_at"),
isOrphaned: boolean("is_orphaned").default(false).notNull(),
},
(table) => [
index("storage_entity_idx").on(table.entityType, table.entityId),
index("storage_key_idx").on(table.key),
],
)