| 1 | import { createId } from '@paralleldrive/cuid2' |
| 2 | import { |
| 3 | boolean, |
| 4 | index, |
| 5 | integer, |
| 6 | pgTable, |
| 7 | text, |
| 8 | timestamp, |
| 9 | } from 'drizzle-orm/pg-core' |
| 10 | import { members, organizations |
| 11 | import { statusEnum } |
| 12 | import { invoices } |
| 13 | import { media } |
| 14 | import { milestones } |
| 15 | import { projects } |
| 16 | |
| 17 | export const expenseCategories = |
| 18 | id: text('id |
| 19 | .primaryKey() |
| 20 | .$defaultFn(() => |
| 21 | organizationId: text('organization_id |
| 22 | .references(() => |
| 23 | .notNull(), |
| 24 | name: text('name |
| 25 | color: text('color |
| 26 | isArchived: boolean('is_archived |
| 27 | sortOrder: integer('sort_order |
| 28 | createdAt: timestamp('created_at |
| 29 | updatedAt: timestamp('updated_at |
| 30 | .defaultNow() |
| 31 | .$onUpdate(() => |
| 32 | .notNull(), |
| 33 | }) |
| 34 | |
| 35 | export const expenses = |
| 36 | 'expenses', |
| 37 | { |
| 38 | id: text('id |
| 39 | .primaryKey() |
| 40 | .$defaultFn(() => |
| 41 | projectId: text('project_id |
| 42 | .references(() => |
| 43 | .notNull(), |
| 44 | memberId: text('member_id |
| 45 | .references(() => |
| 46 | .notNull(), |
| 47 | categoryId: text('category_id |
| 48 | .references(() => |
| 49 | .notNull(), |
| 50 | milestoneId: text('milestone_id |
| 51 | onDelete: 'set null', |
| 52 | }), |
| 53 | title: text('title |
| 54 | description: text('description |
| 55 | amountCents: integer('amount_cents |
| 56 | currency: text('currency |
| 57 | date: timestamp().notNull |
| 58 | billable: boolean().default |
| 59 | status: statusEnum().notNull |
| 60 | rejectReason: text('reject_reason |
| 61 | receiptMediaId: text('receipt_media_id |
| 62 | onDelete: 'set null', |
| 63 | }), |
| 64 | invoiceId: text('invoice_id |
| 65 | onDelete: 'set null', |
| 66 | }), |
| 67 | createdAt: timestamp('created_at |
| 68 | updatedAt: timestamp('updated_at |
| 69 | .defaultNow() |
| 70 | .$onUpdate(() => |
| 71 | .notNull(), |
| 72 | }, |
| 73 | (table) => |
| 74 | index('expenses_project_id_status_idx'). |
| 75 | index('expenses_member_id_idx'). |
| 76 | ] |
| 77 | ) |