Issue Details (XML | Word | Printable)

Key: MDL-8294
Type: Sub-task Sub-task
Status: Resolved Resolved
Resolution: Fixed
Priority: Blocker Blocker
Assignee: Nick Freear
Reporter: Nick Freear
Votes: 0
Watchers: 0
Operations

Add/Edit UI Mockup to this issue
If you were logged in you would be able to see more operations.
Moodle
MDL-7380

During upgrade group IDs aren't maintained - breaks activities/modules

Created: 24/Jan/07 04:38 PM   Updated: 29/Jan/07 11:09 PM
Return to search
Component/s: Groups
Affects Version/s: 1.8
Fix Version/s: 1.8

File Attachments: 1. File patch-MDL-8294-group_upgrade_2.diff (13 kB)
2. File patch-MDL-8294-group_upgrade_4.diff (16 kB)


Database: PostgreSQL
Participants: Nick Freear
Security Level: None
Resolved date: 29/Jan/07
Affected Branches: MOODLE_18_STABLE
Fixed Branches: MOODLE_18_STABLE


 Description  « Hide
During upgrade groups and members are transferred from old tables 'mdl_groups_temp', 'mdl_groups_members_temp'. In the former case the records aren't sorted on ID and the group ID may be lost in the function 'groups_create_group' - the ID is auto-incremented, so a new one is used.

Note, may be database dependent.

 All   Comments   Change History   Version Control      Sort Order: Ascending order - Click to sort in descending order
Nick Freear added a comment - 26/Jan/07 06:46 PM
Help! The patch 'upgrade_2' does NOT work completely, but its as far as I've got. The only way I can see to maintain group IDs during incremental upgrade of 1.8 dev is to 'get rid' of the new 1.8 groups tables, recreate them, then re-transfer the data from the 'groups_temp', 'groups_members_temp' tables, using a raw INSERT to add the records with existing IDs.

So this patch fixes the upgrade from 1.6/1.7, and the incremental upgrade of 1.8 dev by,
1. drops the foreign keys/indexes created by the previous 2007012200 upgrade (sorry Eloy!),
2. renames all the new 1.8 tables to 'groups_temp_18', etc.
3. recreates them using XMLDB.
4. transfers data, calling 'groups_db_upgrade_group'.

(3) goes wrong as the rename does not rename the primary keys - it complains that they already exist. I could drop the tables in (2), but admins won't like that!

Tested on PostgreSQL.


Nick Freear added a comment - 26/Jan/07 06:48 PM
To clarify, the upgrade from 1.6/1.7 etc. works. The problem is the upgrade from 1.8 dev!

Nick Freear added a comment - 29/Jan/07 06:35 PM
I still need help!!
I am now trying to drop the primary key before renaming each table (is this possible?), with code like:

"" $tables = array('', '_members', '_groupings', '_courses_groups', '_courses_groupings', '_groupings_groups');
$suffix = '_temp_18';

foreach ($tables as $t_name) {
$table = new XMLDBTable('groups'.$t_name);
$key = new XMLDBKey('groups'.$t_name);
$key->setAttributes(XMLDB_KEY_PRIMARY, array('id'));
$status = $status && drop_key($table, $key);
$status = $status && rename_table($table, 'groups'.$t_name.$suffix);
...""

But this doesn't seem to work - I currently get this output (Adodb warning at the end):

"" Sorry, groups tables created in Moodle 1.8 dev are being archived and renamed to 'groups_*_temp_18'!

(postgres7): SELECT co.conname AS name, co.consrc AS description FROM pg_constraint co, pg_class cl WHERE co.conrelid = cl.oid AND co.contype = 'c' AND cl.relname = 'headmdl_groups'
(postgres7): ALTER TABLE headmdl_groups RENAME TO headmdl_groups_temp_18
Success

(postgres7): ALTER TABLE headmdl_groups_id_seq RENAME TO headmdl_groups_temp_18_id_seq
Success

...
(postgres7): CREATE TABLE headmdl_groups ( id BIGSERIAL, name VARCHAR(254) NOT NULL DEFAULT '', description TEXT, enrolmentkey VARCHAR(50) NOT NULL DEFAULT '', lang VARCHAR(30) NOT NULL DEFAULT 'en', theme VARCHAR(50) NOT NULL DEFAULT '', picture BIGINT NOT NULL DEFAULT 0, hidepicture SMALLINT NOT NULL DEFAULT 0, timecreated BIGINT NOT NULL DEFAULT 0, timemodified BIGINT NOT NULL DEFAULT 0, CONSTRAINT headmdl_grou_id_pk PRIMARY KEY (id) )

Warning: pg_query() [function.pg-query]: Query failed: ERROR: relation "headmdl_grou_id_pk" already exists in /var/www/html/ndf42/head/lib/adodb/drivers/adodb-postgres7.inc.php on line 115
-1: ERROR: relation "headmdl_grou_id_pk" already exists
ADOConnection._Execute(CREATE TABLE headmdl_groups (
... ""


Nick Freear added a comment - 29/Jan/07 11:08 PM
Fixed using version 4 of the patch.

This uses a new approach - the admin is given a 'Do you want to continue?' message, with yes/ no options - if they choose yes groups tables are dropped and recreated. (This gets round the issue that primary keys can't be dropped separately, and in Postgres, MySQL, etc. keys can't be renamed.)


Nick Freear added a comment - 29/Jan/07 11:09 PM
Fixed, committed. Tested on PostgreSQL - uses XMLDB so hopefully the same on other DBs.