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