CREATE TABLE IF NOT EXISTS `helpdesk_updates` (
    `id`            BIGINT UNSIGNED  NOT NULL AUTO_INCREMENT,
    `tenant_id`     INT UNSIGNED     NOT NULL,
    `ticket_no`     VARCHAR(30)      NOT NULL,
    `category_code` VARCHAR(30)      NOT NULL,
    `debitor_no`    VARCHAR(30)      NOT NULL,
    `debitor_name`  VARCHAR(255)     NOT NULL DEFAULT '',
    `domain_no`     VARCHAR(30)      NOT NULL DEFAULT '',
    `domain_url`    VARCHAR(255)     NOT NULL DEFAULT '',
    `gitea_path`    VARCHAR(255)     NOT NULL DEFAULT '',
    `notes`         TEXT             NULL     DEFAULT NULL,
    `status`        VARCHAR(20)      NOT NULL DEFAULT 'open',
    `created_by`    INT UNSIGNED     NOT NULL,
    `updated_by`    INT UNSIGNED     NULL     DEFAULT NULL,
    `created_at`    DATETIME         NOT NULL DEFAULT CURRENT_TIMESTAMP,
    `updated_at`    DATETIME         NULL     DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
    PRIMARY KEY (`id`),
    UNIQUE KEY `uq_hu_ticket`  (`tenant_id`, `ticket_no`),
    KEY `idx_hu_tenant`        (`tenant_id`),
    KEY `idx_hu_domain`        (`tenant_id`, `domain_no`),
    KEY `idx_hu_status`        (`tenant_id`, `status`),
    KEY `idx_hu_debitor`       (`tenant_id`, `debitor_no`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
