]> pd.if.org Git - zpackage/blob - schema/syncinfo.sql
remove stray debug fprintf
[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 -- but we have to calculate them separately I think.
31 -- once for new, once for update, and once for no-op, might be able
32 -- to combine update and no-op
33 select
34 'new' as op,
35         printf('%s-%s-%s', PFI.package, PFI.version, PFI.release) as pkgid,
36         PFI.path, PFI.username, PFI.uid, PFI.groupname, PFI.gid, PFI.mode,
37         PFI.filetype, PFI.mtime, PFI.hash,
38         PFI.configuration
39         -- + case when PFC.configuration = 1 then 2 else 0 end
40         as configuration,
41         PFI.target, PFI.device, null as ohash,
42         printf('%s:%s:%s:%s', PFI.filetype, PFI.mode, PFI.username, PFI.groupname) as mds,
43         --printf('%s:%s:%s:%s', PFC.filetype, PFC.mode, PFC.username, PFC.groupname) as omds
44         null as omds
45 from
46
47 packagefiles PFI
48 join packages PI
49 on PFI.package = PI.package and PFI.version = PI.version and PFI.release = PI.release
50
51 /*
52 left join packagefiles PFC on PFI.path = PFC.path
53
54 left join packages PC
55 on (PFI.package is not PC.package or PFI.release is not PC.release or PC.version is not PFI.version)
56 and PC.status in ('installed','removing','updating')
57 and PFC.package = PC.package and PFC.version = PC.version and PFC.release = PC.release
58 */
59
60 where
61 PI.status = 'installing'
62 and
63 not exists (select PFC.path
64         from packagefiles PFC
65         join packages PC
66 on PFC.package = PC.package and PFC.version = PC.version and PFC.release = PC.release
67         where PFC.path = PFI.path
68         and PC.status in ('installed','removing','updating')
69 )
70
71 /*
72 (PFC.path is null
73         or
74 PC.status not in ('installed','removing','updating')
75 )
76 */
77
78 union
79 select
80 case
81 when PFI.filetype is not 'l'
82         and PFI.filetype is PFC.filetype
83         and PFI.mode is PFC.mode and PFI.username is PFC.username
84         and PFI.groupname is PFC.groupname and PFI.hash is PFC.hash
85         then 'noop'
86 when PFI.filetype is 'l'
87         and PFI.target is PFC.target
88         and PFI.filetype is PFC.filetype
89         and PFI.mode is PFC.mode and PFI.username is PFC.username
90         and PFI.groupname is PFC.groupname and PFI.hash is PFC.hash
91         then 'noop'
92 when PC.status = 'installed' then 'md conflict'
93 else 'update'
94 end as op,
95         printf('%s-%s-%s', PFI.package, PFI.version, PFI.release) as pkgid,
96         PFI.path, PFI.username, PFI.uid, PFI.groupname, PFI.gid, PFI.mode,
97         PFI.filetype, PFI.mtime, PFI.hash,
98         PFI.configuration + case when PFC.configuration = 1 then 2 else 0 end
99         as configuration,
100         PFI.target, PFI.device, PFC.hash as ohash,
101         printf('%s:%s:%s:%s', PFI.filetype, PFI.mode, PFI.username, PFI.groupname) as mds,
102         printf('%s:%s:%s:%s', PFC.filetype, PFC.mode, PFC.username, PFC.groupname) as omds
103 from
104
105 packagefiles PFI
106 join packages P
107 on PFI.package = P.package and PFI.version = P.version and PFI.release = P.release
108
109 join packagefiles PFC on PFI.path = PFC.path
110
111 join packages PC
112 on (PFI.package is not PC.package or PFI.release is not PC.release or PC.version is not PFI.version)
113 -- er, no, it's a conflict if it's in installed and it doesn't match
114 and PC.status in ('installed','updating','removing')
115 and PFC.package = PC.package and PFC.version = PC.version and PFC.release = PC.release
116
117 where
118 P.status = 'installing'
119 --and PFC.path is not null
120
121 -- every path in updating and removing is either remove or no-op
122 -- not true, could be an update, but should be handled above
123 union
124 select 'remove',
125         printf('%s-%s-%s', PFR.package, PFR.version, PFR.release) as pkgid,
126         PFR.path, 
127         PFR.username, PFR.uid, PFR.groupname, PFR.gid, PFR.mode, PFR.filetype,
128         PFR.mtime, PFR.hash,
129         PFR.configuration, 
130         --PFR.target, coalesce(P.status, ' null status '), --PFR.device,
131         -- PFI.path, coalesce(PFI.status, ' null status '), --PFR.device,
132         PFR.target, PFR.device,
133         null as ohash,
134         --PFI.package,
135         printf('%s:%s:%s:%s', PFR.filetype, PFR.mode, PFR.username, PFR.groupname) as mds,
136         null as omds
137 from packagefiles PFR
138 join packages PU
139 on PFR.package = PU.package and PFR.version = PU.version and PFR.release = PU.release
140 and PU.status in ('removing','updating')
141
142 where
143 not exists (select path from
144         packagefiles PFI
145         join packages P
146         on PFI.package = P.package and PFI.version = P.version and PFI.release = P.release and P.status in ('installing','installed')
147         where PFI.path = PFR.path
148
149 )
150 and path not in (select path from preserve)
151
152 -- paths in 'installed' or 'updated' are no-ops
153
154 union
155 select 'preserve',
156         printf('%s-%s-%s', PFP.package, PFP.version, PFP.release) as pkgid,
157         PFP.path, 
158         PFP.username, PFP.uid, PFP.groupname, PFP.gid, PFP.mode, PFP.filetype,
159         PFP.mtime, PFP.hash,
160         PFP.configuration as configuration,
161         PFP.target, PFP.device,
162         null as ohash,
163         printf('%s:%s:%s:%s', PFP.filetype, PFP.mode, PFP.username, PFP.groupname) as mds,
164         null as omds
165 from preserve PFP
166         -- TODO don't include installed or installing
167         -- left join packages P on P.package = PFP.package ...
168         -- where P.status not in ('installed','installing')
169 ;