update model_artifacts a
set package_format='builtin',
    lifecycle_status='released',
    validation_status='passed',
    released_at=coalesce(a.released_at, a.created_at)
from model_versions v
where v.id=a.model_version_id
  and (v.model_group='pointcloud-analyzer' or lower(a.artifact_type) like 'open3d%');

update model_runtime_deployments d
set desired_artifact_id=a.id,
    installed_artifact_id=a.id,
    artifact_sync_status='ready',
    updated_at=now()
from model_artifacts a
join model_versions v on v.id=a.model_version_id
where d.model_version_id=v.id
  and (v.model_group='pointcloud-analyzer' or lower(a.artifact_type) like 'open3d%');

insert into model_artifact_installations(
    id, artifact_id, runtime_deployment_id, runtime_node_id, status,
    install_path, installed_manifest, loaded, installed_at, last_verified_at
)
select 'install-' || substr(md5(d.id || a.id), 1, 18), a.id, d.id, 'builtin', 'ready',
       'builtin://open3d-geometry', '{"runtime_component":true}'::jsonb, true, now(), now()
from model_runtime_deployments d
join model_artifacts a on a.id=d.installed_artifact_id
join model_versions v on v.id=a.model_version_id
where v.model_group='pointcloud-analyzer' or lower(a.artifact_type) like 'open3d%'
on conflict (artifact_id, runtime_deployment_id, runtime_node_id) do update
set status='ready', loaded=true, last_verified_at=now(), updated_at=now();
