CREATE TABLE IF NOT EXISTS `Message_Outbox` (
  `Id` bigint NOT NULL,
  `Exchange` varchar(200) NOT NULL,
  `Queue` varchar(200) NOT NULL,
  `RoutingKey` varchar(200) NOT NULL,
  `Payload` json NOT NULL,
  `RetryCount` int NOT NULL DEFAULT 0,
  `NextRetryAt` datetime NULL,
  `SentAt` datetime NULL,
  `LastError` varchar(2000) NULL,
  `BusinessType` varchar(100) NOT NULL,
  `BusinessId` bigint NOT NULL,
  `Status` int NOT NULL DEFAULT 0,
  `IsDeleted` bit NOT NULL DEFAULT b'0',
  `CreatedBy` varchar(100) NOT NULL,
  `CreatedAt` datetime NOT NULL,
  `UpdatedBy` varchar(100) NULL,
  `UpdatedAt` datetime NULL,
  PRIMARY KEY (`Id`),
  KEY `idx_message_outbox_status_next_retry` (`Status`, `NextRetryAt`, `CreatedAt`),
  KEY `idx_message_outbox_business` (`BusinessType`, `BusinessId`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
