mirror of
https://github.com/BradNut/boredgame
synced 2025-09-08 17:40:22 +00:00
28 lines
768 B
TypeScript
28 lines
768 B
TypeScript
import { createId as cuid2 } from '@paralleldrive/cuid2';
|
|
import { type InferSelectModel, relations } from 'drizzle-orm';
|
|
import { pgTable, text, uuid } from 'drizzle-orm/pg-core';
|
|
import { timestamps } from '../../../common/utils/table';
|
|
import { user_roles } from './userRoles.table';
|
|
|
|
export enum RoleName {
|
|
ADMIN = 'admin',
|
|
EDITOR = 'editor',
|
|
MODERATOR = 'moderator',
|
|
USER = 'user',
|
|
}
|
|
|
|
export const rolesTable = pgTable('roles', {
|
|
id: uuid().primaryKey().defaultRandom(),
|
|
cuid: text()
|
|
.unique()
|
|
.$defaultFn(() => cuid2())
|
|
.notNull(),
|
|
name: text().unique().notNull(),
|
|
...timestamps,
|
|
});
|
|
|
|
export type Roles = InferSelectModel<typeof rolesTable>;
|
|
|
|
export const role_relations = relations(rolesTable, ({ many }) => ({
|
|
user_roles: many(user_roles),
|
|
}));
|