From 07107e5d39f6a28881d2df0c48b3d78179577c8a Mon Sep 17 00:00:00 2001 From: Daniel Berteaud Date: Wed, 4 Mar 2015 18:30:04 +0100 Subject: [PATCH] Increase peer_id size --- docs/database/schema.mysql | 4 ++-- lib/Vroom/Constants.pm | 2 +- scripts/db_upgrade.pl | 17 +++++++++++++++++ 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/docs/database/schema.mysql b/docs/database/schema.mysql index 469fd00..78a1160 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', '1'); + VALUES ('schema_version', '2'); CREATE TABLE `rooms` ( `id` INT UNSIGNED NOT NULL AUTO_INCREMENT, @@ -31,7 +31,7 @@ CREATE TABLE `room_participants` ( `id` INT UNSIGNED NOT NULL AUTO_INCREMENT, `room_id` INT UNSIGNED NOT NULL, `participant` VARCHAR(60) NOT NULL, - `peer_id` VARCHAR(40) DEFAULT NULL, + `peer_id` VARCHAR(60) DEFAULT NULL, `role` VARCHAR(30) DEFAULT 'participant', `last_activity` DATETIME DEFAULT NULL, PRIMARY KEY (`id`), diff --git a/lib/Vroom/Constants.pm b/lib/Vroom/Constants.pm index 7b213a8..270cbd7 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 => 1; +use constant DB_VERSION => 2; # Components used to generate the credits part use constant COMPONENTS => { diff --git a/scripts/db_upgrade.pl b/scripts/db_upgrade.pl index e94290f..72e9adb 100644 --- a/scripts/db_upgrade.pl +++ b/scripts/db_upgrade.pl @@ -58,3 +58,20 @@ if ($cur_ver == Vroom::Constants::DB_VERSION){ exit 0; } +if ($cur_ver < 2){ + print "Upgrading the schema to version 2\n"; + eval { + $dbh->begin_work; + $dbh->do(qq{ ALTER TABLE `room_participants` MODIFY `peer_id` VARCHAR(60) }); + $dbh->do(qq{ UPDATE `config` SET `value`='2' 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 2\n"; +} +