CREATE TABLE IF NOT EXISTS mci_message_media (
    id BIGINT AUTO_INCREMENT PRIMARY KEY,
    tenant_code VARCHAR(64) NOT NULL COMMENT '所属租户',
    msgid VARCHAR(128) COMMENT '关联的消息 ID',
    sdkfileid VARCHAR(256) COMMENT '企微媒体文件 ID',
    media_type VARCHAR(32) COMMENT '媒体类型：image / voice / video / file / emotion',
    file_name VARCHAR(256) COMMENT '文件名',
    file_size BIGINT COMMENT '文件大小',
    md5sum VARCHAR(64) COMMENT 'MD5',
    storage_type TINYINT NOT NULL DEFAULT 2 COMMENT '存储类型：2SeaweedFS',
    bucket VARCHAR(128) COMMENT 'SeaweedFS bucket',
    object_key VARCHAR(512) COMMENT 'SeaweedFS object key',
    access_url VARCHAR(512) COMMENT '访问 URL',
    status TINYINT NOT NULL DEFAULT 0 COMMENT '状态：0未下载 1下载中 2已下载 3下载失败',
    create_time DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
    update_time DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
    deleted TINYINT NOT NULL DEFAULT 0,
    KEY idx_tenant_msgid (tenant_code, msgid),
    KEY idx_status (status)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='媒体文件表';
