| 1 | import { createId } from '@paralleldrive/cuid2' |
| 2 | import { |
| 3 | date, |
| 4 | index, |
| 5 | integer, |
| 6 | numeric, |
| 7 | pgTable, |
| 8 | text, |
| 9 | timestamp, |
| 10 | unique, |
| 11 | } from 'drizzle-orm/pg-core' |
| 12 | import { members } |
| 13 | import { statusEnum } |
| 14 | import { media } |
| 15 | import { projects } |
| 16 | |
| 17 | export const proposals = |
| 18 | 'proposals', |
| 19 | { |
| 20 | id: text('id |
| 21 | .primaryKey() |
| 22 | .$defaultFn(() => |
| 23 | projectId: text('project_id |
| 24 | .references(() => |
| 25 | .notNull(), |
| 26 | authorId: text('author_id |
| 27 | onDelete: 'set null', |
| 28 | }), |
| 29 | title: text('title |
| 30 | slug: text('slug |
| 31 | body: text('body |
| 32 | terms: text('terms |
| 33 | status: statusEnum('status |
| 34 | validUntil: date('valid_until |
| 35 | currency: text('currency |
| 36 | totalAmount: numeric('total_amount |
| 37 | .default('0') |
| 38 | .notNull(), |
| 39 | createdAt: timestamp('created_at |
| 40 | updatedAt: timestamp('updated_at |
| 41 | .defaultNow() |
| 42 | .$onUpdate(() => |
| 43 | .notNull(), |
| 44 | }, |
| 45 | (table) => |
| 46 | ) |
| 47 | |
| 48 | export const proposalDeliverables = |
| 49 | id: text('id |
| 50 | .primaryKey() |
| 51 | .$defaultFn(() => |
| 52 | proposalId: text('proposal_id |
| 53 | .references(() => |
| 54 | .notNull(), |
| 55 | title: text('title |
| 56 | quantity: numeric('quantity |
| 57 | unitPrice: numeric('unit_price |
| 58 | amount: numeric('amount |
| 59 | sortOrder: integer('sort_order |
| 60 | createdAt: timestamp('created_at |
| 61 | updatedAt: timestamp('updated_at |
| 62 | .defaultNow() |
| 63 | .$onUpdate(() => |
| 64 | .notNull(), |
| 65 | }) |
| 66 | |
| 67 | export const proposalRecipients = |
| 68 | 'proposal_recipients', |
| 69 | { |
| 70 | id: text('id |
| 71 | .primaryKey() |
| 72 | .$defaultFn(() => |
| 73 | proposalId: text('proposal_id |
| 74 | .references(() => |
| 75 | .notNull(), |
| 76 | clientMemberId: text('client_member_id |
| 77 | .references(() => |
| 78 | .notNull(), |
| 79 | sentAt: timestamp('sent_at |
| 80 | createdAt: timestamp('created_at |
| 81 | updatedAt: timestamp('updated_at |
| 82 | .defaultNow() |
| 83 | .$onUpdate(() => |
| 84 | .notNull(), |
| 85 | }, |
| 86 | (t) => |
| 87 | ) |
| 88 | |
| 89 | export const proposalSignatures = |
| 90 | id: text('id |
| 91 | .primaryKey() |
| 92 | .$defaultFn(() => |
| 93 | proposalId: text('proposal_id |
| 94 | .references(() => |
| 95 | .notNull(), |
| 96 | clientMemberId: text('client_member_id |
| 97 | .references(() => |
| 98 | .notNull(), |
| 99 | mediaId: text('media_id |
| 100 | onDelete: 'set null', |
| 101 | }), |
| 102 | signedAt: timestamp('signed_at |
| 103 | createdAt: timestamp('created_at |
| 104 | updatedAt: timestamp('updated_at |
| 105 | .defaultNow() |
| 106 | .$onUpdate(() => |
| 107 | .notNull(), |
| 108 | }) |