added comment vote table
Some checks failed
Gitea Actions Demo / Explore-Gitea-Actions (push) Failing after 0s

This commit is contained in:
mr-shortman 2025-03-18 21:49:35 +01:00
parent 6a32dcced7
commit d9d16d7a7e

View File

@ -1,9 +1,17 @@
import { index, jsonb, timestamp, varchar } from "drizzle-orm/pg-core";
import {
index,
integer,
jsonb,
primaryKey,
timestamp,
varchar,
} from "drizzle-orm/pg-core";
import { articles } from "./article";
import { JSONContent } from "novel";
import { relations, sql } from "drizzle-orm";
import { createId, createTable } from "./schema-utils";
import { users } from "./auth";
import { User } from "next-auth";
export const comments = createTable(
"comment",
@ -37,3 +45,30 @@ export const comments = createTable(
export const commentsRelations = relations(comments, ({ many }) => ({
comments: many(comments),
}));
export type Comment = typeof comments.$inferSelect & {
author?: User;
parent?: Comment;
};
export const commentVotes = createTable(
"comment_vote",
{
vote: integer("vote").notNull().$type<1 | -1>().default(1),
commentId: varchar("comment_id", {
length: 255,
})
.references(() => comments.id)
.notNull(),
userId: varchar("user_id", {
length: 255,
})
.references(() => users.id)
.notNull(),
},
(example) => ({
comboundKey: primaryKey({
columns: [example.commentId, example.userId],
}),
}),
);