Add an audit table

master
Daniel Berteaud 10 years ago
parent 3f9e523aa5
commit 2044bbedbd
  1. 13
      docs/database/schema.mysql
  2. 2
      lib/Vroom/Constants.pm
  3. 27
      scripts/db_upgrade.pl

@ -6,7 +6,7 @@ CREATE TABLE `config` (
UNIQUE (`key`) UNIQUE (`key`)
) ENGINE INNODB DEFAULT CHARSET=utf8; ) ENGINE INNODB DEFAULT CHARSET=utf8;
INSERT INTO `config` (`key`,`value`) INSERT INTO `config` (`key`,`value`)
VALUES ('schema_version', '7'); VALUES ('schema_version', '8');
CREATE TABLE `session_keys` ( CREATE TABLE `session_keys` (
`id` INT UNSIGNED NOT NULL AUTO_INCREMENT, `id` INT UNSIGNED NOT NULL AUTO_INCREMENT,
@ -88,3 +88,14 @@ CREATE TABLE `room_keys` (
ON DELETE CASCADE ON DELETE CASCADE
) ENGINE INNODB DEFAULT CHARSET=utf8; ) 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;

@ -7,7 +7,7 @@ use base 'Exporter';
our @EXPORT = qw/DB_VERSION COMPONENTS MOH JS_STRINGS API_ACTIONS/; our @EXPORT = qw/DB_VERSION COMPONENTS MOH JS_STRINGS API_ACTIONS/;
# Database version # Database version
use constant DB_VERSION => 7; use constant DB_VERSION => 8;
# Components used to generate the credits part # Components used to generate the credits part
use constant COMPONENTS => { use constant COMPONENTS => {

@ -166,3 +166,30 @@ if ($cur_ver < 7){
}; };
print "Successfully upgraded to schema version 7\n"; 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";
}

Loading…
Cancel
Save