s4

changeset 278:2f1607d8b56b

New access log schema started
author HIROSE Yuuji <yuuji@gentei.org>
date Tue, 02 Aug 2016 13:25:47 +0859
parents cfbedd0686dd
children 7d7b81cfd3a0
files s4-funcs.sh s4-init.sh
diffstat 2 files changed, 15 insertions(+), 3 deletions(-) [+]
line diff
     1.1 --- a/s4-funcs.sh	Tue Aug 02 10:08:34 2016 +0859
     1.2 +++ b/s4-funcs.sh	Tue Aug 02 13:25:47 2016 +0859
     1.3 @@ -447,7 +447,8 @@
     1.4    if [ -n "$n" ]; then
     1.5      now=`date +"%F %T"`
     1.6      #query "replace into acclog values('$user', '$1', '$n', '$now');"
     1.7 -    query "replace into acclog values('$user', '$1', $n, '$now');"
     1.8 +    #query "replace into acclog values('$user', '$1', $n, '$now');"
     1.9 +    query "replace into tblaccesses values('$user', '$1', $n, '$now');"
    1.10    fi
    1.11  )
    1.12  gecos() (
     2.1 --- a/s4-init.sh	Tue Aug 02 10:08:34 2016 +0859
     2.2 +++ b/s4-init.sh	Tue Aug 02 13:25:47 2016 +0859
     2.3 @@ -71,9 +71,20 @@
     2.4  create table par '(sessid text, var text, type text, val text, primary key(sessid, var, val) foreign key(sessid) references session(id) on update cascade on delete cascade);'
     2.5  create table session '(id text primary key, expire text);'
     2.6  create table cookie '(sessid text, var text, type text, val text, primary key(sessid, var) foreign key(sessid) references session(id) on update cascade on delete cascade);'
     2.7 -create table acclog "(user, tbl, tblrowid, time, \
     2.8 -	primary key(user, tbl, tblrowid), \
     2.9 +tblacc=`query "select name from sqlite_master where name='tblaccesses';"`
    2.10 +acc=`query "select name from sqlite_master where name='acclog';"`
    2.11 +echo tblacc="[$tblacc]" acc="[$acc]"
    2.12 +create table tblaccesses "(user, tbl, tblrowid, time, \
    2.13 +	unique(user, tbl, tblrowid, time), \
    2.14  	foreign key(user) references user(name))"
    2.15 +if [ -z "$tblacc" -a -n "$acc" ]; then
    2.16 +  echo Regenerating...
    2.17 +  query "INSERT INTO tblaccesses SELECT * FROM acclog;
    2.18 +DROP TABLE acclog;"
    2.19 +fi
    2.20 +create view acclog "AS
    2.21 +SELECT user, tbl, tblrowid, max(time) time FROM tblaccesses
    2.22 +GROUP by user, tbl, tblrowid;"
    2.23  
    2.24  create view gecoses "AS
    2.25  SELECT rowid,