added comment vote table
Some checks failed
Gitea Actions Demo / Explore-Gitea-Actions (push) Failing after 0s
Some checks failed
Gitea Actions Demo / Explore-Gitea-Actions (push) Failing after 0s
This commit is contained in:
parent
6a32dcced7
commit
d9d16d7a7e
@ -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 { articles } from "./article";
|
||||||
import { JSONContent } from "novel";
|
import { JSONContent } from "novel";
|
||||||
import { relations, sql } from "drizzle-orm";
|
import { relations, sql } from "drizzle-orm";
|
||||||
import { createId, createTable } from "./schema-utils";
|
import { createId, createTable } from "./schema-utils";
|
||||||
import { users } from "./auth";
|
import { users } from "./auth";
|
||||||
|
import { User } from "next-auth";
|
||||||
|
|
||||||
export const comments = createTable(
|
export const comments = createTable(
|
||||||
"comment",
|
"comment",
|
||||||
@ -37,3 +45,30 @@ export const comments = createTable(
|
|||||||
export const commentsRelations = relations(comments, ({ many }) => ({
|
export const commentsRelations = relations(comments, ({ many }) => ({
|
||||||
comments: many(comments),
|
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],
|
||||||
|
}),
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user