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