2024-08-31 00:36:22 +00:00
|
|
|
import { createId as cuid2 } from '@paralleldrive/cuid2'
|
2024-09-01 19:22:00 +00:00
|
|
|
import { type InferSelectModel, relations } from 'drizzle-orm'
|
|
|
|
|
import { boolean, pgTable, text, uuid } from 'drizzle-orm/pg-core'
|
2024-09-04 23:04:41 +00:00
|
|
|
import { timestamps } from '../../common/utils/table'
|
|
|
|
|
import { user_roles } from './userRoles.table'
|
2024-07-25 00:39:03 +00:00
|
|
|
|
2024-07-29 01:39:42 +00:00
|
|
|
export const usersTable = pgTable('users', {
|
2024-07-25 00:39:03 +00:00
|
|
|
id: uuid('id').primaryKey().defaultRandom(),
|
|
|
|
|
cuid: text('cuid')
|
|
|
|
|
.unique()
|
|
|
|
|
.$defaultFn(() => cuid2()),
|
|
|
|
|
username: text('username').unique(),
|
|
|
|
|
email: text('email').unique(),
|
|
|
|
|
first_name: text('first_name'),
|
|
|
|
|
last_name: text('last_name'),
|
|
|
|
|
verified: boolean('verified').default(false),
|
|
|
|
|
receive_email: boolean('receive_email').default(false),
|
2024-09-21 00:25:51 +00:00
|
|
|
email_verified: boolean('email_verified').default(false),
|
|
|
|
|
picture: text('picture'),
|
2024-08-31 00:36:22 +00:00
|
|
|
mfa_enabled: boolean('mfa_enabled').notNull().default(false),
|
2024-07-25 00:39:03 +00:00
|
|
|
theme: text('theme').default('system'),
|
|
|
|
|
...timestamps,
|
2024-08-31 00:36:22 +00:00
|
|
|
})
|
2024-07-25 00:39:03 +00:00
|
|
|
|
|
|
|
|
export const userRelations = relations(usersTable, ({ many }) => ({
|
|
|
|
|
user_roles: many(user_roles),
|
2024-08-31 00:36:22 +00:00
|
|
|
}))
|
2024-07-25 00:39:03 +00:00
|
|
|
|
2024-08-31 00:36:22 +00:00
|
|
|
export type Users = InferSelectModel<typeof usersTable>
|