MDL-49795 mod_data: Add userid foreign key to data_records

This commit is contained in:
Kevin Pham 2021-06-28 17:02:28 +10:00
parent 1499f83cad
commit 5ab70be182
3 changed files with 16 additions and 3 deletions

View File

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8" ?>
<XMLDB PATH="mod/data/db" VERSION="20160906" COMMENT="XMLDB file for Moodle mod/data"
<XMLDB PATH="mod/data/db" VERSION="20220530" COMMENT="XMLDB file for Moodle mod/data"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="../../../lib/xmldb/xmldb.xsd"
>
@ -91,6 +91,7 @@
<KEYS>
<KEY NAME="primary" TYPE="primary" FIELDS="id"/>
<KEY NAME="dataid" TYPE="foreign" FIELDS="dataid" REFTABLE="data" REFFIELDS="id"/>
<KEY NAME="userid" TYPE="foreign" FIELDS="userid" REFTABLE="user" REFFIELDS="id"/>
</KEYS>
</TABLE>
<TABLE NAME="data_content" COMMENT="the content introduced in each record/fields">

View File

@ -22,13 +22,25 @@
defined('MOODLE_INTERNAL') || die();
function xmldb_data_upgrade($oldversion) {
global $CFG;
global $DB;
$dbman = $DB->get_manager(); // Loads ddl manager and xmldb classes.
// Automatically generated Moodle v3.9.0 release upgrade line.
// Put any upgrade step following this.
// Automatically generated Moodle v4.0.0 release upgrade line.
// Put any upgrade step following this.
if ($oldversion < 2022053000) {
// Define key userid (foreign) to be added to data_records.
$table = new xmldb_table('data_records');
$key = new xmldb_key('userid', XMLDB_KEY_FOREIGN, ['userid'], 'user', ['id']);
// Launch add key userid.
$dbman->add_key($table, $key);
// Data savepoint reached.
upgrade_mod_savepoint(true, 2022053000, 'data');
}
return true;
}

View File

@ -24,7 +24,7 @@
defined('MOODLE_INTERNAL') || die();
$plugin->version = 2022041900; // The current module version (Date: YYYYMMDDXX).
$plugin->version = 2022053000; // The current module version (Date: YYYYMMDDXX).
$plugin->requires = 2022041200; // Requires this Moodle version.
$plugin->component = 'mod_data'; // Full name of the plugin (used for diagnostics)
$plugin->cron = 0;