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.
This commit is contained in:
+4
-2
@@ -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"
|
||||
>
|
||||
@@ -741,7 +741,9 @@
|
||||
<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">
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user