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