2024-07-25 00:39:03 +00:00
|
|
|
import { boolean, pgTable, text, uuid } from 'drizzle-orm/pg-core';
|
|
|
|
|
import { type InferSelectModel, relations } from 'drizzle-orm';
|
2024-08-23 02:26:22 +00:00
|
|
|
import { createId as cuid2 } from '@paralleldrive/cuid2';
|
2024-07-25 00:39:03 +00:00
|
|
|
import { timestamps } from '../utils';
|
2024-08-07 17:01:38 +00:00
|
|
|
import {user_roles} from './userRoles';
|
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),
|
|
|
|
|
theme: text('theme').default('system'),
|
|
|
|
|
...timestamps,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
export const userRelations = relations(usersTable, ({ many }) => ({
|
|
|
|
|
user_roles: many(user_roles),
|
|
|
|
|
}));
|
|
|
|
|
|
|
|
|
|
export type Users = InferSelectModel<typeof usersTable>;
|