Skip to content

Commit

Permalink
MDL-49795 mod_data: Add userid foreign key to data_records
Browse files Browse the repository at this point in the history
  • Loading branch information
keevan committed Aug 3, 2022
1 parent 1499f83 commit 5ab70be
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
3 changes: 2 additions & 1 deletion mod/data/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="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"
>
Expand Down Expand Up @@ -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">
Expand Down
14 changes: 13 additions & 1 deletion mod/data/db/upgrade.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
2 changes: 1 addition & 1 deletion mod/data/version.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

0 comments on commit 5ab70be

Please sign in to comment.