-with
-preserved as (
- select BASE.*, 'preserved' as rstatus
- from packagefiles_status BASE
- join elflibraries EL on EL.file = BASE.hash
- where
- BASE.status in ('removed', 'updated')
- and BASE.hash in (select hash from packagefiles_status where
- status in ('installed'))
-),
-syncstatus as (
- select distinct BASE.*,
- case when P.status = 'installing' and BASE.status = 'installed'
- then 'updating'
- when BASE.status in ('removed','updated')
- and BASE.path in (select path from preserved) then
- 'preserved'
- else
- BASE.status
- end as rstatus
- from packagefiles_status BASE
- left join packages P on P.package = BASE.package
- and BASE.status in ('installed', 'removing')
- and P.status = 'installing'
-),