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 (
... ""
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.