import { index, pgTable, text, timestamp, uuid } from "drizzle-orm/pg-core"; import { contents } from "./content"; import { users } from "./users"; export const comments = pgTable( "comments", { id: uuid("id").primaryKey().defaultRandom(), contentId: uuid("content_id") .notNull() .references(() => contents.id, { onDelete: "cascade" }), userId: uuid("user_id") .notNull() .references(() => users.uuid, { onDelete: "cascade" }), text: text("text").notNull(), createdAt: timestamp("created_at", { withTimezone: true }) .notNull() .defaultNow(), updatedAt: timestamp("updated_at", { withTimezone: true }) .notNull() .defaultNow(), deletedAt: timestamp("deleted_at", { withTimezone: true }), }, (table) => ({ contentIdIdx: index("comments_content_id_idx").on(table.contentId), userIdIdx: index("comments_user_id_idx").on(table.userId), }), ); export type CommentInDb = typeof comments.$inferSelect; export type NewCommentInDb = typeof comments.$inferInsert;