CREATE TABLE IF NOT EXISTS image_upscale_queue (
    id BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
    scope_type VARCHAR(32) NOT NULL,
    scope_id BIGINT UNSIGNED NULL,
    asset_type VARCHAR(64) NOT NULL,
    asset_id BIGINT UNSIGNED NOT NULL,
    asset_key VARCHAR(64) NOT NULL DEFAULT 'primary',
    source_path TEXT NOT NULL,
    source_sha256 CHAR(64) NOT NULL,
    scale SMALLINT UNSIGNED NOT NULL DEFAULT 2,
    status VARCHAR(32) NOT NULL,
    remote_job_id VARCHAR(128) NULL,
    queue_position INT NULL,
    stage_progress DECIMAL(8,6) NULL,
    error_code VARCHAR(128) NULL,
    error_message TEXT NULL,
    requested_at DATETIME NOT NULL,
    started_at DATETIME NULL,
    completed_at DATETIME NULL,
    updated_at DATETIME NOT NULL,
    KEY idx_upscale_asset_current (asset_type,asset_id,asset_key,source_sha256,scale),
    KEY idx_upscale_status (status),
    KEY idx_upscale_remote_job (remote_job_id),
    KEY idx_upscale_scope (scope_type,scope_id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
