]> git.mjollnir.org Git - moodle.git/commitdiff
Dropping one UNIQUE index over NULLable columns. It isn't
authorstronk7 <stronk7>
Thu, 6 Sep 2007 18:31:13 +0000 (18:31 +0000)
committerstronk7 <stronk7>
Thu, 6 Sep 2007 18:31:13 +0000 (18:31 +0000)
cross-db at all. So we make the composite index not unique
to get speed benefits but the unique constraint is
controlled programatically.

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

index 341b3e41f142907f101c94c5679ea6eeddac3c5f..8d86b55b6a2058d2b8d98952dce1f695d95a44d0 100644 (file)
@@ -1,5 +1,5 @@
 <?xml version="1.0" encoding="UTF-8" ?>
-<XMLDB PATH="lib/db" VERSION="20070905" COMMENT="XMLDB file for core Moodle tables"
+<XMLDB PATH="lib/db" VERSION="20070906" COMMENT="XMLDB file for core Moodle tables"
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xsi:noNamespaceSchemaLocation="../../lib/xmldb/xmldb.xsd"
 >
         <INDEX NAME="visible" UNIQUE="false" FIELDS="visible" NEXT="course"/>
         <INDEX NAME="course" UNIQUE="false" FIELDS="course" PREVIOUS="visible" NEXT="module"/>
         <INDEX NAME="module" UNIQUE="false" FIELDS="module" PREVIOUS="course" NEXT="instance"/>
-        <INDEX NAME="instance" UNIQUE="false" FIELDS="instance" PREVIOUS="module" NEXT="idnumber"/>
-        <INDEX NAME="idnumber" UNIQUE="true" FIELDS="idnumber" COMMENT="Default comment for the index, please edit me" PREVIOUS="instance"/>
+        <INDEX NAME="instance" UNIQUE="false" FIELDS="instance" PREVIOUS="module" NEXT="idnumber-course"/>
+        <INDEX NAME="idnumber-course" UNIQUE="false" FIELDS="idnumber, course" COMMENT="non unique index (although programatically we are guarantying some sort of uniqueness both under this table and the grade_items one). TODO: We need a central store of module idnumbers in the future." PREVIOUS="instance"/>
       </INDEXES>
     </TABLE>
     <TABLE NAME="course_sections" COMMENT="to define the sections for each course" PREVIOUS="course_modules" NEXT="course_request">
       <INDEXES>
         <INDEX NAME="locked-locktime" UNIQUE="false" FIELDS="locked, locktime" COMMENT="used in grading cron" NEXT="itemtype-needsupdate"/>
         <INDEX NAME="itemtype-needsupdate" UNIQUE="false" FIELDS="itemtype, needsupdate" COMMENT="used in grading cron" PREVIOUS="locked-locktime" NEXT="gradetype"/>
-        <INDEX NAME="gradetype" UNIQUE="false" FIELDS="gradetype" COMMENT="index for gradetype" PREVIOUS="itemtype-needsupdate"/>
+        <INDEX NAME="gradetype" UNIQUE="false" FIELDS="gradetype" COMMENT="index for gradetype" PREVIOUS="itemtype-needsupdate" NEXT="idnumber-courseid"/>
+        <INDEX NAME="idnumber-courseid" UNIQUE="false" FIELDS="idnumber, courseid" COMMENT="non unique index (although programatically we are guarantying some sort of uniqueness both under this table and the course_modules one). TODO: We need a central store of module idnumbers in the future." PREVIOUS="gradetype"/>
       </INDEXES>
     </TABLE>
     <TABLE NAME="grade_grades" COMMENT="grade_grades  This table keeps individual grades for each user and each item, exactly as imported or submitted by modules. The rawgrademax/min and rawscaleid are stored here to record the values at the time the grade was stored, because teachers might change this for an activity! All the results are normalised/resampled for the final grade value." PREVIOUS="grade_items" NEXT="grade_grades_text">
index 20a7b0e9cf9e64e0184d54681b1c8e181696f0fc..d550837eb59206ee46554f602fb9bdbcfee09876 100644 (file)
@@ -2034,6 +2034,35 @@ function xmldb_main_upgrade($oldversion=0) {
         }
     }
 
+/// To have UNIQUE indexes over NULLable columns isn't cross-db at all
+/// so we create a non unique index and programatically enforce uniqueness
+    if ($result && $oldversion < 2007090600) {
+
+    /// Define index idnumber (unique) to be dropped form course_modules
+        $table = new XMLDBTable('course_modules');
+        $index = new XMLDBIndex('idnumber');
+        $index->setAttributes(XMLDB_INDEX_UNIQUE, array('idnumber'));
+
+    /// Launch drop index idnumber
+        $result = $result && drop_index($table, $index);
+
+    /// Define index idnumber-course (not unique) to be added to course_modules
+        $table = new XMLDBTable('course_modules');
+        $index = new XMLDBIndex('idnumber-course');
+        $index->setAttributes(XMLDB_INDEX_NOTUNIQUE, array('idnumber', 'course'));
+
+    /// Launch add index idnumber-course
+        $result = $result && add_index($table, $index);
+
+    /// Define index idnumber-courseid (not unique) to be added to grade_items
+        $table = new XMLDBTable('grade_items');
+        $index = new XMLDBIndex('idnumber-courseid');
+        $index->setAttributes(XMLDB_INDEX_NOTUNIQUE, array('idnumber', 'courseid'));
+
+    /// Launch add index idnumber-courseid
+        $result = $result && add_index($table, $index);
+
+    }
 
 
 /*