From 1cb94eabb42d5d12a714547a823799a730aac0b8 Mon Sep 17 00:00:00 2001 From: Jake Dallimore Date: Mon, 10 Sep 2018 11:06:35 +0800 Subject: [PATCH] MDL-63658 core_favourites: add tables to the subsystem --- lib/db/install.xml | 22 ++++++++++++++++++++++ lib/db/upgrade.php | 37 +++++++++++++++++++++++++++++++++++++ version.php | 2 +- 3 files changed, 60 insertions(+), 1 deletion(-) diff --git a/lib/db/install.xml b/lib/db/install.xml index 455b29c7944..76c20f5bc39 100644 --- a/lib/db/install.xml +++ b/lib/db/install.xml @@ -3898,5 +3898,27 @@ + + + + + + + + + + + + + + + + + + + + + +
diff --git a/lib/db/upgrade.php b/lib/db/upgrade.php index a6087d3da1d..b64923fa34a 100644 --- a/lib/db/upgrade.php +++ b/lib/db/upgrade.php @@ -2524,5 +2524,42 @@ function xmldb_main_upgrade($oldversion) { upgrade_main_savepoint(true, 2018092800.03); } + if ($oldversion < 2018101600.01) { + // Define table 'favourite' to be created. + $table = new xmldb_table('favourite'); + + // Adding fields to table 'favourite'. + $table->add_field('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null); + $table->add_field('component', XMLDB_TYPE_CHAR, '100', null, XMLDB_NOTNULL, null, null); + $table->add_field('itemtype', XMLDB_TYPE_CHAR, '100', null, XMLDB_NOTNULL, null, null); + $table->add_field('itemid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null); + $table->add_field('contextid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null); + $table->add_field('userid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null); + $table->add_field('ordering', XMLDB_TYPE_INTEGER, 10, null, null, null, null); + $table->add_field('timecreated', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null); + $table->add_field('timemodified', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null); + + // Adding keys to table 'favourite'. + $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); + $table->add_key('contextid', XMLDB_KEY_FOREIGN, array('contextid'), 'context', array('id')); + $table->add_key('userid', XMLDB_KEY_FOREIGN, array('userid'), 'user', array('id')); + + // Conditionally launch create table for 'favourite'. + if (!$dbman->table_exists($table)) { + $dbman->create_table($table); + } + + // Add composite index 'uniqueuserfavouriteitem' to the table 'favourite'. + $index = new xmldb_index('uniqueuserfavouriteitem', XMLDB_INDEX_UNIQUE, + ['component', 'itemtype', 'itemid', 'contextid', 'userid']); + + if (!$dbman->index_exists($table, $index)) { + $dbman->add_index($table, $index); + } + + // Main savepoint reached. + upgrade_main_savepoint(true, 2018101600.01); + } + return true; } diff --git a/version.php b/version.php index 7ae9209295b..65c1ddb1bc3 100644 --- a/version.php +++ b/version.php @@ -29,7 +29,7 @@ defined('MOODLE_INTERNAL') || die(); -$version = 2018101600.00; // YYYYMMDD = weekly release date of this DEV branch. +$version = 2018101600.01; // YYYYMMDD = weekly release date of this DEV branch. // RR = release increments - 00 in DEV branches. // .XX = incremental changes.