[Dbconfig-common-devel] Difficult/partial upgrade

Vincent Bernat bernat at luffy.cx
Wed Feb 16 19:49:38 UTC 2011


Hi!

I  am using dbconfig-common  to package  Roundcube [1]  and I  have some
difficulties  to provide proper  upgrade files  to upgrade  to Roundcube
0.5.*. I  am receiving some bug  reports [2] about users  unable to have
their MySQL database upgraded properly.

The problem  is that upstream upgrade  files may be  incorrect. It seems
that  on some  installation, some  indexes already  exists.  The upgrade
procedure  consists in  playing  the  SQL file  without  looking at  the
errors. Something that  dbconfig-common is unable to do.  MySQL does not
have instructions to ignore errors or instructions like "IF EXISTS".

I have therefore  move some upgrading into postinst  with something like
this:

#v+
	# We try to fix an incomplete upgrade (see #610725)
	if [ -n "$2" ] && dpkg --compare-versions "$2" le 0.5.1+dfsg-2; then
	    db_get roundcube/dbconfig-upgrade || true
	    if [ x"$RET" = x"true" ]; then
		# Ok, we may need to do some upgrade steps. Let's get
		# database parameters
		eval `sed -n 's/^\$\(.*\);$/\1/p' /etc/roundcube/debian-db.php`
		if [ x"$dbtype" = x"mysql" ]; then
		    echo "Fixing MySQL indexes (you can ignore errors)..."
		    MYSQLARGS="-f -u $dbuser -p$dbpass $dbname"
		    [ -z "$dbserver" ] || MYSQLARGS="-h $dbserver $MYSQLARGS"
		    [ -z "$dbport" ] || MYSQLARGS="-P $dbport $MYSQLARGS"
		    cat <<EOF | mysql $MYSQLARGS || true
ALTER TABLE \`messages\` ADD INDEX \`index_index\` (\`user_id\`, \`cache_key\`, \`idx\`);
ALTER TABLE \`session\` CHANGE \`vars\` \`vars\` MEDIUMTEXT NOT NULL;
ALTER TABLE \`contacts\`ADD INDEX \`user_contacts_index\` (\`user_id\`,\`email\`);
ALTER TABLE \`identities\` ADD INDEX \`user_identities_index\` (\`user_id\`, \`del\`);
EOF
		fi
	    fi
	fi
#v-

My main problem is how to provide an upgrade path for users that already
have upgraded to some "buggy" version of my package.

For a  user which  upgraded from  0.3.1-6 to 0.5.1-1  and for  which the
upgrade has failed (upgrade file is  0.5-1), I would like to ensure that
I understand correctly how dbconfig-common works:
 - a ROLLBACK  has been issued  and therefore, _nothing_ in  the upgrade
   has been applied
 - if the user later upgrade to 0.5.1+dfsg-2, dbconfig-common will _not_
   reapply upgrade file for 0.5-1.

Therefore,   I   was  thinking   about   just   issuing   "mysql  -f   <
$SQL_UPGRADE_FILE" if  the user is upgrading from  something more recent
than 0.5-1 and  less recent than the current version.  Is there a better
way?

[1] http://packages.qa.debian.org/r/roundcube.html
[2] http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=613586
-- 
Test input for validity and plausibility.
            - The Elements of Programming Style (Kernighan & Plauger)



More information about the Dbconfig-common-devel mailing list