summaryrefslogtreecommitdiff
path: root/src/server/db/schema/comments.ts
blob: 9c0626bdd11909894cab2a621193bf64bc042def (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import {
  boolean,
  index,
  integer,
  json,
  primaryKey,
  serial,
  timestamp,
  varchar,
} from 'drizzle-orm/pg-core';
import { pgTableCreator } from 'drizzle-orm/pg-core';

const createTable = pgTableCreator((name) => `blog_${name}`);

export const roles = createTable('roles', {
  userId: varchar('userId', { length: 256 }).primaryKey(),
  name: varchar('name', { length: 256 }).notNull(),
  canDelete: boolean('canDelete').notNull(),
});

export const comments = createTable('comments', {
  id: serial('id').primaryKey().notNull(),
  page: varchar('page', { length: 256 }).notNull(),
  thread: integer('thread'),
  author: varchar('author', { length: 256 }).notNull(),
  content: json('content').notNull(),
  timestamp: timestamp('timestamp', { withTimezone: true })
    .defaultNow()
    .notNull(),
});

export const rates = createTable(
  'rates',
  {
    userId: varchar('userId', { length: 256 }).notNull(),
    commentId: integer('commentId').notNull(),
    like: boolean('like').notNull(),
  },
  (table) => [
    primaryKey({ columns: [table.userId, table.commentId] }),
    index('comment_idx').on(table.commentId),
  ],
);