2024-07-25 00:39:03 +00:00
|
|
|
import { pgTable, text, uuid } from 'drizzle-orm/pg-core';
|
|
|
|
|
import { createId as cuid2 } from '@paralleldrive/cuid2';
|
|
|
|
|
import { type InferSelectModel, relations } from 'drizzle-orm';
|
2024-08-07 17:01:38 +00:00
|
|
|
import {user_roles} from './userRoles';
|
2024-07-25 00:39:03 +00:00
|
|
|
import { timestamps } from '../utils';
|
|
|
|
|
|
2024-08-07 17:01:38 +00:00
|
|
|
export const roles = pgTable('roles', {
|
2024-07-25 00:39:03 +00:00
|
|
|
id: uuid('id').primaryKey().defaultRandom(),
|
|
|
|
|
cuid: text('cuid')
|
|
|
|
|
.unique()
|
|
|
|
|
.$defaultFn(() => cuid2())
|
|
|
|
|
.notNull(),
|
|
|
|
|
name: text('name').unique().notNull(),
|
|
|
|
|
...timestamps,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
export type Roles = InferSelectModel<typeof roles>;
|
|
|
|
|
|
|
|
|
|
export const role_relations = relations(roles, ({ many }) => ({
|
|
|
|
|
user_roles: many(user_roles),
|
|
|
|
|
}));
|