diff --git a/lib/db/schema/gameComments.ts b/lib/db/schema/gameComments.ts new file mode 100644 index 0000000..7020186 --- /dev/null +++ b/lib/db/schema/gameComments.ts @@ -0,0 +1,39 @@ +import { + boolean, + integer, + jsonb, + pgTable, + text, + timestamp, + index, +} from "drizzle-orm/pg-core" +import { games } from "./games" +import { user } from "./auth" + +export const gameComments = pgTable( + "game_comments", + { + id: text("id") + .primaryKey() + .$defaultFn(() => crypto.randomUUID()), + gameId: text("game_id") + .notNull() + .references(() => games.id, { onDelete: "cascade" }), + userId: text("user_id") + .notNull() + .references(() => user.id, { onDelete: "cascade" }), + parentId: text("parent_id").references((): any => gameComments.id, { + onDelete: "cascade", + }), + // Tiptap JSON document + content: jsonb("content").notNull().$type>(), + upvotes: integer("upvotes").default(0).notNull(), + isRemoved: boolean("is_removed").default(false).notNull(), + createdAt: timestamp("created_at").defaultNow().notNull(), + updatedAt: timestamp("updated_at").defaultNow().notNull(), + }, + (table) => [ + index("comments_game_created_idx").on(table.gameId, table.createdAt), + index("comments_parent_idx").on(table.parentId), + ], +)