]> git.mjollnir.org Git - moodle.git/commitdiff
enforcing unique constraint on (courseid, shortname) pair on outcomes
authortoyomoyo <toyomoyo>
Wed, 1 Aug 2007 03:17:00 +0000 (03:17 +0000)
committertoyomoyo <toyomoyo>
Wed, 1 Aug 2007 03:17:00 +0000 (03:17 +0000)
lib/db/install.xml
lib/db/upgrade.php
version.php

index 1ed0ce1b59628414007c2eb7604bf86971fc9867..aa743914b76a0d15da1b25b5d843feaf117cb654 100644 (file)
         <KEY NAME="primary" TYPE="primary" FIELDS="id" COMMENT="primary key of the table, please edit me" NEXT="courseid"/>
         <KEY NAME="courseid" TYPE="foreign" FIELDS="courseid" REFTABLE="course" REFFIELDS="id" PREVIOUS="primary" NEXT="scaleid"/>
         <KEY NAME="scaleid" TYPE="foreign" FIELDS="scaleid" REFTABLE="scale" REFFIELDS="id" PREVIOUS="courseid" NEXT="usermodified"/>
-        <KEY NAME="usermodified" TYPE="foreign" FIELDS="usermodified" REFTABLE="user" REFFIELDS="id" PREVIOUS="scaleid"/>
+        <KEY NAME="usermodified" TYPE="foreign" FIELDS="usermodified" REFTABLE="user" REFFIELDS="id" PREVIOUS="scaleid" NEXT="courseid-shortname"/>
+        <KEY NAME="courseid-shortname" TYPE="unique" FIELDS="courseid, shortname" COMMENT="Default comment for the key, please edit me" PREVIOUS="usermodified"/>
       </KEYS>
     </TABLE>
     <TABLE NAME="grade_outcomes_courses" COMMENT="stores what outcomes are used in what courses." PREVIOUS="grade_outcomes" NEXT="grade_categories">
index e47a55ea1915365fd7dd05ecbc468e98160fe8ba..ad696fb93b7c0642824b05b373345227b9d44210 100644 (file)
@@ -1553,7 +1553,18 @@ function xmldb_main_upgrade($oldversion=0) {
         }
 
     }
+    
+    // adding unique contraint on (courseid,shortname) of an outcome
+    if ($result && $oldversion < 2007080100) {
+
+    /// Define key courseid-shortname (unique) to be added to grade_outcomes
+        $table = new XMLDBTable('grade_outcomes');
+        $key = new XMLDBKey('courseid-shortname');
+        $key->setAttributes(XMLDB_KEY_UNIQUE, array('courseid', 'shortname'));
 
+    /// Launch add key courseid-shortname
+        $result = $result && add_key($table, $key);
+    }
 
 /*
     /// drop old gradebook tables
index cfd1c685fc970377ec411ece7d98cf492861eeaf..4639b699d6cd9a2daa5a9480698d7c564529d358 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 = 2007073105;  // YYYYMMDD = date
+    $version = 2007080100;  // YYYYMMDD = date
                             //       XY = increments within a single day
 
     $release = '1.9 dev';   // Human-friendly version name