]> pd.if.org Git - zpackage/commitdiff
sanitize packages table
authorNathan Wagner <nw@hydaspes.if.org>
Sat, 15 Sep 2018 02:05:55 +0000 (02:05 +0000)
committerNathan Wagner <nw@hydaspes.if.org>
Mon, 17 Sep 2018 12:13:04 +0000 (12:13 +0000)
Added check constraints, and removed pkgid column.  Added a
view packages_pkgid with the pkgid column constructed from
the package, version, and release columns.

db.sql

diff --git a/db.sql b/db.sql
index 5f227c87ee3fe99b752f2a7751b94c146a5d2b46..0a183265c551878cc981906d2f9278988ea5dcf8 100644 (file)
--- a/db.sql
+++ b/db.sql
@@ -19,10 +19,10 @@ CREATE TABLE files (
 -- a package is identified by a package,version,release triple
 create table packages (
        -- primary key columns
-       package text,
-       version text, -- the upstream version string
-       release integer, -- the local release number
-       pkgid   text, -- the three above joined with '-'
+       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,
@@ -35,13 +35,24 @@ create table packages (
        install_time    integer,
        checksum        text, -- checksum of package contents.  null for incompleted packages
        primary key (package,version,release),
+       check (typeof(package) = 'text'),
+       check (typeof(version) = 'text'),
        check (typeof(release) = 'integer'),
        check (release > 0)
-       -- TODO enforce name and release conventions
+       -- TODO enforce name and version conventions
+       -- check(instr(version,'-') = 0)
+       -- check(instr(package,'/') = 0)
+       -- check(instr(package,'/') = 0)
+       -- check(length(package) < 64)
+       -- check(length(version) < 32)
 )
 without rowid
 ;
 
+create view packages_pkgid as
+select printf('%s-%s-%s', package, version, release) as pkgid, *
+from packages;
+
 -- handle package status history with a logging trigger.
 create trigger logpkgstatus after update of status on packages
 begin insert into zpmlog (action,target,info)