[Dbconfig-common-devel] Difficult/partial upgrade

Vincent Bernat bernat at debian.org
Sat Feb 19 09:27:32 UTC 2011


OoO La nuit ayant déjà recouvert  d'encre ce jour du mercredi 16 février
2011, vers 23:42, Sean Finney <seanius at debian.org> disait :

>> So,  I should  be able  to use  dbc_mysql_exec_file inside  the "script"
>> functionality, right?

> if you're doing that, i think you will need to actually do it in your
> postinst script directly (i.e. in an "if dpkg-compareversions ...." type
> block).

> it ought to be possible to setup dbconfig in a seperate script through
> the standard upgrade mechanism, but you'd need to spend some time
> reading what dbc_go actually does to do this, and it's probably just
> easier to do it int he postinst since everything's already set up there.

Here is  how I "solved"  this problem. This  is pretty ugly but  this is
better than  leaving the  user with an  incomplete upgrade. The  idea is
that 0.5-1  upgrade file may have  been played partially  because it was
adding indexes that could already exists.

There are two parts in the fix:
 1. I  have commented index creation  in the upgrade file  to avoid that
    users upgrading to  the new version get a  failed upgrade. The index
    creation is moved into postinst.
 2. For users that already upgraded, I force to replay the whole upgrade
    file without checking for errors.

The postinst snippet follows (it should hurt some eyes):

#v+
	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
		if [ x"$dbc_dbtype" = x"mysql" ]; then
		    # Ok, we may need to do some upgrade steps.
		    echo "Fixing MySQL installation..."
		    if dpkg --compare-versions "$2" ge 0.5; then
			# Hack (ugly) to replace "mysql" by "mysql -f"
			real_mysql="$(which mysql)"
			workdir="$(mktemp -d)"
			oldpath="$PATH"
			cat <<EOF > "$workdir/mysql"
#!/bin/sh
"$real_mysql" "\$@" -f
EOF
			chmod +x "$workdir/mysql"
			PATH="$workdir:$PATH"
			dbc_mysql_exec_file \
			    /usr/share/dbconfig-common/data/roundcube/upgrade/mysql/0.5-1 || true
			PATH="$oldpath"
			rm -rf "$workdir"
                    fi
		    cat <<EOF | while read command; do dbc_mysql_exec_command "$command" || true ; done
ALTER TABLE \`messages\` ADD INDEX \`index_index\` (\`user_id\`, \`cache_key\`, \`idx\`);
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-
-- 
panic("sun_82072_fd_inb: How did I get here?");
        2.2.16 /usr/src/linux/include/asm-sparc/floppy.h
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 197 bytes
Desc: not available
URL: <http://lists.alioth.debian.org/pipermail/dbconfig-common-devel/attachments/20110219/fac20558/attachment.pgp>


More information about the Dbconfig-common-devel mailing list