db.changelog.20210331-fix-resource-with-metadata-view.yml Maven / Gradle / Ivy
databaseChangeLog:
- changeSet:
id: fix-resource-with-metadata-view
author: fletch
changes:
- dropView:
viewName: resource_with_metadata
- createView:
viewName: resource_with_metadata
selectQuery: |
select
resource.uid,
resource.id,
resource.application,
resource.kind,
json_object(
'uid', resource.uid,
'id', resource.id,
'version', resource.version,
'application', resource.application,
'environment', latest_environment.uid,
'environmentName', latest_environment.name,
'deliveryConfig', delivery_config.uid,
'serviceAccount', delivery_config.service_account
) as metadata,
resource.spec
from resource
left join environment_resource on resource.uid = environment_resource.resource_uid
join latest_environment on latest_environment.uid = environment_resource.environment_uid and latest_environment.version = environment_resource.environment_version
left join delivery_config on delivery_config.uid = latest_environment.delivery_config_uid
where resource.version = (select max(r2.version) from resource r2 where resource.id = r2.id)