You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
virt/web/sql/ticket_telegram_replies.sql

24 lines
1.4 KiB
SQL

-- Add durable Telegram notification-to-ticket mappings before deploying the
-- two-way administrator ticket bridge. No existing ticket or binding rows are
-- rewritten; the first post-upgrade notification assigns a binding generation.
CREATE TABLE IF NOT EXISTS `ticket_telegram_deliveries` (
`id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
`binding_generation` char(32) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,
`bound_admin_id` bigint(20) NOT NULL,
`chat_id` varchar(20) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,
`ticket_id` bigint(20) NOT NULL,
`ticket_message_id` bigint(20) NOT NULL,
`event_kind` varchar(24) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,
`telegram_message_id` bigint(20) unsigned DEFAULT NULL,
`state` varchar(16) CHARACTER SET ascii COLLATE ascii_bin NOT NULL DEFAULT 'dispatching',
`content_hash` char(64) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,
`created_at` bigint(20) unsigned NOT NULL DEFAULT 0,
`sent_at` bigint(20) unsigned DEFAULT NULL,
`updated_at` bigint(20) unsigned NOT NULL DEFAULT 0,
PRIMARY KEY (`id`),
UNIQUE KEY `ticket_telegram_event` (`binding_generation`,`ticket_message_id`,`event_kind`),
UNIQUE KEY `ticket_telegram_message` (`binding_generation`,`chat_id`,`telegram_message_id`),
KEY `ticket_telegram_ticket` (`ticket_id`,`ticket_message_id`),
KEY `ticket_telegram_admin` (`bound_admin_id`,`created_at`,`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;