Commit 7948dae1 authored by Mark Nelson's avatar Mark Nelson
Browse files

MDL-59904 core: add missing FKs to analytics tables

parent 9eb3c173
......@@ -3600,10 +3600,8 @@
</FIELDS>
<KEYS>
<KEY NAME="primary" TYPE="primary" FIELDS="id"/>
<KEY NAME="modelid" TYPE="foreign" FIELDS="modelid" REFTABLE="analytics_models" REFFIELDS="id"/>
</KEYS>
<INDEXES>
<INDEX NAME="modelid" UNIQUE="false" FIELDS="modelid" COMMENT="Index on modelid"/>
</INDEXES>
</TABLE>
<TABLE NAME="analytics_predictions" COMMENT="Predictions">
<FIELDS>
......@@ -3619,6 +3617,8 @@
</FIELDS>
<KEYS>
<KEY NAME="primary" TYPE="primary" FIELDS="id"/>
<KEY NAME="modelid" TYPE="foreign" FIELDS="modelid" REFTABLE="analytics_models" REFFIELDS="id"/>
<KEY NAME="contextid" TYPE="foreign" FIELDS="contextid" REFTABLE="context" REFFIELDS="id"/>
</KEYS>
<INDEXES>
<INDEX NAME="modelidandcontextid" UNIQUE="false" FIELDS="modelid, contextid" COMMENT="Index on modelid and contextid"/>
......@@ -3636,6 +3636,8 @@
</FIELDS>
<KEYS>
<KEY NAME="primary" TYPE="primary" FIELDS="id"/>
<KEY NAME="modelid" TYPE="foreign" FIELDS="modelid" REFTABLE="analytics_models" REFFIELDS="id"/>
<KEY NAME="fileid" TYPE="foreign" FIELDS="fileid" REFTABLE="files" REFFIELDS="id"/>
</KEYS>
<INDEXES>
<INDEX NAME="modelidandanalysableidandtimesplitting" UNIQUE="false" FIELDS="modelid, analysableid, timesplitting" COMMENT="Index on modelid and analysableid and timesplitting"/>
......@@ -3654,6 +3656,7 @@
</FIELDS>
<KEYS>
<KEY NAME="primary" TYPE="primary" FIELDS="id"/>
<KEY NAME="modelid" TYPE="foreign" FIELDS="modelid" REFTABLE="analytics_models" REFFIELDS="id"/>
</KEYS>
<INDEXES>
<INDEX NAME="modelidandanalysableidandtimesplittingandrangeindex" UNIQUE="false" FIELDS="modelid, analysableid, timesplitting, rangeindex" COMMENT="Index on modelid and analysableid and timesplitting"/>
......@@ -3669,6 +3672,8 @@
</FIELDS>
<KEYS>
<KEY NAME="primary" TYPE="primary" FIELDS="id"/>
<KEY NAME="modelid" TYPE="foreign" FIELDS="modelid" REFTABLE="analytics_models" REFFIELDS="id"/>
<KEY NAME="fileid" TYPE="foreign" FIELDS="fileid" REFTABLE="files" REFFIELDS="id"/>
</KEYS>
<INDEXES>
<INDEX NAME="modelidandfileidandaction" UNIQUE="false" FIELDS="modelid, fileid, action" COMMENT="Index on modelid and fileid and action"/>
......@@ -3688,6 +3693,7 @@
</FIELDS>
<KEYS>
<KEY NAME="primary" TYPE="primary" FIELDS="id"/>
<KEY NAME="contextid" TYPE="foreign" FIELDS="contextid" REFTABLE="context" REFFIELDS="id"/>
</KEYS>
<INDEXES>
<INDEX NAME="starttime-endtime-contextid" UNIQUE="false" FIELDS="starttime, endtime, contextid"/>
......
......@@ -2369,5 +2369,59 @@ function xmldb_main_upgrade($oldversion) {
upgrade_main_savepoint(true, 2017082300.01);
}
if ($oldversion < 2017082500.00) {
// Handle FKs for the table 'analytics_models_log'.
$table = new xmldb_table('analytics_models_log');
// Remove the existing index before adding FK (which creates an index).
$index = new xmldb_index('modelid', XMLDB_INDEX_NOTUNIQUE, array('modelid'));
// Conditionally launch drop index.
if ($dbman->index_exists($table, $index)) {
$dbman->drop_index($table, $index);
}
// Now, add the FK.
$key = new xmldb_key('modelid', XMLDB_KEY_FOREIGN, array('modelid'), 'analytics_models', array('id'));
$dbman->add_key($table, $key);
// Handle FKs for the table 'analytics_predictions'.
$table = new xmldb_table('analytics_predictions');
$key = new xmldb_key('modelid', XMLDB_KEY_FOREIGN, array('modelid'), 'analytics_models', array('id'));
$dbman->add_key($table, $key);
$key = new xmldb_key('contextid', XMLDB_KEY_FOREIGN, array('contextid'), 'context', array('id'));
$dbman->add_key($table, $key);
// Handle FKs for the table 'analytics_train_samples'.
$table = new xmldb_table('analytics_train_samples');
$key = new xmldb_key('modelid', XMLDB_KEY_FOREIGN, array('modelid'), 'analytics_models', array('id'));
$dbman->add_key($table, $key);
$key = new xmldb_key('fileid', XMLDB_KEY_FOREIGN, array('fileid'), 'files', array('id'));
$dbman->add_key($table, $key);
// Handle FKs for the table 'analytics_predict_samples'.
$table = new xmldb_table('analytics_predict_samples');
$key = new xmldb_key('modelid', XMLDB_KEY_FOREIGN, array('modelid'), 'analytics_models', array('id'));
$dbman->add_key($table, $key);
// Handle FKs for the table 'analytics_used_files'.
$table = new xmldb_table('analytics_used_files');
$key = new xmldb_key('modelid', XMLDB_KEY_FOREIGN, array('modelid'), 'analytics_models', array('id'));
$dbman->add_key($table, $key);
$key = new xmldb_key('fileid', XMLDB_KEY_FOREIGN, array('fileid'), 'files', array('id'));
$dbman->add_key($table, $key);
// Handle FKs for the table 'analytics_indicator_calc'.
$table = new xmldb_table('analytics_indicator_calc');
$key = new xmldb_key('contextid', XMLDB_KEY_FOREIGN, array('contextid'), 'context', array('id'));
$dbman->add_key($table, $key);
// Main savepoint reached.
upgrade_main_savepoint(true, 2017082500.00);
}
return true;
}
......@@ -29,7 +29,7 @@
defined('MOODLE_INTERNAL') || die();
$version = 2017082400.00; // YYYYMMDD = weekly release date of this DEV branch.
$version = 2017082500.00; // YYYYMMDD = weekly release date of this DEV branch.
// RR = release increments - 00 in DEV branches.
// .XX = incremental changes.
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment