- Introduced support for nested comment replies in both frontend and backend. - Added comment liking and unliking features, including like count and "isLiked" state tracking. - Updated database schema with `parentId` and new `comment_likes` table. - Enhanced UI for threaded comments and implemented display of like counts and reply actions. - Refactored APIs and repositories to support replies, likes, and enriched comment data.
36 lines
1.1 KiB
TypeScript
36 lines
1.1 KiB
TypeScript
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" }),
|
|
parentId: uuid("parent_id").references(() => comments.id, {
|
|
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),
|
|
parentIdIdx: index("comments_parent_id_idx").on(table.parentId),
|
|
}),
|
|
);
|
|
|
|
export type CommentInDb = typeof comments.$inferSelect;
|
|
export type NewCommentInDb = typeof comments.$inferInsert;
|