| 1 | import { createId } from '@paralleldrive/cuid2' |
| 2 | import { |
| 3 | pgEnum, |
| 4 | pgTable, |
| 5 | text, |
| 6 | timestamp, |
| 7 | uniqueIndex, |
| 8 | } from 'drizzle-orm/pg-core' |
| 9 | import { members, organizations |
| 10 | |
| 11 | export const projectStatus = |
| 12 | 'planning', |
| 13 | 'in-progress', |
| 14 | 'on-hold', |
| 15 | 'completed', |
| 16 | 'archived', |
| 17 | ]) |
| 18 | |
| 19 | export const projects = |
| 20 | id: text('id |
| 21 | .primaryKey() |
| 22 | .$defaultFn(() => |
| 23 | name: text('name |
| 24 | description: text('description |
| 25 | slug: text('slug |
| 26 | organizationId: text('organization_id |
| 27 | .references(() => |
| 28 | .notNull(), |
| 29 | status: projectStatus().default |
| 30 | dueDate: timestamp('due_date |
| 31 | createdAt: timestamp('created_at |
| 32 | updatedAt: timestamp('updated_at |
| 33 | .defaultNow() |
| 34 | .$onUpdate(() => |
| 35 | .notNull(), |
| 36 | }) |
| 37 | |
| 38 | export const projectTeamAssignments = |
| 39 | 'project_team_assignments', |
| 40 | { |
| 41 | id: text('id |
| 42 | .primaryKey() |
| 43 | .$defaultFn(() => |
| 44 | projectId: text('project_id |
| 45 | .references(() => |
| 46 | .notNull(), |
| 47 | teamId: text('team_id |
| 48 | .references(() => |
| 49 | .notNull(), |
| 50 | assignedAt: timestamp('assigned_at |
| 51 | }, |
| 52 | (table) => |
| 53 | uniqueIndex('project_team_unique'). |
| 54 | ] |
| 55 | ) |
| 56 | |
| 57 | export const projectMemberAssignments = |
| 58 | 'project_member_assignments', |
| 59 | { |
| 60 | id: text('id |
| 61 | .primaryKey() |
| 62 | .$defaultFn(() => |
| 63 | projectId: text('project_id |
| 64 | .references(() => |
| 65 | .notNull(), |
| 66 | memberId: text('member_id |
| 67 | .references(() => |
| 68 | .notNull(), |
| 69 | role: text('role |
| 70 | assignedAt: timestamp('assigned_at |
| 71 | }, |
| 72 | (table) => |
| 73 | uniqueIndex('project_member_unique'). |
| 74 | ] |
| 75 | ) |
| 76 | |
| 77 | export const projectClientAssignments = |
| 78 | 'project_client_assignments', |
| 79 | { |
| 80 | id: text('id |
| 81 | .primaryKey() |
| 82 | .$defaultFn(() => |
| 83 | projectId: text('project_id |
| 84 | .references(() => |
| 85 | .notNull(), |
| 86 | memberId: text('member_id |
| 87 | .references(() => |
| 88 | .notNull(), |
| 89 | assignedAt: timestamp('assigned_at |
| 90 | }, |
| 91 | (table) => |
| 92 | uniqueIndex('project_client_unique'). |
| 93 | ] |
| 94 | ) |
| 95 | |
| 96 | export const projectInvitationTypeEnum = |
| 97 | 'member', |
| 98 | 'client', |
| 99 | ]) |
| 100 | |
| 101 | export const projectInvitations = |
| 102 | id: text('id |
| 103 | .primaryKey() |
| 104 | .$defaultFn(() => |
| 105 | invitationId: text('invitation_id |
| 106 | projectId: text('project_id |
| 107 | .references(() => |
| 108 | .notNull(), |
| 109 | type: projectInvitationTypeEnum('type |
| 110 | createdAt: timestamp('created_at |
| 111 | }) |