From 601632c07b8b8c62e188fff6264b68d99410c11a Mon Sep 17 00:00:00 2001 From: Daniel Berteaud Date: Fri, 26 Jun 2015 13:36:56 +0200 Subject: [PATCH] Drop the owner column in rooms table, useless --- docs/database/schema.mysql | 3 +-- lib/Vroom/Constants.pm | 2 +- scripts/db_upgrade.pl | 17 +++++++++++++++++ vroom.pl | 14 ++++++-------- 4 files changed, 25 insertions(+), 11 deletions(-) diff --git a/docs/database/schema.mysql b/docs/database/schema.mysql index 51b9540..e103968 100644 --- a/docs/database/schema.mysql +++ b/docs/database/schema.mysql @@ -6,12 +6,11 @@ CREATE TABLE `config` ( UNIQUE (`key`) ) ENGINE INNODB DEFAULT CHARSET=utf8; INSERT INTO `config` (`key`,`value`) - VALUES ('schema_version', '5'); + VALUES ('schema_version', '6'); CREATE TABLE `rooms` ( `id` INT UNSIGNED NOT NULL AUTO_INCREMENT, `name` VARCHAR(120) NOT NULL, - `owner` VARCHAR(60) DEFAULT NULL, `create_date` DATETIME DEFAULT NULL, `last_activity` DATETIME DEFAULT NULL, `locked` TINYINT UNSIGNED DEFAULT '0', diff --git a/lib/Vroom/Constants.pm b/lib/Vroom/Constants.pm index add8235..10c5cd2 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 => 5; +use constant DB_VERSION => 6; # Components used to generate the credits part use constant COMPONENTS => { diff --git a/scripts/db_upgrade.pl b/scripts/db_upgrade.pl index 1d79cf7..4a3fd26 100644 --- a/scripts/db_upgrade.pl +++ b/scripts/db_upgrade.pl @@ -128,3 +128,20 @@ if ($cur_ver < 5){ print "Successfully upgraded to schema version 5\n"; } +if ($cur_ver < 6){ + print "Upgrading the schema to version 6\n"; + eval { + $dbh->begin_work; + $dbh->do(qq{ ALTER TABLE `rooms` DROP COLUMN `owner` }); + $dbh->do(qq{ UPDATE `config` SET `value`='6' 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 6\n"; +} + diff --git a/vroom.pl b/vroom.pl index 713bd90..d21aad0 100755 --- a/vroom.pl +++ b/vroom.pl @@ -197,7 +197,7 @@ helper logout => sub { # Requires two args: the name of the room and the session name of the creator helper create_room => sub { my $self = shift; - my ($name,$owner) = @_; + my ($name) = @_; # Convert room names to lowercase if ($name ne lc $name){ $name = lc $name; @@ -213,16 +213,14 @@ helper create_room => sub { $self->db->prepare('INSERT INTO `rooms` (`name`, `create_date`, - `last_activity`, - `owner`) + `last_activity`) VALUES (?, CONVERT_TZ(NOW(), @@session.time_zone, \'+00:00\'), - CONVERT_TZ(NOW(), @@session.time_zone, \'+00:00\'), - ?)'); + CONVERT_TZ(NOW(), @@session.time_zone, \'+00:00\') + )'); }; $sth->execute( - $name, - $owner + $name ); $self->app->log->info("Room $name created by " . $self->get_name); # Etherpad integration ? If so, create the corresponding pad @@ -1434,7 +1432,7 @@ any '/api' => sub { $json->{msg} = $self->l('ERROR_NAME_CONFLICT'); return $self->render(json => $json, status => 409); } - if (!$self->create_room($req->{param}->{room},$self->get_name)){ + if (!$self->create_room($req->{param}->{room})){ $json->{err} = 'ERROR_OCCURRED'; $json->{msg} = $self->l('ERROR_OCCURRED'); return $self->render(json => $json, status => 500);