alter table model_runtime_deployments
    add column if not exists connectivity_status varchar(32) not null default 'unknown',
    add column if not exists connectivity_message text,
    add column if not exists last_connectivity_at timestamptz;

update model_runtime_deployments
set connectivity_status = case
        when health_status = 'unreachable' then 'unreachable'
        when health_status in ('healthy', 'degraded', 'incompatible') then 'connected'
        else 'unknown'
    end,
    connectivity_message = case
        when health_status = 'unreachable' then health_message
        when health_status in ('healthy', 'degraded', 'incompatible') then '服务连接正常'
        else null
    end,
    last_connectivity_at = last_health_at
where last_health_at is not null;
