#!/bin/sh new=$1 old=$2 # if current is older than 0.4.0 we update. if [ "$(apk version -t $old 0.4.0)" = "<" ]; then psql -U postgres -c "ALTER TABLE weblog ADD COLUMN shortreason text" \ webproxylog psql -U postgres -c "ALTER TABLE pubweblog ADD COLUMN shortreason text" \ webproxylog psql -U postgres -c "ALTER TABLE pubblocklog ADD COLUMN shortreason text" \ webproxylog psql -U postgres -c "ALTER TABLE blocklog ADD COLUMN shortreason text" \ webproxylog fi # if current is older than 0.4.5 we update. if [ "$(apk version -t $old 0.4.5)" = "<" ]; then psql -U postgres -c "ALTER TABLE dbhistlog ALTER logdatetime TYPE timestamp(3)"\ webproxylog fi # if current is older than 0.5.4 we update. if [ "$(apk version -t $old 0.5.4)" = "<" ]; then psql -U postgres -c "ALTER TABLE weblog ALTER bytes TYPE bigint"\ webproxylog psql -U postgres -c "ALTER TABLE pubweblog ALTER bytes TYPE bigint"\ webproxylog psql -U postgres -c "ALTER TABLE blocklog ALTER bytes TYPE bigint"\ webproxylog psql -U postgres -c "ALTER TABLE pubblocklog ALTER bytes TYPE bigint"\ webproxylog fi # if current is older than 0.6.0 we update. if [ "$(apk version -t $old 0.6.0)" = "<" ]; then mkdir /etc/weblog mv /etc/weblog.conf /etc/weblog/ echo "Executing db updates" psql -U postgres -c "ALTER TABLE pubweblog ADD COLUMN badyesno int, ADD COLUMN deniedyesno int, ADD COLUMN bypassyesno int, ADD COLUMN wordloc text, ADD COLUMN goodwordloc text, ADD COLUMN selected boolean, ADD COLUMN id int UNIQUE" -d webproxylog psql -U weblogowner -c "CREATE SEQUENCE pubweblog_id_seq" -d webproxylog psql -U postgres -c "ALTER TABLE pubweblog ALTER COLUMN id SET DEFAULT NEXTVAL('pubweblog_id_seq')" -d webproxylog psql -U postgres -c "UPDATE pubweblog SET id = NEXTVAL('pubweblog_id_seq')" -d webproxylog psql -U postgres -c "INSERT INTO pubweblog SELECT *,'0','1','0','','','false' FROM pubblocklog" -d webproxylog psql -U postgres -c "INSERT INTO pubweblog SELECT *,'0','0','0','','','false' FROM weblog" -d webproxylog psql -U postgres -c "INSERT INTO pubweblog SELECT *,'0','1','0','','','false' FROM blocklog" -d webproxylog psql -U postgres -c "ALTER TABLE weblog ADD COLUMN badyesno int, ADD COLUMN deniedyesno int, ADD COLUMN bypassyesno int, ADD COLUMN wordloc text, ADD COLUMN goodwordloc text" -d webproxylog psql -U weblogowner -c "CREATE TABLE pubweblog_history(sourcename character varying(40), clientip inet NOT NULL, clientuserid character varying(64) NOT NULL, logdatetime timestamp(3) without time zone NOT NULL, uri text NOT NULL, bytes bigint NOT NULL, reason text, score integer, shortreason text, badyesno int, deniedyesno int, bypassyesno int, wordloc text, goodwordloc text, selected boolean, id int)" -d webproxylog psql -U postgres -c "GRANT SELECT ON pubweblog_history TO webloguser" -d webproxylog psql -U postgres -c "DROP TABLE pubblocklog" -d webproxylog psql -U postgres -c "DROP TABLE watchlist" -d webproxylog psql -U postgres -c "DROP TABLE blocklog" -d webproxylog fi exit 0