task-f.4
This commit is contained in:
@@ -188,6 +188,99 @@ export const trAuditLogs = pgTable('tr_audit_logs', {
|
||||
createdAt: timestamp('created_at', { withTimezone: true }).defaultNow().notNull()
|
||||
});
|
||||
|
||||
export const appNotificationEvents = pgTable(
|
||||
'app_notification_events',
|
||||
{
|
||||
id: text('id').primaryKey(),
|
||||
organizationId: text('organization_id').notNull(),
|
||||
eventType: text('event_type').notNull(),
|
||||
entityType: text('entity_type').notNull(),
|
||||
entityId: text('entity_id').notNull(),
|
||||
actorUserId: text('actor_user_id'),
|
||||
payload: jsonb('payload'),
|
||||
dedupeKey: text('dedupe_key'),
|
||||
status: text('status').default('pending').notNull(),
|
||||
lastError: text('last_error'),
|
||||
publishedAt: timestamp('published_at', { withTimezone: true }).defaultNow().notNull(),
|
||||
processedAt: timestamp('processed_at', { withTimezone: true }),
|
||||
createdAt: timestamp('created_at', { withTimezone: true }).defaultNow().notNull(),
|
||||
updatedAt: timestamp('updated_at', { withTimezone: true }).defaultNow().notNull()
|
||||
},
|
||||
(table) => ({
|
||||
organizationDedupeIdx: uniqueIndex('app_notification_events_org_dedupe_idx').on(
|
||||
table.organizationId,
|
||||
table.dedupeKey
|
||||
)
|
||||
})
|
||||
);
|
||||
|
||||
export const appNotifications = pgTable(
|
||||
'app_notifications',
|
||||
{
|
||||
id: text('id').primaryKey(),
|
||||
organizationId: text('organization_id').notNull(),
|
||||
recipientUserId: text('recipient_user_id').notNull(),
|
||||
eventId: text('event_id').notNull(),
|
||||
title: text('title').notNull(),
|
||||
body: text('body').notNull(),
|
||||
linkUrl: text('link_url'),
|
||||
severity: text('severity').default('info').notNull(),
|
||||
status: text('status').default('unread').notNull(),
|
||||
readAt: timestamp('read_at', { withTimezone: true }),
|
||||
archivedAt: timestamp('archived_at', { withTimezone: true }),
|
||||
metadata: jsonb('metadata'),
|
||||
createdAt: timestamp('created_at', { withTimezone: true }).defaultNow().notNull(),
|
||||
updatedAt: timestamp('updated_at', { withTimezone: true }).defaultNow().notNull()
|
||||
},
|
||||
(table) => ({
|
||||
recipientEventIdx: uniqueIndex('app_notifications_recipient_event_idx').on(
|
||||
table.recipientUserId,
|
||||
table.eventId
|
||||
)
|
||||
})
|
||||
);
|
||||
|
||||
export const appNotificationTemplates = pgTable(
|
||||
'app_notification_templates',
|
||||
{
|
||||
id: text('id').primaryKey(),
|
||||
organizationId: text('organization_id').notNull(),
|
||||
eventType: text('event_type').notNull(),
|
||||
channel: text('channel').notNull(),
|
||||
titleTemplate: text('title_template').notNull(),
|
||||
bodyTemplate: text('body_template').notNull(),
|
||||
linkTemplate: text('link_template'),
|
||||
isActive: boolean('is_active').default(true).notNull(),
|
||||
metadata: jsonb('metadata'),
|
||||
createdAt: timestamp('created_at', { withTimezone: true }).defaultNow().notNull(),
|
||||
updatedAt: timestamp('updated_at', { withTimezone: true }).defaultNow().notNull(),
|
||||
deletedAt: timestamp('deleted_at', { withTimezone: true }),
|
||||
createdBy: text('created_by').notNull(),
|
||||
updatedBy: text('updated_by').notNull()
|
||||
},
|
||||
(table) => ({
|
||||
organizationEventChannelIdx: uniqueIndex('app_notification_templates_org_event_channel_idx').on(
|
||||
table.organizationId,
|
||||
table.eventType,
|
||||
table.channel
|
||||
)
|
||||
})
|
||||
);
|
||||
|
||||
export const appNotificationDeliveries = pgTable('app_notification_deliveries', {
|
||||
id: text('id').primaryKey(),
|
||||
organizationId: text('organization_id').notNull(),
|
||||
notificationId: text('notification_id').notNull(),
|
||||
channel: text('channel').notNull(),
|
||||
recipientAddress: text('recipient_address'),
|
||||
status: text('status').default('pending').notNull(),
|
||||
attemptCount: integer('attempt_count').default(0).notNull(),
|
||||
lastError: text('last_error'),
|
||||
sentAt: timestamp('sent_at', { withTimezone: true }),
|
||||
createdAt: timestamp('created_at', { withTimezone: true }).defaultNow().notNull(),
|
||||
updatedAt: timestamp('updated_at', { withTimezone: true }).defaultNow().notNull()
|
||||
});
|
||||
|
||||
export const crmCustomers = pgTable(
|
||||
'crm_customers',
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user