feat: add project collaborators schema
Introduced `projectCollaborators` schema to define project-user relationships. Includes indices and a unique constraint for `projectId` and `userId`. Added corresponding type definitions for select and insert operations.
This commit is contained in:
parent
c16c8d51d2
commit
0154f9c0aa
25
backend/src/database/schema/projectCollaborators.ts
Normal file
25
backend/src/database/schema/projectCollaborators.ts
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
import { pgTable, uuid, timestamp, index, uniqueIndex } from 'drizzle-orm/pg-core';
|
||||||
|
import { projects } from './projects';
|
||||||
|
import { users } from './users';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Project Collaborators relation table schema
|
||||||
|
*/
|
||||||
|
export const projectCollaborators = pgTable('project_collaborators', {
|
||||||
|
id: uuid('id').primaryKey().defaultRandom(),
|
||||||
|
projectId: uuid('projectId').notNull().references(() => projects.id, { onDelete: 'cascade' }),
|
||||||
|
userId: uuid('userId').notNull().references(() => users.id, { onDelete: 'cascade' }),
|
||||||
|
createdAt: timestamp('createdAt', { withTimezone: true }).defaultNow().notNull()
|
||||||
|
}, (table) => {
|
||||||
|
return {
|
||||||
|
projectIdIdx: index('pc_projectId_idx').on(table.projectId),
|
||||||
|
userIdIdx: index('pc_userId_idx').on(table.userId),
|
||||||
|
projectUserUniqueIdx: uniqueIndex('pc_project_user_unique_idx').on(table.projectId, table.userId)
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ProjectCollaborators type definitions
|
||||||
|
*/
|
||||||
|
export type ProjectCollaborator = typeof projectCollaborators.$inferSelect;
|
||||||
|
export type NewProjectCollaborator = typeof projectCollaborators.$inferInsert;
|
Loading…
x
Reference in New Issue
Block a user