Translate Toolkit & Pootle

Tools to help you make your software local

User Tools


Database Schema Upgrade

Users following Pootle development have to deal with model changes that require changes to database schema. Until recently we asked users to recreate their databases from scratch, but that's not always possible.

Schema updates are not easy in Django but the Django Command Extensions provides a sqldiff command for manage.py that works for many cases. It seems to work fine with MySQL for the types of changes we've been doing between the various betas and RCs of Pootle 2.0.0, but fails with SQLite though.

Steps

Install django-command-extensions using easy_install

 easy_install django-extensions

Add the following line to localsettings.py

 INSTALLED_APPS += ("django_extensions",)

Now command extensions are ready to be used, if you use the sqldiff manage command it will show SQL instructions for updating the database

 ./manage.py sqldiff -a

You need to pass these SQL instructions to your RDBMS, easiest way is to use the dbshell manage command

 ./manage.py sqldiff -a | ./manage.py dbshell

If the syntax produced by sqldiff is incorrect (happens with sqlite3) you can get a textual description of the changes needed and do them manually instead

 ./manage.py sqldiff -a -t

If you are running from install the manage.py file won't be available, use django-admin.py command with the option --settings=pootle.settings instead.

So for example

 ./manage.py sqldiff -a

Becomes

 django-admin.py sqldiff -a --settings=pootle.settings