Add an audit table

This commit is contained in:
Daniel Berteaud 2015-07-03 17:37:01 +02:00
parent 3f9e523aa5
commit 2044bbedbd
3 changed files with 40 additions and 2 deletions

View File

@ -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;

View File

@ -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 => {

View File

@ -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";
}