X-Git-Url: https://pd.if.org/git/?a=blobdiff_plain;f=db.sql;h=d4f2d3e0f1d12200a4d497da31c6a5e5aa409330;hb=82b289d233b84181e0a926a7b1085a321e7eb163;hp=bf6fd22a07c01b886d9d6e26a9dc1557d5132c03;hpb=1543353d5f552717ef55bea0a70f5ef80072ce3d;p=zpackage diff --git a/db.sql b/db.sql index bf6fd22..d4f2d3e 100644 --- a/db.sql +++ b/db.sql @@ -52,6 +52,8 @@ create table packages ( without rowid ; +create index package_status_index on packages (status); + create view packages_pkgid as select printf('%s-%s-%s', package, version, release) as pkgid, * from packages; @@ -137,22 +139,60 @@ create table packagefiles ( foreign key (package,version,release) references packages (package,version,release) on delete cascade on update cascade, check (not (filetype = 'l' and target is null)), check (not (filetype = 'r' and hash is null)), - check (not (filetype = 'c' and (devmajor is null or devminor is null))) + check (not (filetype = 'c' and (devmajor is null or devminor is null))), + check (not (filetype = 'b' and (devmajor is null or devminor is null))), + check (configuration = 0 or configuration = 1) ) without rowid ; create view packagefiles_pkgid as -select printf('%s-%s-%s', package, version, release) as pkgid, * +select printf('%s-%s-%s', package, version, release) as pkgid, *, +printf('%s:%o:%s:%s', filetype, mode, username, groupname) as mds from packagefiles ; +create trigger packagefiles_update_trigger instead of +update on packagefiles_pkgid +begin + update packages + set package = NEW.package, + version = NEW.version, + release = NEW.release, + path = NEW.path, + mode = NEW.mode, + username = NEW.username, + groupname = NEW.groupname, + uid = NEW.uid, + gid = NEW.gid, + configuration = NEW.configuration, + filetype = NEW.filetype, + target = NEW.target, + devmajor = NEW.devmajor, + devminor = NEW.devminor, + hash = NEW.hash, + mtime = NEW.mtime + where package = OLD.package + and version = OLD.version + and release = OLD.release + and path = OLD.path + ; +end +; + create view installed_ref_count as select I.path, count(*) as refcount from installedfiles I group by I.path ; +create view sync_status_ref_count as +select path, status, count(*) as refcount +from packagefiles_status +where status in ('installed', 'installing', 'removing') +group by path, status +; + create view packagefiles_status as select P.status, PF.* from packagefiles_pkgid PF @@ -197,6 +237,16 @@ left join packagefiles_status PN and PI.pkgid != PN.pkgid where PN.path is null and PI.package in (select package from packages where status = 'installing') + +union all +-- remove files in removing, but not installing +select distinct 'remove' as op, PR.* +from packagefiles_status PR +left join packagefiles_status PN +on PR.path = PN.path +and PR.pkgid != PN.pkgid and PN.status in ('installing', 'installed') +where PN.path is null +and PR.status = 'removing' ; create table pathtags (