Commit a145e83d authored by Nigel McNie's avatar Nigel McNie
Browse files

Fixes to the upgrade so that an upgrade from a pristine 0.9 postgres to 1.0...

Fixes to the upgrade so that an upgrade from a pristine 0.9 postgres to 1.0 produces the same schema as installing from 1.0.
parent 27b36fe9
......@@ -95,6 +95,15 @@ function xmldb_artefact_blog_upgrade($oldversion=0) {
if ($oldversion < 2008020700) {
$table = new XMLDBTable('artefact_blog_blog');
drop_table($table);
if (is_postgres()) {
// Rename indexes to keep things the same regardless of whether the
// user installed or upgraded to this release
execute_sql('DROP INDEX {arteblogblog_blo2_ix}');
execute_sql('CREATE INDEX {arteblogblog_blo_ix} ON {artefact_blog_blogpost} USING btree (blogpost)');
execute_sql('ALTER TABLE {artefact_blog_blogpost} DROP CONSTRAINT {arteblogblog_blo2_fk}');
execute_sql('ALTER TABLE {artefact_blog_blogpost} ADD CONSTRAINT {arteblogblog_blo_fk} FOREIGN KEY (blogpost) REFERENCES {artefact}(id)');
}
}
return $status;
}
......
......@@ -36,9 +36,14 @@ function xmldb_artefact_resume_upgrade($oldversion=0) {
'artefact_resume_educationhistory',
'artefact_resume_membership') as $table) {
$records = get_records_array($table, '', '', 'startdate DESC', 'id,startdate,enddate');
table_column($table, null, 'displayorder');
// Sigh. table_column is screwed beyond belief. We let it do its
// work (in the case of start and stopdate at least because it does
// cast the columns OK), then fix its bugs
execute_sql('ALTER TABLE {' . $table . '} ADD displayorder INTEGER');
table_column($table, 'startdate', 'startdate', 'text', null, null, '', 'not null');
execute_sql('ALTER TABLE {' . $table . '} ALTER COLUMN startdate DROP DEFAULT');
table_column($table, 'enddate', 'enddate', 'text', null, null, '', '');
execute_sql('ALTER TABLE {' . $table . '} ALTER COLUMN enddate DROP DEFAULT');
if (!empty($records)) {
foreach ($records as $k => $r) {
set_field($table, 'displayorder', $k, 'id', $r->id);
......@@ -50,13 +55,16 @@ function xmldb_artefact_resume_upgrade($oldversion=0) {
'id', $r->id);
}
}
execute_sql('ALTER TABLE {' . $table . '} ALTER displayorder SET NOT NULL');
execute_sql('ALTER TABLE {' . $table . '} ALTER COLUMN startdate SET NOT NULL');
}
foreach (array(
'artefact_resume_certification',
'artefact_resume_book') as $table) {
$records = get_records_array($table, '', '', 'date DESC', 'id,date');
table_column($table, null, 'displayorder');
execute_sql('ALTER TABLE {' . $table . '} ADD displayorder INTEGER');
table_column($table, 'date', 'date', 'text', null, null, '', 'not null');
execute_sql('ALTER TABLE {' . $table . '} ALTER COLUMN date DROP DEFAULT');
if (!empty($records)) {
foreach ($records as $k => $r) {
set_field($table, 'displayorder', $k, 'id', $r->id);
......@@ -65,6 +73,8 @@ function xmldb_artefact_resume_upgrade($oldversion=0) {
'id', $r->id);
}
}
execute_sql('ALTER TABLE {' . $table . '} ALTER displayorder SET NOT NULL');
execute_sql('ALTER TABLE {' . $table . '} ALTER COLUMN date SET NOT NULL');
}
}
......
......@@ -437,11 +437,13 @@ function xmldb_core_upgrade($oldversion=0) {
delete_records('activity_type', 'name', 'newview');
}
if ($oldversion < 2007082300) {
// 0.9 - 1.0 upgrade begins here
// Version numbers begin at one day after the release date of 0.9 -
// although many were actually done before that date. A side effect of
// parallel development
if ($oldversion < 2007120800) {
// Institution message activity type
// NOTE: this patch was not actually done on 2007/08/23, but has been
// placed here to ensure that the activity type upgrade happens after
// it
insert_record('activity_type', (object) array(
'name' => 'institutionmessage',
'admin' => 0,
......@@ -462,7 +464,7 @@ function xmldb_core_upgrade($oldversion=0) {
}
}
if ($oldversion < 2007103000) {
if ($oldversion < 2007120801) {
// create interaction tables
$table = new XMLDBTable('interaction_installed');
......@@ -529,7 +531,7 @@ function xmldb_core_upgrade($oldversion=0) {
}
if ($oldversion < 2007111900) {
if ($oldversion < 2007120802) {
// move the activitytype table around
$fks = array(
'activity_queue' => 'type',
......@@ -612,7 +614,7 @@ function xmldb_core_upgrade($oldversion=0) {
$table->addFieldInfo('expirymailsent', XMLDB_TYPE_INTEGER, 1, XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, 0);
$table->addKeyInfo('usrfk', XMLDB_KEY_FOREIGN, array('usr'), 'usr', array('id'));
$table->addKeyInfo('institutionfk', XMLDB_KEY_FOREIGN, array('institution'), 'institution', array('name'));
$table->addKeyInfo('usrinstitutionuk', XMLDB_KEY_UNIQUE, array('usr', 'institution'));
$table->addKeyInfo('usrinstitutionuk', XMLDB_KEY_PRIMARY, array('usr', 'institution'));
create_table($table);
$table = new XMLDBTable('usr_institution_request');
......@@ -624,7 +626,7 @@ function xmldb_core_upgrade($oldversion=0) {
$table->addFieldInfo('ctime', XMLDB_TYPE_DATETIME, null, null);
$table->addKeyInfo('usrfk', XMLDB_KEY_FOREIGN, array('usr'), 'usr', array('id'));
$table->addKeyInfo('institutionfk', XMLDB_KEY_FOREIGN, array('institution'), 'institution', array('name'));
$table->addKeyInfo('usrinstitutionuk', XMLDB_KEY_UNIQUE, array('usr', 'institution'));
$table->addKeyInfo('usrinstitutionuk', XMLDB_KEY_PRIMARY, array('usr', 'institution'));
create_table($table);
// From now on usernames will be unique, and remote xmlrpc
......@@ -807,7 +809,7 @@ function xmldb_core_upgrade($oldversion=0) {
}
if ($oldversion < 2008012401) {
table_column('usr_registration', null, 'lang', 'text', null, null, '', '');
execute_sql('ALTER TABLE {usr_registration} ADD COLUMN lang TEXT');
}
if ($oldversion < 2008012500) {
......@@ -825,6 +827,18 @@ function xmldb_core_upgrade($oldversion=0) {
drop_field($table, $field);
}
if ($oldversion < 2008021200) {
// Install the new auth plugins and the group forums
$data = check_upgrades('auth.none');
upgrade_plugin($data);
$data = check_upgrades('auth.ldap');
upgrade_plugin($data);
$data = check_upgrades('interaction.forum');
upgrade_plugin($data);
}
return $status;
}
......
......@@ -43,7 +43,7 @@ function db_table_name($name) {
* @return string
*/
function db_quote_table_placeholders($sql) {
return preg_replace_callback('/\{([a-z_]+)\}/', create_function('$matches', 'return db_table_name($matches[1]);'), $sql);
return preg_replace_callback('/\{([a-z][a-z0-9_]+)\}/', create_function('$matches', 'return db_table_name($matches[1]);'), $sql);
}
/**
......
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