Commit ffa51659 authored by Robert Lyon's avatar Robert Lyon
Browse files

Bug 1774103: New structure for the tags table



Looking at consolidating all the differnet *_tag tables into one table

Also fixing up older upgrade where we add a column and then delete it
again. It slows down the upgrade for no gain.

behatnotneeded

Change-Id: I715a076dab74bca2897c56b171cc0536d6c65ff4
Signed-off-by: Robert Lyon's avatarRobert Lyon <robertl@catalyst.net.nz>
parent fd5dc8fa
......@@ -238,16 +238,6 @@
<INDEX NAME="usrix" UNIQUE="false" FIELDS="usr"/>
</INDEXES>
</TABLE>
<TABLE NAME="usr_tag">
<FIELDS>
<FIELD NAME="usr" TYPE="int" LENGTH="10" NOTNULL="true"/>
<FIELD NAME="tag" TYPE="char" LENGTH="128" NOTNULL="true"/>
</FIELDS>
<KEYS>
<KEY NAME="primary" TYPE="primary" FIELDS="usr,tag"/>
<KEY NAME="usrfk" TYPE="foreign" FIELDS="usr" REFTABLE="usr" REFFIELDS="id"/>
</KEYS>
</TABLE>
<TABLE NAME="auth_remote_user">
<FIELDS>
<FIELD NAME="authinstance" TYPE="int" LENGTH="10" NOTNULL="true" />
......@@ -555,16 +545,6 @@
<KEY NAME="primary" TYPE="primary" FIELDS="name" />
</KEYS>
</TABLE>
<TABLE NAME="artefact_tag">
<FIELDS>
<FIELD NAME="artefact" TYPE="int" LENGTH="10" NOTNULL="true" />
<FIELD NAME="tag" TYPE="char" LENGTH="128" NOTNULL="true" />
</FIELDS>
<KEYS>
<KEY NAME="primary" TYPE="primary" FIELDS="artefact,tag" />
<KEY NAME="artefactfk" TYPE="foreign" FIELDS="artefact" REFTABLE="artefact" REFFIELDS="id" />
</KEYS>
</TABLE>
<TABLE NAME="artefact_access_usr">
<FIELDS>
<FIELD NAME="usr" TYPE="int" LENGTH="10" NOTNULL="true" />
......@@ -850,16 +830,6 @@
<KEY NAME="viewfk" TYPE="foreign" FIELDS="view" REFTABLE="view" REFFIELDS="id"/>
</KEYS>
</TABLE>
<TABLE NAME="view_tag">
<FIELDS>
<FIELD NAME="view" TYPE="int" LENGTH="10" NOTNULL="true" />
<FIELD NAME="tag" TYPE="char" LENGTH="128" NOTNULL="true" />
</FIELDS>
<KEYS>
<KEY NAME="primary" TYPE="primary" FIELDS="view,tag" />
<KEY NAME="viewfk" TYPE="foreign" FIELDS="view" REFTABLE="view" REFFIELDS="id" />
</KEYS>
</TABLE>
<TABLE NAME="view_autocreate_grouptype">
<FIELDS>
<FIELD NAME="view" TYPE="int" LENGTH="10" NOTNULL="true" />
......@@ -1133,16 +1103,6 @@
<KEY NAME="viewfk" TYPE="foreign" FIELDS="view" REFTABLE="view" REFFIELDS="id" />
</KEYS>
</TABLE>
<TABLE NAME="collection_tag">
<FIELDS>
<FIELD NAME="collection" TYPE="int" LENGTH="10" NOTNULL="true" />
<FIELD NAME="tag" TYPE="char" LENGTH="128" NOTNULL="true" />
</FIELDS>
<KEYS>
<KEY NAME="primary" TYPE="primary" FIELDS="collection,tag" />
<KEY NAME="collectionfk" TYPE="foreign" FIELDS="collection" REFTABLE="collection" REFFIELDS="id" />
</KEYS>
</TABLE>
<TABLE NAME="existingcopy">
<FIELDS>
<FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="true" />
......@@ -1428,7 +1388,7 @@
<KEY NAME="sitecontentfk" TYPE="foreign" FIELDS="sitecontentid" REFTABLE="site_content_version" REFFIELDS="id"/>
</KEYS>
</TABLE>
<TABLE NAME="usr_pendingdeletion">
<TABLE NAME="usr_pendingdeletion">
<FIELDS>
<FIELD NAME="id" TYPE="int" LENGTH="10" SEQUENCE="true" NOTNULL="true" />
<FIELD NAME="usr" TYPE="int" LENGTH="10" NOTNULL="true" />
......@@ -1440,5 +1400,22 @@
<KEY NAME="usrfk" TYPE="foreign" FIELDS="usr" REFTABLE="usr" REFFIELDS="id"/>
</KEYS>
</TABLE>
<TABLE NAME="tag">
<FIELDS>
<FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="true" />
<FIELD NAME="tag" TYPE="char" LENGTH="255" NOTNULL="true" />
<FIELD NAME="resourcetype" TYPE="char" LENGTH="100" NOTNULL="true" />
<FIELD NAME="resourceid" TYPE="char" LENGTH="255" NOTNULL="true" />
<FIELD NAME="ownertype" TYPE="char" LENGTH="100" NOTNULL="true" />
<FIELD NAME="ownerid" TYPE="char" LENGTH="100" NOTNULL="false" />
<FIELD NAME="editedby" TYPE="int" LENGTH="10" NOTNULL="false" />
<FIELD NAME="ctime" TYPE="datetime" NOTNULL="true" />
<FIELD NAME="mtime" TYPE="datetime" NOTNULL="false" />
</FIELDS>
<KEYS>
<KEY NAME="primary" TYPE="primary" FIELDS="id" />
<KEY NAME="editedbyfk" TYPE="foreign" FIELDS="editedby" REFTABLE="usr" REFFIELDS="id" />
</KEYS>
</TABLE>
</TABLES>
</XMLDB>
......@@ -5837,19 +5837,8 @@ function xmldb_core_upgrade($oldversion=0) {
}
}
if ($oldversion < 2018050200) {
log_debug('Create new "existinggroupmembercopy" field to "view" table');
$table = new XMLDBTable('view');
$field = new XMLDBField('existinggroupmembercopy');
$field->setAttributes(XMLDB_TYPE_INTEGER, 1, null, XMLDB_NOTNULL, null, null, null, 0);
add_field($table, $field);
}
if ($oldversion < 2018050201) {
log_debug('Create new "existingcopy" table to map who already has what. Also drop "existinggroupmembercopy" field');
$table = new XMLDBTable('view');
$field = new XMLDBField('existinggroupmembercopy');
drop_field($table, $field);
log_debug('Create new "existingcopy" table to map who already has what.');
$table = new XMLDBTable('existingcopy');
$table->addFieldInfo('id', XMLDB_TYPE_INTEGER, 10, null, XMLDB_NOTNULL, XMLDB_SEQUENCE);
......@@ -5884,5 +5873,50 @@ function xmldb_core_upgrade($oldversion=0) {
}
}
if ($oldversion < 2018061801) {
log_debug('Add a "tag" table to migrate all the tag information to');
$table = new XMLDBTable('tag');
$table->addFieldInfo('id', XMLDB_TYPE_INTEGER, 10, XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null);
$table->addFieldInfo('tag', XMLDB_TYPE_CHAR, 255, null, XMLDB_NOTNULL);
$table->addFieldInfo('resourcetype', XMLDB_TYPE_CHAR, 100, null, XMLDB_NOTNULL);
$table->addFieldInfo('resourceid', XMLDB_TYPE_CHAR, 255, null, XMLDB_NOTNULL);
$table->addFieldInfo('ownertype', XMLDB_TYPE_CHAR, 100, null, XMLDB_NOTNULL);
$table->addFieldInfo('ownerid', XMLDB_TYPE_CHAR, 100);
$table->addFieldInfo('editedby', XMLDB_TYPE_INTEGER, 10);
$table->addFieldInfo('ctime', XMLDB_TYPE_DATETIME, null, null, XMLDB_NOTNULL);
$table->addFieldInfo('mtime', XMLDB_TYPE_DATETIME);
$table->addKeyInfo('primary', XMLDB_KEY_PRIMARY, array('id'));
$table->addKeyInfo('editedbyfk', XMLDB_KEY_FOREIGN, array('editedby'), 'usr', array('id'));
if (create_table($table)) {
log_debug('Move the data from the old *_tag tables');
$types = array('artefact', 'collection', 'view');
$typecast = is_postgres() ? '::varchar' : '';
foreach ($types as $type) {
execute_sql("INSERT INTO {tag} (tag,resourcetype,resourceid,ownertype,ownerid,editedby,ctime,mtime)
SELECT xt.tag, '" . $type . "' AS resourcetype, xt." . $type . " AS resourceid,
CASE WHEN x.owner IS NOT NULL THEN 'user'
WHEN x.group IS NOT NULL THEN 'group'
ELSE 'institution'
END AS ownertype,
CASE WHEN x.owner IS NOT NULL THEN x.owner" . $typecast . "
WHEN x.group IS NOT NULL THEN x.group" . $typecast . "
ELSE x.institution
END AS ownerid,
NULL AS editedby, x.ctime AS ctime, x.mtime AS mtime
FROM {" . $type . "_tag} xt
JOIN {" . $type . "} x ON x.id = xt." . $type);
}
execute_sql("INSERT INTO {tag} (tag,resourcetype,resourceid,ownertype,ownerid,editedby,ctime,mtime)
SELECT ut.tag, 'usr' AS resourcetype, ut.usr AS resourceid, 'institution' AS ownertype,
SUBSTRING(ut.tag, LENGTH('lastinstitution:') + 1, 255) AS ownerid,
NULL as editedby, u.ctime AS ctime, NULL AS mtime
FROM {usr_tag} ut
JOIN {usr} u ON u.id = ut.usr
WHERE u.deleted = 0");
}
}
return $status;
}
......@@ -16,7 +16,7 @@ $config = new stdClass();
// See https://wiki.mahara.org/wiki/Developer_Area/Version_Numbering_Policy
// For upgrades on stable branches, increment the version by one. On master, use the date.
$config->version = 2018061800;
$config->version = 2018061801;
$config->series = '18.10';
$config->release = '18.10dev';
$config->minupgradefrom = 2015030409;
......
Markdown is supported
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