Skip to content

Commit

Permalink
refactor(db): simplify primary key
Browse files Browse the repository at this point in the history
  • Loading branch information
tszhong0411 committed Feb 9, 2025
1 parent 40a84b4 commit f1de605
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 9 deletions.
7 changes: 2 additions & 5 deletions packages/db/src/schema/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,7 @@ import { guestbook } from './guestbook'
export const roleEnum = pgEnum('role', ['user', 'admin'])

export const users = pgTable('user', {
id: text('id')
.notNull()
.primaryKey()
.$defaultFn(() => createId()),
id: text('id').primaryKey().$defaultFn(createId),
name: text('name'),
email: text('email').notNull().unique(),
emailVerified: timestamp('email_verified', { precision: 3 }),
Expand Down Expand Up @@ -48,7 +45,7 @@ export const accounts = pgTable(
)

export const sessions = pgTable('session', {
sessionToken: text('session_token').notNull().primaryKey(),
sessionToken: text('session_token').primaryKey(),
userId: text('user_id')
.notNull()
.references(() => users.id, { onDelete: 'cascade' }),
Expand Down
2 changes: 1 addition & 1 deletion packages/db/src/schema/comments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { users } from './auth'
import { posts } from './posts'

export const comments = pgTable('comment', {
id: text('id').notNull().primaryKey(),
id: text('id').primaryKey(),
body: text('body').notNull(),
userId: text('user_id')
.notNull()
Expand Down
2 changes: 1 addition & 1 deletion packages/db/src/schema/guestbook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { pgTable, text, timestamp } from 'drizzle-orm/pg-core'
import { users } from './auth'

export const guestbook = pgTable('guestbook', {
id: text('id').notNull().primaryKey(),
id: text('id').primaryKey(),
body: text('body').notNull(),
userId: text('user_id')
.notNull()
Expand Down
2 changes: 1 addition & 1 deletion packages/db/src/schema/likes-sessions.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { integer, pgTable, text, timestamp } from 'drizzle-orm/pg-core'

export const likesSessions = pgTable('likes_session', {
id: text('id').notNull().primaryKey(),
id: text('id').primaryKey(),
createdAt: timestamp('created_at', { precision: 3 }).notNull().defaultNow(),
likes: integer('likes').notNull().default(0)
})
2 changes: 1 addition & 1 deletion packages/db/src/schema/posts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { comments } from './comments'

export const posts = pgTable('post', {
createdAt: timestamp('created_at', { precision: 3 }).notNull().defaultNow(),
slug: text('slug').notNull().primaryKey(),
slug: text('slug').primaryKey(),
likes: integer('likes').notNull().default(0),
views: integer('views').notNull().default(0)
})
Expand Down

0 comments on commit f1de605

Please sign in to comment.