Skip to content

Commit

Permalink
MDL-51412 question: add index to qtype field
Browse files Browse the repository at this point in the history
  • Loading branch information
davosmith committed Sep 15, 2015
1 parent f495510 commit 581e663
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
5 changes: 4 additions & 1 deletion lib/db/install.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8" ?>
<XMLDB PATH="lib/db" VERSION="20150824" COMMENT="XMLDB file for core Moodle tables"
<XMLDB PATH="lib/db" VERSION="20150915" COMMENT="XMLDB file for core Moodle tables"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="../../lib/xmldb/xmldb.xsd"
>
Expand Down Expand Up @@ -1248,6 +1248,9 @@
<KEY NAME="createdby" TYPE="foreign" FIELDS="createdby" REFTABLE="user" REFFIELDS="id" COMMENT="foreign (createdby) references user (id)"/>
<KEY NAME="modifiedby" TYPE="foreign" FIELDS="modifiedby" REFTABLE="user" REFFIELDS="id" COMMENT="foreign (modifiedby) references user (id)"/>
</KEYS>
<INDEXES>
<INDEX NAME="qtype" UNIQUE="false" FIELDS="qtype"/>
</INDEXES>
</TABLE>
<TABLE NAME="question_answers" COMMENT="Answers, with a fractional grade (0-1) and feedback">
<FIELDS>
Expand Down
14 changes: 14 additions & 0 deletions lib/db/upgrade.php
Original file line number Diff line number Diff line change
Expand Up @@ -4558,5 +4558,19 @@ function xmldb_main_upgrade($oldversion) {
upgrade_main_savepoint(true, 2015090801.00);
}

if ($oldversion < 2015091500.00) {
// Define index qtype (not unique) to be added to question.
$table = new xmldb_table('question');
$index = new xmldb_index('qtype', XMLDB_INDEX_NOTUNIQUE, array('qtype'));

// Conditionally launch add index qtype.
if (!$dbman->index_exists($table, $index)) {
$dbman->add_index($table, $index);
}

// Main savepoint reached.
upgrade_main_savepoint(true, 2015091500.00);
}

return true;
}

0 comments on commit 581e663

Please sign in to comment.