From 2044bbedbd69b15291452bf116fbdb815032c510 Mon Sep 17 00:00:00 2001 From: Daniel Berteaud Date: Fri, 3 Jul 2015 17:37:01 +0200 Subject: [PATCH] Add an audit table --- docs/database/schema.mysql | 13 ++++++++++++- lib/Vroom/Constants.pm | 2 +- scripts/db_upgrade.pl | 27 +++++++++++++++++++++++++++ 3 files changed, 40 insertions(+), 2 deletions(-) diff --git a/docs/database/schema.mysql b/docs/database/schema.mysql index cbfc7b5..6dfff3f 100644 --- a/docs/database/schema.mysql +++ b/docs/database/schema.mysql @@ -6,7 +6,7 @@ CREATE TABLE `config` ( UNIQUE (`key`) ) ENGINE INNODB DEFAULT CHARSET=utf8; INSERT INTO `config` (`key`,`value`) - VALUES ('schema_version', '7'); + VALUES ('schema_version', '8'); CREATE TABLE `session_keys` ( `id` INT UNSIGNED NOT NULL AUTO_INCREMENT, @@ -88,3 +88,14 @@ CREATE TABLE `room_keys` ( ON DELETE CASCADE ) ENGINE INNODB DEFAULT CHARSET=utf8; +CREATE TABLE `audit` ( + `id` INT UNSIGNED NOT NULL AUTO_INCREMENT, + `date` DATETIME NOT NULL, + `event` VARCHAR(255) NOT NULL, + `from_ip` VARCHAR(45) DEFAULT NULL, + `message` TEXT NOT NULL, + PRIMARY KEY (`id`), + INDEX (`date`), + INDEX (`event`), + INDEX (`from_ip`) +) ENGINE INNODB DEFAULT CHARSET=utf8; diff --git a/lib/Vroom/Constants.pm b/lib/Vroom/Constants.pm index a63b15d..0fae109 100644 --- a/lib/Vroom/Constants.pm +++ b/lib/Vroom/Constants.pm @@ -7,7 +7,7 @@ use base 'Exporter'; our @EXPORT = qw/DB_VERSION COMPONENTS MOH JS_STRINGS API_ACTIONS/; # Database version -use constant DB_VERSION => 7; +use constant DB_VERSION => 8; # Components used to generate the credits part use constant COMPONENTS => { diff --git a/scripts/db_upgrade.pl b/scripts/db_upgrade.pl index d647697..4b50fc4 100644 --- a/scripts/db_upgrade.pl +++ b/scripts/db_upgrade.pl @@ -166,3 +166,30 @@ if ($cur_ver < 7){ }; print "Successfully upgraded to schema version 7\n"; } + +if ($cur_ver < 8){ + print "Upgrading the schema to version 8\n"; + eval { + $dbh->begin_work; + $dbh->do(qq{ CREATE TABLE `audit` (`id` INT UNSIGNED NOT NULL AUTO_INCREMENT, + `date` DATETIME NOT NULL, + `event` VARCHAR(255) NOT NULL, + `from_ip` VARCHAR(45) DEFAULT NULL, + `message` TEXT NOT NULL, + PRIMARY KEY (`id`), + INDEX (`date`), + INDEX (`event`), + INDEX (`from_ip`)) + ENGINE INNODB DEFAULT CHARSET=utf8; }); + $dbh->do(qq{ UPDATE `config` SET `value`='8' WHERE `key`='schema_version' }); + $dbh->commit; + }; + if ($@){ + print "An error occurred: " . $dbh->errstr . "\n"; + local $dbh->{RaiseError} = 0; + $dbh->rollback; + exit 255; + }; + print "Successfully upgraded to schema version 8\n"; +} +