@@ -413,6 +413,116 @@ export const monobankEvents = pgTable(
413413 ]
414414) ;
415415
416+ export const paymentEvents = pgTable (
417+ 'payment_events' ,
418+ {
419+ id : uuid ( 'id' ) . defaultRandom ( ) . primaryKey ( ) ,
420+ orderId : uuid ( 'order_id' )
421+ . notNull ( )
422+ . references ( ( ) => orders . id , { onDelete : 'cascade' } ) ,
423+ provider : text ( 'provider' ) . notNull ( ) ,
424+ eventName : text ( 'event_name' ) . notNull ( ) ,
425+ eventSource : text ( 'event_source' ) . notNull ( ) ,
426+ eventRef : text ( 'event_ref' ) ,
427+ attemptId : uuid ( 'attempt_id' ) . references ( ( ) => paymentAttempts . id , {
428+ onDelete : 'set null' ,
429+ } ) ,
430+ providerPaymentIntentId : text ( 'provider_payment_intent_id' ) ,
431+ providerChargeId : text ( 'provider_charge_id' ) ,
432+ amountMinor : bigint ( 'amount_minor' , { mode : 'number' } ) . notNull ( ) ,
433+ currency : currencyEnum ( 'currency' ) . notNull ( ) ,
434+ payload : jsonb ( 'payload' )
435+ . $type < Record < string , unknown > > ( )
436+ . notNull ( )
437+ . default ( sql `'{}'::jsonb` ) ,
438+ dedupeKey : text ( 'dedupe_key' ) . notNull ( ) ,
439+ occurredAt : timestamp ( 'occurred_at' , { withTimezone : true } )
440+ . notNull ( )
441+ . defaultNow ( ) ,
442+ createdAt : timestamp ( 'created_at' , { withTimezone : true } )
443+ . notNull ( )
444+ . defaultNow ( ) ,
445+ } ,
446+ t => [
447+ uniqueIndex ( 'payment_events_dedupe_key_uq' ) . on ( t . dedupeKey ) ,
448+ index ( 'payment_events_order_id_idx' ) . on ( t . orderId ) ,
449+ index ( 'payment_events_attempt_id_idx' ) . on ( t . attemptId ) ,
450+ index ( 'payment_events_event_ref_idx' ) . on ( t . eventRef ) ,
451+ index ( 'payment_events_occurred_at_idx' ) . on ( t . occurredAt ) ,
452+ ]
453+ ) ;
454+
455+ export const shippingEvents = pgTable (
456+ 'shipping_events' ,
457+ {
458+ id : uuid ( 'id' ) . defaultRandom ( ) . primaryKey ( ) ,
459+ orderId : uuid ( 'order_id' )
460+ . notNull ( )
461+ . references ( ( ) => orders . id , { onDelete : 'cascade' } ) ,
462+ shipmentId : uuid ( 'shipment_id' ) . references ( ( ) => shippingShipments . id , {
463+ onDelete : 'set null' ,
464+ } ) ,
465+ provider : text ( 'provider' ) . notNull ( ) ,
466+ eventName : text ( 'event_name' ) . notNull ( ) ,
467+ eventSource : text ( 'event_source' ) . notNull ( ) ,
468+ eventRef : text ( 'event_ref' ) ,
469+ statusFrom : text ( 'status_from' ) ,
470+ statusTo : text ( 'status_to' ) ,
471+ trackingNumber : text ( 'tracking_number' ) ,
472+ payload : jsonb ( 'payload' )
473+ . $type < Record < string , unknown > > ( )
474+ . notNull ( )
475+ . default ( sql `'{}'::jsonb` ) ,
476+ dedupeKey : text ( 'dedupe_key' ) . notNull ( ) ,
477+ occurredAt : timestamp ( 'occurred_at' , { withTimezone : true } )
478+ . notNull ( )
479+ . defaultNow ( ) ,
480+ createdAt : timestamp ( 'created_at' , { withTimezone : true } )
481+ . notNull ( )
482+ . defaultNow ( ) ,
483+ } ,
484+ t => [
485+ uniqueIndex ( 'shipping_events_dedupe_key_uq' ) . on ( t . dedupeKey ) ,
486+ index ( 'shipping_events_order_id_idx' ) . on ( t . orderId ) ,
487+ index ( 'shipping_events_shipment_id_idx' ) . on ( t . shipmentId ) ,
488+ index ( 'shipping_events_occurred_at_idx' ) . on ( t . occurredAt ) ,
489+ ]
490+ ) ;
491+
492+ export const adminAuditLog = pgTable (
493+ 'admin_audit_log' ,
494+ {
495+ id : uuid ( 'id' ) . defaultRandom ( ) . primaryKey ( ) ,
496+ orderId : uuid ( 'order_id' ) . references ( ( ) => orders . id , {
497+ onDelete : 'set null' ,
498+ } ) ,
499+ actorUserId : text ( 'actor_user_id' ) . references ( ( ) => users . id , {
500+ onDelete : 'set null' ,
501+ } ) ,
502+ action : text ( 'action' ) . notNull ( ) ,
503+ targetType : text ( 'target_type' ) . notNull ( ) ,
504+ targetId : text ( 'target_id' ) . notNull ( ) ,
505+ requestId : text ( 'request_id' ) ,
506+ payload : jsonb ( 'payload' )
507+ . $type < Record < string , unknown > > ( )
508+ . notNull ( )
509+ . default ( sql `'{}'::jsonb` ) ,
510+ dedupeKey : text ( 'dedupe_key' ) . notNull ( ) ,
511+ occurredAt : timestamp ( 'occurred_at' , { withTimezone : true } )
512+ . notNull ( )
513+ . defaultNow ( ) ,
514+ createdAt : timestamp ( 'created_at' , { withTimezone : true } )
515+ . notNull ( )
516+ . defaultNow ( ) ,
517+ } ,
518+ t => [
519+ uniqueIndex ( 'admin_audit_log_dedupe_key_uq' ) . on ( t . dedupeKey ) ,
520+ index ( 'admin_audit_log_order_id_idx' ) . on ( t . orderId ) ,
521+ index ( 'admin_audit_log_actor_user_id_idx' ) . on ( t . actorUserId ) ,
522+ index ( 'admin_audit_log_occurred_at_idx' ) . on ( t . occurredAt ) ,
523+ ]
524+ ) ;
525+
416526export const monobankRefunds = pgTable (
417527 'monobank_refunds' ,
418528 {
@@ -837,6 +947,9 @@ export type DbInternalJobState = typeof internalJobState.$inferSelect;
837947export type DbPaymentAttempt = typeof paymentAttempts . $inferSelect ;
838948export type DbApiRateLimit = typeof apiRateLimits . $inferSelect ;
839949export type DbMonobankEvent = typeof monobankEvents . $inferSelect ;
950+ export type DbPaymentEvent = typeof paymentEvents . $inferSelect ;
951+ export type DbShippingEvent = typeof shippingEvents . $inferSelect ;
952+ export type DbAdminAuditLog = typeof adminAuditLog . $inferSelect ;
840953export type DbMonobankRefund = typeof monobankRefunds . $inferSelect ;
841954export type DbMonobankPaymentCancel =
842955 typeof monobankPaymentCancels . $inferSelect ;
0 commit comments