export const posts = pgTable('post', {
id: serial('id').primaryKey(),
createdAt: timestamp('createdAt').defaultNow(),
title: text('title').notNull(),
content: text('content'),
likes: integer('likes').default(0),
dislikes: integer('dislikes').default(0),
userId: integer('userId')
.notNull()
.references(() => users.id),
topic: topicsEnum('topics'),
category: categoriesEnum('categories')
});
export const postRelations = relations(posts, ({ one, many }) => {
user: one(users, {
fields: [posts.userId],
references: [users.id]
});
comments: many(comments);
});
export const comments = pgTable('comment', {
id: serial('id').primaryKey(),
comment: text('content'),
likes: integer('likes').default(0),
dislikes: integer('dislikes').default(0),
postId: integer('postId')
.notNull()
.references(() => posts.id),
createdAt: timestamp('createdAt').defaultNow()
});
export const commentRelations = relations(comments, ({ one }) => {
post: one(posts, {
fields: [comments.postId],
references: [posts.id]
});
});
export const posts = pgTable('post', {
id: serial('id').primaryKey(),
createdAt: timestamp('createdAt').defaultNow(),
title: text('title').notNull(),
content: text('content'),
likes: integer('likes').default(0),
dislikes: integer('dislikes').default(0),
userId: integer('userId')
.notNull()
.references(() => users.id),
topic: topicsEnum('topics'),
category: categoriesEnum('categories')
});
export const postRelations = relations(posts, ({ one, many }) => {
user: one(users, {
fields: [posts.userId],
references: [users.id]
});
comments: many(comments);
});
export const comments = pgTable('comment', {
id: serial('id').primaryKey(),
comment: text('content'),
likes: integer('likes').default(0),
dislikes: integer('dislikes').default(0),
postId: integer('postId')
.notNull()
.references(() => posts.id),
createdAt: timestamp('createdAt').defaultNow()
});
export const commentRelations = relations(comments, ({ one }) => {
post: one(posts, {
fields: [comments.postId],
references: [posts.id]
});
});