]> pd.if.org Git - zpackage/blob - db.sql
add views useful for installs and uninstalls
[zpackage] / db.sql
1 begin;
2
3 PRAGMA application_id = 0x5a504442;
4 PRAGMA user_version = 1;
5
6 -- should be faster with rowid due to the blob content
7 -- these are really just blobs of data
8 -- TODO copyright and license information should probably
9 -- go here
10 CREATE TABLE files (
11         hash text primary key, -- sha256 of content
12         size integer, -- bigint?  certainly need > 2GB
13         compression text, -- always xz?
14         content blob
15 )
16 ;
17
18 -- information about packages
19 -- a package is identified by a package,version,release triple
20 create table packages (
21         -- primary key columns
22         package text,
23         version text, -- the upstream version string
24         release integer, -- the local release number
25         pkgid   text, -- the three above joined with '-'
26
27         -- metadata columns
28         description     text,
29         architecture    text,
30         url     text,
31         status  text,
32         licenses        text, -- hash of actual license?  need table for more than one?
33         packager        text,
34         build_time      integer default (strftime('%s', 'now')),
35         install_time    integer,
36         checksum        text, -- checksum of package contents.  null for incompleted packages
37         primary key (package,version,release),
38         check (typeof(release) = 'integer'),
39         check (release > 0)
40         -- TODO enforce name and release conventions
41 )
42 without rowid
43 ;
44
45 -- handle package status history with a logging trigger.
46 create trigger logpkgstatus after update of status on packages
47 begin insert into zpmlog (action,target,info)
48         values (printf('status change %s %s', OLD.status, NEW.status),
49                 printf('%s-%s-%s', NEW.package, NEW.version, NEW.release),
50                 NULL); END;
51
52 create table packagetags (
53         -- package id triple
54         package text,
55         version text,
56         release integer,
57         tag     text,
58         set_time integer default (strftime('%s', 'now')),
59         primary key (package,version,release,tag),
60         foreign key (package,version,release) references packages (package,version,release) on delete cascade
61 );
62
63 -- packagefile hash is columns as text, joined with null bytes, then
64 -- sha256 sum of that
65 -- package checksum is package columns as text, joined with null bytes,
66 -- other than the checksum and install_time column
67 -- then that hashed.  finally, that hash, plus the ascii sorted
68 -- hashes of the package files all joined with newlines, hashed.
69 -- really don't like this.
70
71 -- files contained in a package
72 create table packagefiles (
73         -- package id triple
74         package text,
75         version text,
76         release integer,
77
78         path    text, -- filesystem path
79         mode    text, -- perms, use text for octal rep?
80         username        text, -- name of owner
81         groupname       text, -- group of owner
82         uid     integer, -- numeric uid, generally ignored
83         gid     integer, -- numeric gid, generally ignored
84         filetype varchar default 'r',
85         -- r regular file
86         -- d directory
87         -- s symlink
88         -- h hard link -- not supported
89         -- c character special and b device special files add dev number column
90         -- b block special
91         -- p fifos (i.e. pipe)
92         target  text, -- link target for links
93         -- device file dev numbers, should probably be a separate table
94         devmajor        integer,
95         devminor        integer,
96         hash    text, -- null if no actual content, i.e. anything but a regular file
97         mtime   integer, -- seconds since epoch, finer resolution probably not needed
98         primary key (package,version,release,path),
99         foreign key (package,version,release) references packages (package,version,release) on delete cascade
100 )
101 without rowid
102 ;
103
104 create view installedfiles as
105 select PF.package, PF.version, PF.release,
106 printf('%s-%s-%s', PF.package, PF.version, PF.release) as pkgid,
107 PF.path, PF.hash, PF.filetype
108 from packagefiles PF
109 left join packages P
110 on P.package = PF.package and P.version = PF.version and P.release = PF.release
111 where
112 P.status = 'installed'
113 ;
114
115 create view installed_ref_count as
116 select I.path, count(*) as refcount
117 from installedfiles I
118 group by I.path
119 ;
120
121 create table pathtags (
122         -- package id triple
123         package text,
124         version text,
125         release integer,
126
127         path    text, -- filesystem path
128         tag     text,
129         primary key (package,version,release,path,tag)
130 )
131 without rowid
132 ;
133
134 create table elfinfo (
135         file    text primary key, -- hash of blob
136         elftype text,
137         foreign key (file) references files on delete cascade
138 )
139 without rowid
140 ;
141
142 create table elfdeps (
143         file    text,
144         soname  text,
145         dependency text,
146         primary key (file, soname, dependency),
147         foreign key (file) references files on delete cascade
148 )
149 without rowid
150 ;
151
152 -- TODO just elf information?
153 -- and just hash, not package?
154 create table elflibraries (
155         file    text primary key,
156         soname  text,
157         foreign key (file) references files on delete cascade
158 )
159 without rowid
160 ;
161
162 create table elfneeded (
163         file    text,
164         needed  text, -- soname of dependency
165         primary key (file, needed),
166         foreign key (file) references files on delete cascade
167 )
168 without rowid
169 ;
170
171 -- package scripts: table of package, stage, file
172 create table scripts (
173         package text,
174         version text,
175         release integer,
176         stage   text,
177         hash    text
178 );
179
180 -- package dependencies: table of package, dependency, dep type (package, soname)
181 create table packagedeps (
182         package text,
183         version text,
184         release integer,
185         required        text, -- package name
186         -- following can be null for not checked
187         minversion      text,
188         minrelease      integer,
189         maxversion      text,
190         maxrelease      integer
191 );
192
193 -- capability labels
194 create table provides (
195         package text,
196         subpackage      text,
197         label   text -- a capability label
198 );
199
200 create table requires (
201         package text,
202         subpackage      text,
203         label   text -- a capability label
204 );
205
206 create table packagegroups (
207         package text,
208         "group" text
209 );
210
211 -- zpm actions
212 -- not sure how machine readable this needs to be,
213 -- do not at all for now, figure it out later
214 -- could be worth logging all commands in a history table,
215 -- the zpm driver could do that and capture the exit status
216 -- as well
217 -- might want the history table to note a "group" to tie together
218 -- sub-invocations, probably an environment variable set if not
219 -- already set by zpm, probably a uuid or a timestamp
220 create table zpmlog (
221         ts      text default (strftime('%Y-%m-%d %H:%M:%f', 'now')),
222         -- timestamp of action
223         action  text,
224         target  text, -- packagename, repo name, etc
225         info    text -- human readable
226 );
227
228 create table history (
229         ts      integer, -- again, probably needs timestamp sub second
230         cmd     text,
231         args    text,
232         status  integer
233 );
234
235 create table repository (
236         name    text primary key, -- our name for a repo
237         url     text not null,
238         priority        integer not null default 1,
239         refreshed       integer -- last refresh time
240 );
241
242 -- urls for downloading packages.  possibly unneeded
243 create table repository_packages (
244         repo    text,
245         pkg     text, -- glob pattern?  in which case others not needed
246         version text,
247         release text,
248         url     text
249 );
250
251 -- track which repository a package was cloned from, i.e. where we got it
252 create table packagesource (
253         name    text,
254         version text,
255         release integer,
256         repository      text references repository
257 );
258
259 commit;