]> pd.if.org Git - zpackage/blobdiff - db.sql
don't run ldconfig if etc doesn't exist
[zpackage] / db.sql
diff --git a/db.sql b/db.sql
index 041c06efdf24e9524b7457a8627c7d2ff036df5e..2418d12904b98fa323ed5c15aadd7d58afaf943d 100644 (file)
--- a/db.sql
+++ b/db.sql
@@ -22,7 +22,6 @@ create table packages (
        package text not null,
        version text not null, -- the upstream version string
        release integer not null, -- the local release number
---     pkgid   text, -- the three above joined with '-'
 
        -- metadata columns
        description     text,
@@ -33,21 +32,24 @@ create table packages (
        packager        text,
        build_time      integer default (strftime('%s', 'now')),
        install_time    integer,
-       checksum        text, -- checksum of package contents.  null for incompleted packages
+       hash    text, -- see integ.c for package hash details
        primary key (package,version,release),
        check (typeof(package) = 'text'),
        check (typeof(version) = 'text'),
        check (typeof(release) = 'integer'),
-       check (release > 0)
-       -- TODO enforce name and version conventions
-       -- check(instr(version,'-') = 0)
-       -- check(instr(package,'/') = 0)
-       -- check(instr(package,'/') = 0)
-       -- check(instr(version,' ') = 0)
-       -- check(instr(package,' ') = 0)
-       -- check(instr(package,' ') = 0)
-       -- check(length(package) < 64)
-       -- check(length(version) < 32)
+       check (release > 0),
+       -- enforce name and version conventions
+       check(instr(package,' ') = 0),
+       check(instr(package,'/') = 0),
+       check(instr(package,':') = 0),
+       check(instr(version,' ') = 0),
+       check(instr(version,'-') = 0),
+       check(instr(version,'/') = 0),
+       check(instr(version,':') = 0),
+       check(length(package) < 64),
+       check(length(package) > 0),
+       check(length(version) < 32),
+       check(length(version) > 0)
 )
 without rowid
 ;
@@ -59,6 +61,13 @@ create view packages_pkgid as
 select printf('%s-%s-%s', package, version, release) as pkgid, *
 from packages;
 
+create trigger packages_delete_trigger instead of
+delete on packages_pkgid
+begin
+       delete from packages where package = OLD.package
+       and version = OLD.version and release = OLD.release;
+end;
+
 create trigger packages_update_trigger instead of
 update on packages_pkgid
 begin
@@ -74,7 +83,7 @@ begin
        packager = NEW.packager,
        build_time = NEW.build_time,
        install_time = NEW.install_time,
-       checksum = NEW.checksum
+       hash = NEW.hash
        where package = OLD.package
        and version = OLD.version
        and release = OLD.release
@@ -100,14 +109,6 @@ create table packagetags (
        foreign key (package,version,release) references packages (package,version,release) on delete cascade on update cascade
 );
 
--- packagefile hash is columns as text, joined with null bytes, then
--- sha256 sum of that
--- package checksum is package columns as text, joined with null bytes,
--- other than the checksum and install_time column
--- then that hashed.  finally, that hash, plus the ascii sorted
--- hashes of the package files all joined with newlines, hashed.
--- really don't like this.
-
 -- files contained in a package
 create table packagefiles (
        -- package id triple
@@ -127,25 +128,35 @@ create table packagefiles (
        -- d directory
        -- s symlink
        -- h hard link -- not supported
-       -- c character special and b device special files add dev number column
-       -- b block special
-       -- p fifos (i.e. pipe)
+       -- c character special -- not supported
+       -- b block special -- not supported
+       -- c and b device special files add dev number column
+       -- p fifos (i.e. pipe) -- not supported
        target  text, -- link target for links
-       -- device file dev numbers, should probably be a separate table
+       -- device file dev numbers
        devmajor        integer,
        devminor        integer,
-       hash    text, -- null if no actual content, i.e. anything but a regular file
-       mtime   integer, -- seconds since epoch, finer resolution probably not needed
+       hash    text, -- null if not a regular file
+       mtime   integer, -- seconds since epoch, finer resolution not needed
        primary key (package,version,release,path),
-       foreign key (package,version,release) references packages (package,version,release) on delete cascade on update cascade,
+       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 = 'h' and target is null)),
+       check (target is null or length(target) between 1 and 4095),
+       check (hash is null or length(hash) between 1 and 1024),
        check (not (filetype = 'r' and hash 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 (filetype in ('r','d','s','h','c','b','p')),
+       check(length(username) between 1 and 256),
+       check(length(groupname) between 1 and 256),
        check (configuration = 0 or configuration = 1)
 )
 without rowid
 ;
+
 create index packagefile_package_index on packagefiles (package);
 create index packagefile_path_index on packagefiles (path);
 create index packagefile_hash_index on packagefiles (hash);