]> pd.if.org Git - zpackage/commitdiff
add packagefiles_pkgid update trigger
authorNathan Wagner <nw@hydaspes.if.org>
Sun, 30 Sep 2018 13:02:22 +0000 (13:02 +0000)
committerNathan Wagner <nw@hydaspes.if.org>
Sun, 30 Sep 2018 13:02:22 +0000 (13:02 +0000)
Added check constraints on packagefiles columns.

db.sql

diff --git a/db.sql b/db.sql
index 2e34ad38b6f0fbfc67ba5fc82ba510fe242f3f27..d4f2d3e0f1d12200a4d497da31c6a5e5aa409330 100644 (file)
--- a/db.sql
+++ b/db.sql
@@ -139,7 +139,9 @@ 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
 ;
@@ -150,6 +152,34 @@ 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