Add service accounts schema, enum, audit events, recurringBills FK
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -974,6 +974,10 @@ export const recurringBills = pgTable(
|
|||||||
.references(() => companyAccounts.id, { onDelete: 'restrict' }),
|
.references(() => companyAccounts.id, { onDelete: 'restrict' }),
|
||||||
categoryId: uuid('category_id').references(() => categories.id, { onDelete: 'set null' }),
|
categoryId: uuid('category_id').references(() => categories.id, { onDelete: 'set null' }),
|
||||||
partyId: uuid('party_id').references(() => parties.id, { onDelete: 'set null' }),
|
partyId: uuid('party_id').references(() => parties.id, { onDelete: 'set null' }),
|
||||||
|
serviceAccountId: uuid('service_account_id').references(
|
||||||
|
(): any => companyServiceAccounts.id,
|
||||||
|
{ onDelete: 'set null' }
|
||||||
|
),
|
||||||
name: text('name').notNull(),
|
name: text('name').notNull(),
|
||||||
description: text('description'),
|
description: text('description'),
|
||||||
cycle: recurringBillCycleEnum('cycle').notNull(),
|
cycle: recurringBillCycleEnum('cycle').notNull(),
|
||||||
@@ -999,6 +1003,47 @@ export const recurringBills = pgTable(
|
|||||||
]
|
]
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// ── Service Accounts ───────────────────────────────────
|
||||||
|
|
||||||
|
export const serviceAccountTypeEnum = pgEnum('service_account_type', [
|
||||||
|
'electricity',
|
||||||
|
'water',
|
||||||
|
'gas',
|
||||||
|
'internet',
|
||||||
|
'phone',
|
||||||
|
'shipping',
|
||||||
|
'insurance',
|
||||||
|
'tax_registration',
|
||||||
|
'social_security',
|
||||||
|
'customs',
|
||||||
|
'other'
|
||||||
|
]);
|
||||||
|
|
||||||
|
export const companyServiceAccounts = pgTable(
|
||||||
|
'company_service_accounts',
|
||||||
|
{
|
||||||
|
id: uuid('id').primaryKey().defaultRandom(),
|
||||||
|
companyId: uuid('company_id')
|
||||||
|
.notNull()
|
||||||
|
.references(() => companies.id, { onDelete: 'cascade' }),
|
||||||
|
type: serviceAccountTypeEnum('type').notNull(),
|
||||||
|
providerName: text('provider_name').notNull(),
|
||||||
|
accountNumber: text('account_number').notNull(),
|
||||||
|
customLabel: text('custom_label'),
|
||||||
|
contactPhone: text('contact_phone'),
|
||||||
|
websiteUrl: text('website_url'),
|
||||||
|
notes: text('notes'),
|
||||||
|
isActive: boolean('is_active').notNull().default(true),
|
||||||
|
createdBy: text('created_by').references(() => users.id, { onDelete: 'set null' }),
|
||||||
|
deletedAt: timestamp('deleted_at', { withTimezone: true }),
|
||||||
|
createdAt: timestamp('created_at', { withTimezone: true }).notNull().defaultNow(),
|
||||||
|
updatedAt: timestamp('updated_at', { withTimezone: true }).notNull().defaultNow()
|
||||||
|
},
|
||||||
|
(table) => [
|
||||||
|
index('company_service_accounts_company_type_idx').on(table.companyId, table.type)
|
||||||
|
]
|
||||||
|
);
|
||||||
|
|
||||||
export const companyAddresses = pgTable(
|
export const companyAddresses = pgTable(
|
||||||
'company_addresses',
|
'company_addresses',
|
||||||
{
|
{
|
||||||
@@ -1099,7 +1144,10 @@ export const companyLogEventEnum = pgEnum('company_log_event', [
|
|||||||
'recurring_bill_paused',
|
'recurring_bill_paused',
|
||||||
'recurring_bill_resumed',
|
'recurring_bill_resumed',
|
||||||
'recurring_bill_skipped',
|
'recurring_bill_skipped',
|
||||||
'recurring_bill_posted'
|
'recurring_bill_posted',
|
||||||
|
'service_account_created',
|
||||||
|
'service_account_updated',
|
||||||
|
'service_account_deleted'
|
||||||
]);
|
]);
|
||||||
|
|
||||||
export const companyLog = pgTable(
|
export const companyLog = pgTable(
|
||||||
|
|||||||
Reference in New Issue
Block a user