Skip to content

Commit

Permalink
feat: adjust timestamp to use tz
Browse files Browse the repository at this point in the history
  • Loading branch information
zekhoi committed Aug 31, 2024
1 parent fd18df6 commit a063550
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 7 deletions.
8 changes: 6 additions & 2 deletions src/database/tables/reference.table.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,12 @@ export const reference = pgTable('references', {
title: varchar('title', { length: 100 }),
status: statusEnum('status').notNull(),
description: varchar('description', { length: 255 }),
createdAt: timestamp('created_at').defaultNow().notNull(),
updatedAt: timestamp('updated_at').defaultNow().notNull(),
createdAt: timestamp('created_at', { withTimezone: true })
.defaultNow()
.notNull(),
updatedAt: timestamp('updated_at', { withTimezone: true })
.defaultNow()
.notNull(),
createdBy: uuid('created_by')
.notNull()
.references(() => user.id),
Expand Down
7 changes: 6 additions & 1 deletion src/database/tables/role.table.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@ import { v7 as uuidv7 } from 'uuid';
export const role = pgTable('roles', {
id: uuid('id').primaryKey().$defaultFn(uuidv7),
name: text('name').unique().notNull(),
createdAt: timestamp('created_at').defaultNow().notNull(),
createdAt: timestamp('created_at', { withTimezone: true })
.defaultNow()
.notNull(),
updatedAt: timestamp('updated_at', { withTimezone: true })
.defaultNow()
.notNull(),
});

export type Role = typeof role.$inferSelect;
8 changes: 6 additions & 2 deletions src/database/tables/tag.table.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,12 @@ import { user } from './user.table';
export const tag = pgTable('tags', {
id: uuid('id').primaryKey().$defaultFn(uuidv7),
name: varchar('name', { length: 50 }).notNull().unique(),
createdAt: timestamp('created_at').defaultNow().notNull(),
updatedAt: timestamp('updated_at').defaultNow().notNull(),
createdAt: timestamp('created_at', { withTimezone: true })
.defaultNow()
.notNull(),
updatedAt: timestamp('updated_at', { withTimezone: true })
.defaultNow()
.notNull(),
createdBy: uuid('created_by')
.notNull()
.references(() => user.id),
Expand Down
8 changes: 6 additions & 2 deletions src/database/tables/user.table.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,12 @@ export const user = pgTable('users', {
roleId: uuid('role_id')
.notNull()
.references(() => role.id),
createdAt: timestamp('created_at').defaultNow().notNull(),
updatedAt: timestamp('updated_at').defaultNow().notNull(),
createdAt: timestamp('created_at', { withTimezone: true })
.defaultNow()
.notNull(),
updatedAt: timestamp('updated_at', { withTimezone: true })
.defaultNow()
.notNull(),
});

export type User = typeof user.$inferSelect;
Expand Down
1 change: 1 addition & 0 deletions src/lib/actions/roles.action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export async function editRoleName(roleId: string, name: string) {
.update(role)
.set({
name,
updatedAt: new Date(),
})
.where(eq(role.id, roleId));
}
Expand Down
1 change: 1 addition & 0 deletions src/lib/actions/users.action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ export async function editUserRole(userId: string, roleId: string) {
.update(user)
.set({
roleId,
updatedAt: new Date(),
})
.where(eq(user.id, userId));
}

0 comments on commit a063550

Please sign in to comment.