X-Git-Url: https://pd.if.org/git/?a=blobdiff_plain;f=db.sql;h=b1343d00a3b6a7f829452af0868f1de2c04798e1;hb=47b298c6557161ff7e46a778de693268cf9230cc;hp=658865031684e5ad4c943ac3177c446b9e4e8a4e;hpb=1323381f0eeb38466d8afc185a5295e4b5024bd5;p=zpackage diff --git a/db.sql b/db.sql index 6588650..b1343d0 100644 --- a/db.sql +++ b/db.sql @@ -157,6 +157,7 @@ create table packagefiles ( check (not (filetype = 'h' and target is null)), check (target is null or length(target) between 1 and 4095), check (hash is null or length(hash) between 1 and 1024), + check (path not in ('.', '..')), check (not (filetype = 'r' and hash is null)), check (not (filetype = 'c' and device is null)), check (not (filetype = 'b' and device is null)), @@ -171,6 +172,7 @@ without rowid create index packagefile_package_index on packagefiles (package); create index packagefile_path_index on packagefiles (path); create index packagefile_hash_index on packagefiles (hash); +create index pkgfile_configuration on packagefiles (configuration) where configuration = 1; create view packagefiles_pkgid as select printf('%s-%s-%s', package, version, release) as pkgid, *, @@ -416,46 +418,32 @@ create table packagesource ( ); create view syncconflicts as -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' -), +with -- metadata different md_conflict as ( - select path, count(distinct mds) as mdcount, - count(distinct hash) as hashcount - from syncstatus SS - where SS.rstatus in ('installing', 'installed') + select path, count(distinct + printf('%s:%s:%s:%s', PFA.filetype, PFA.mode, PFA.username, PFA.groupname)) as mdcount, + count(distinct PFA.hash) as hashcount + from packagefiles PFA + join packages PA + on PA.package = PFA.package and PA.version = PFA.version and PA.release = PFA.release + where PA.status in ('installing', 'installed') group by path - having (count(distinct mds) > 1 or count(distinct hash) > 1) + having (count(distinct printf('%s:%s:%s:%s', PFA.filetype, PFA.mode, PFA.username, PFA.groupname) + ) > 1 or count(distinct PFA.hash) > 1) ) -select BASE.*, 'hash' as conflict -from syncstatus BASE +select PFH.*, + printf('%s-%s-%s', PFH.package, PFH.version, PFH.release) as pkgid, + printf('%s:%s:%s:%s', PFH.filetype, PFH.mode, PFH.username, PFH.groupname) as mds, +'hash' as conflict +from packagefiles PFH where path in (select path from md_conflict where hashcount > 1) union -select BASE.*, 'md' as conflict -from syncstatus BASE +select PFM.*, + printf('%s-%s-%s', PFM.package, PFM.version, PFM.release) as pkgid, + printf('%s:%s:%s:%s', PFM.filetype, PFM.mode, PFM.username, PFM.groupname) as mds, +'md' as conflict +from packagefiles PFM where path in (select path from md_conflict where mdcount > 1) ; @@ -628,6 +616,9 @@ select 'preserve', printf('%s:%s:%s:%s', PFP.filetype, PFP.mode, PFP.username, PFP.groupname) as mds, null as omds from preserve PFP + -- TODO don't include installed or installing + -- left join packages P on P.package = PFP.package ... + -- where P.status not in ('installed','installing') ; commit;