]> git.mjollnir.org Git - moodle.git/commitdiff
roles database: MDL-17253 add unique index to role.name and role.shortname
authortjhunt <tjhunt>
Tue, 18 Nov 2008 07:41:28 +0000 (07:41 +0000)
committertjhunt <tjhunt>
Tue, 18 Nov 2008 07:41:28 +0000 (07:41 +0000)
We were trying to enforce it in PHP, but much better to have the database watching our back.

lib/db/install.xml
lib/db/upgrade.php
version.php

index 817c6be416787364d286751593ffa181b4d94fb9..277e401154724bd44f266d0120c25ece9b92305f 100644 (file)
@@ -1,5 +1,5 @@
 <?xml version="1.0" encoding="UTF-8" ?>
-<XMLDB PATH="lib/db" VERSION="20081111" COMMENT="XMLDB file for core Moodle tables"
+<XMLDB PATH="lib/db" VERSION="20081118" COMMENT="XMLDB file for core Moodle tables"
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xsi:noNamespaceSchemaLocation="../../lib/xmldb/xmldb.xsd"
 >
         <KEY NAME="primary" TYPE="primary" FIELDS="id"/>
       </KEYS>
       <INDEXES>
-        <INDEX NAME="sortorder" UNIQUE="true" FIELDS="sortorder"/>
+        <INDEX NAME="sortorder" UNIQUE="true" FIELDS="sortorder" NEXT="name"/>
+        <INDEX NAME="name" UNIQUE="true" FIELDS="name" COMMENT="Enforces the constraint that role names should be unique." PREVIOUS="sortorder" NEXT="shortname"/>
+        <INDEX NAME="shortname" UNIQUE="true" FIELDS="shortname" COMMENT="Enforces the constraint that role shortnames must be unique." PREVIOUS="name"/>
       </INDEXES>
     </TABLE>
     <TABLE NAME="context" COMMENT="one of these must be set" PREVIOUS="role" NEXT="context_temp">
index 7821efb7cf003992b092604f20ea16e1bd5c63af..8904ad4c533682e61f1ca886ec4c8d80e54f5d0a 100644 (file)
@@ -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;
 }
 
index 300a43b55e1a4606b870906e3ea948b4b94510ee..27e4600a8447697af28a17bc18f3182b433ced19 100644 (file)
@@ -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