Commit dfdbdec3 authored by Nathan Lewis's avatar Nathan Lewis Committed by Gerrit Code Review
Browse files

Add id field to institution table (Bug #1300997)



- Preparing for future patches which require an integer id for performance and other reasons.
- 'name' will continue to be used as the primary key.

Change-Id: I5006b7f39edccc217fe5e4287585e62fc2545036
Signed-off-by: default avatarNathan Lewis <nathan.lewis@totaralms.com>
parent a78e99e7
......@@ -57,6 +57,7 @@
</TABLE>
<TABLE NAME="institution">
<FIELDS>
<FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="true"/>
<FIELD NAME="name" TYPE="char" LENGTH="255" NOTNULL="true"/>
<FIELD NAME="displayname" TYPE="char" LENGTH="255" NOTNULL="true"/>
<FIELD NAME="registerallowed" TYPE="int" LENGTH="1" NOTNULL="true" DEFAULT="1"/>
......@@ -84,6 +85,7 @@
</FIELDS>
<KEYS>
<KEY NAME="primary" TYPE="primary" FIELDS="name" />
<KEY NAME="inst_id_uk" TYPE="unique" FIELDS="id"/>
<KEY NAME="stylefk" TYPE="foreign" FIELDS="style" REFTABLE="style" REFFIELDS="id"/>
</KEYS>
</TABLE>
......
......@@ -3204,5 +3204,43 @@ function xmldb_core_upgrade($oldversion=0) {
update_magicdb_path();
}
// Add id field and corresponding index to institution table.
if ($oldversion < 2014040400) {
$table = new XMLDBTable('institution');
// Add id field.
$field = new XMLDBField('id');
if (!field_exists($table, $field)) {
// Field.
$field->setAttributes(XMLDB_TYPE_INTEGER, 10, null, XMLDB_NOTNULL, null, null, null, 1, 'name');
add_field($table, $field);
// Update ids.
$institutions = get_records_array('institution');
$x = 1;
foreach ($institutions as $institution) {
execute_sql('UPDATE {institution} SET id = ? WHERE name = ?', array($x, $institution->name));
$x++;
}
$key = new XMLDBKey('inst_id_uk');
$key->setAttributes(XMLDB_KEY_UNIQUE, array('id'));
add_key($table, $key);
// Add sequence.
$field = new XMLDBField('id');
$field->setAttributes(XMLDB_TYPE_INTEGER, 10, null, XMLDB_NOTNULL, XMLDB_SEQUENCE);
change_field_type($table, $field);
// In postgres, keys and indexes are removed when a field is changed ("Add sequence" above), so add the key back.
if (is_postgres()) {
$key = new XMLDBKey('inst_id_uk');
$key->setAttributes(XMLDB_KEY_UNIQUE, array('id'));
add_key($table, $key);
}
}
}
return $status;
}
......@@ -15,7 +15,7 @@ $config = new stdClass();
// See https://wiki.mahara.org/index.php/Developer_Area/Version_Numbering_Policy
// For upgrades on stable branches, increment the version by one. On master, use the date.
$config->version = 2014040300;
$config->version = 2014040400;
$config->release = '1.10.0dev';
$config->minupgradefrom = 2009022600;
$config->minupgraderelease = '1.1.0 (release tag 1.1.0_RELEASE)';
......
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