2024-09-01 19:22:00 +00:00
|
|
|
import { createId as cuid2 } from '@paralleldrive/cuid2'
|
|
|
|
|
import { type InferSelectModel, relations } from 'drizzle-orm'
|
|
|
|
|
import { 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-09-01 19:22:00 +00:00
|
|
|
|
2024-09-14 00:21:22 +00:00
|
|
|
export enum RoleName {
|
|
|
|
|
ADMIN = 'admin',
|
|
|
|
|
EDITOR = 'editor',
|
|
|
|
|
MODERATOR = 'moderator',
|
|
|
|
|
USER = 'user',
|
|
|
|
|
}
|
|
|
|
|
|
2024-09-04 23:04:41 +00:00
|
|
|
export const rolesTable = pgTable('roles', {
|
2024-09-01 19:22:00 +00:00
|
|
|
id: uuid('id').primaryKey().defaultRandom(),
|
|
|
|
|
cuid: text('cuid')
|
|
|
|
|
.unique()
|
|
|
|
|
.$defaultFn(() => cuid2())
|
|
|
|
|
.notNull(),
|
|
|
|
|
name: text('name').unique().notNull(),
|
|
|
|
|
...timestamps,
|
|
|
|
|
})
|
|
|
|
|
|
2024-09-04 23:04:41 +00:00
|
|
|
export type Roles = InferSelectModel<typeof rolesTable>
|
2024-09-01 19:22:00 +00:00
|
|
|
|
2024-09-04 23:04:41 +00:00
|
|
|
export const role_relations = relations(rolesTable, ({ many }) => ({
|
2024-09-01 19:22:00 +00:00
|
|
|
user_roles: many(user_roles),
|
|
|
|
|
}))
|