From: tjhunt Date: Tue, 18 Nov 2008 07:41:28 +0000 (+0000) Subject: roles database: MDL-17253 add unique index to role.name and role.shortname X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=40c792c3d1d6435abbe97d8ae9920c021ff19e8b;p=moodle.git roles database: MDL-17253 add unique index to role.name and role.shortname We were trying to enforce it in PHP, but much better to have the database watching our back. --- diff --git a/lib/db/install.xml b/lib/db/install.xml index 817c6be416..277e401154 100644 --- a/lib/db/install.xml +++ b/lib/db/install.xml @@ -1,5 +1,5 @@ - @@ -741,7 +741,9 @@ - + + + diff --git a/lib/db/upgrade.php b/lib/db/upgrade.php index 7821efb7cf..8904ad4c53 100644 --- a/lib/db/upgrade.php +++ b/lib/db/upgrade.php @@ -1024,6 +1024,38 @@ function xmldb_main_upgrade($oldversion) { upgrade_main_savepoint($result, 2008111200); } +/// Add a unique index to the role.name column. + if ($result && $oldversion < 2008111800) { + + /// Define index name (unique) to be added to role + $table = new xmldb_table('role'); + $index = new xmldb_index('name', XMLDB_INDEX_UNIQUE, array('name')); + + /// Conditionally launch add index name + if (!$dbman->index_exists($table, $index)) { + $dbman->add_index($table, $index); + } + + /// Main savepoint reached + upgrade_main_savepoint($result, 2008111800); + } + +/// Add a unique index to the role.shortname column. + if ($result && $oldversion < 2008111801) { + + /// Define index shortname (unique) to be added to role + $table = new xmldb_table('role'); + $index = new xmldb_index('shortname', XMLDB_INDEX_UNIQUE, array('shortname')); + + /// Conditionally launch add index shortname + if (!$dbman->index_exists($table, $index)) { + $dbman->add_index($table, $index); + } + + /// Main savepoint reached + upgrade_main_savepoint($result, 2008111801); + } + return $result; } diff --git a/version.php b/version.php index 300a43b55e..27e4600a84 100644 --- a/version.php +++ b/version.php @@ -6,7 +6,7 @@ // This is compared against the values stored in the database to determine // whether upgrades should be performed (see lib/db/*.php) - $version = 2008111200; // YYYYMMDD = date of the last version bump + $version = 2008111801; // YYYYMMDD = date of the last version bump // XX = daily increments $release = '2.0 dev (Build: 20081118)'; // Human-friendly version name