]> pd.if.org Git - zpackage/blob - schema/syncinfo.sql
fix syncinfo
[zpackage] / schema / syncinfo.sql
1 create view syncinfo as
2 with
3 -- paths to libraries we need to keep around
4 preserve as (
5 select
6 PFL.*
7 from packagefiles PFL
8 join elflibraries EL on EL.file = PFL.hash
9 join elfneeded EN on EN.needed = EL.soname
10 join packagefiles PFN on EN.file = PFN.hash
11 join packages PN
12 on PFN.package = PN.package and PFN.version = PN.version and PFN.release = PN.release
13 where
14 PN.status = 'installing' or PN.status = 'installed'
15 and not (PFN.package = PFL.package and PFN.version = PFN.version and PFN.release = PFL.release)
16 ),
17 waspreserved as (
18         select PF.path
19         from packagefiles PF
20         join elflibraries EL on EL.file = PF.hash
21         join elfneeded EN on EN.needed = EL.soname
22         join packagefiles PL on EN.file = PL.hash
23         join packages P
24         on PL.path = P.package and PL.version = P.version and PL.release = P.release
25         where
26         P.status = 'removing' or P.status = 'installed' or P.status = 'updating'
27 )
28
29 -- every path in 'installing' is either new or update, or no-op
30 select
31 case when --PFC.path is null
32         P.status is null
33         and PFC.path not in (select path from waspreserved)
34         -- if the path is in preserved, this will an update with no old md.
35         then 'new'
36 when PFI.filetype is PFC.filetype
37         and PFI.mode is PFC.mode and PFI.username is PFC.username
38         and PFI.groupname is PFC.groupname and PFI.hash is PFC.hash
39         then 'noop'
40 else 'update'
41 end as op,
42         printf('%s-%s-%s', PFI.package, PFI.version, PFI.release) as pkgid,
43         PFI.path, PFI.username, PFI.uid, PFI.groupname, PFI.gid, PFI.mode,
44         PFI.filetype, PFI.mtime, PFI.hash,
45         PFI.configuration + case when PFC.configuration = 1 then 2 else 0 end
46         as configuration,
47         PFI.target, PFI.device, PFC.hash as ohash,
48         printf('%s:%s:%s:%s', PFI.filetype, PFI.mode, PFI.username, PFI.groupname) as mds,
49         printf('%s:%s:%s:%s', PFC.filetype, PFC.mode, PFC.username, PFC.groupname) as omds
50 from
51 packagefiles PFI
52 join packages PI
53 on PFI.package = PI.package and PFI.version = PI.version and PFI.release = PI.release
54 left join packagefiles PFC on PFI.path = PFC.path
55 and (PFI.package is not PFC.package or PFI.release is not PFC.release or PFC.version is not PFI.version)
56 left join packages P 
57         on PFC.package = P.package and PFC.version = P.version and PFC.release = P.release
58 and P.status in ('installed','removing','updating')
59 where
60 PI.status = 'installing'
61 and (
62         --P.status is null or
63         PFC.path is null
64         or
65         P.status in ('installed','removing','updating')
66 )
67
68 -- every path in updating and removing is either remove or no-op
69 -- not true, could be an update, but should be handled above
70 union
71 select 'remove',
72         printf('%s-%s-%s', PFR.package, PFR.version, PFR.release) as pkgid,
73         PFR.path, 
74         PFR.username, PFR.uid, PFR.groupname, PFR.gid, PFR.mode, PFR.filetype,
75         PFR.mtime, PFR.hash,
76         PFR.configuration, 
77         --PFR.target, coalesce(P.status, ' null status '), --PFR.device,
78         -- PFI.path, coalesce(PFI.status, ' null status '), --PFR.device,
79         PFR.target, PFR.device,
80         null as ohash,
81         --PFI.package,
82         printf('%s:%s:%s:%s', PFR.filetype, PFR.mode, PFR.username, PFR.groupname) as mds,
83         null as omds
84 from packagefiles PFR
85 join packages PU
86 on PFR.package = PU.package and PFR.version = PU.version and PFR.release = PU.release and PU.status in ('removing','updating')
87
88 where
89 not exists (select path from
90         packagefiles PFI
91         join packages P
92         on PFI.package = P.package and PFI.version = P.version and PFI.release = P.release and P.status in ('installing','installed')
93         where PFI.path = PFR.path
94
95 )
96
97 -- paths in 'installed' or 'updated' are no-ops
98
99 union
100 select 'preserve',
101         printf('%s-%s-%s', PFP.package, PFP.version, PFP.release) as pkgid,
102         PFP.path, 
103         PFP.username, PFP.uid, PFP.groupname, PFP.gid, PFP.mode, PFP.filetype,
104         PFP.mtime, PFP.hash,
105         PFP.configuration as configuration,
106         PFP.target, PFP.device,
107         null as ohash,
108         printf('%s:%s:%s:%s', PFP.filetype, PFP.mode, PFP.username, PFP.groupname) as mds,
109         null as omds
110 from preserve PFP
111         -- TODO don't include installed or installing
112         -- left join packages P on P.package = PFP.package ...
113         -- where P.status not in ('installed','installing')
114 ;