Automating Database Change for Development on Multiple Versions

When developing on both master and the 1.6.x branch, you will need a separate database for each version. By editing ‘settings_local.py’ we can automatically choose the correct database based on the version currently running.

Here is an example from the top of my ‘settings_local.py’ which switches to ‘db/rb-1.6.x.db’ when working on 1.6, and uses the ‘db/rb.db’ file otherwise:

from reviewboard import VERSION
if VERSION[0] == 1 and VERSION[1] == 6:
    db_name = 'db/rb-1.6.x.db'
else:
    db_name = 'db/rb.db'

# Database backend.  Any supported django database engine should work.
DATABASES = {
    'default': {
        # 'django.db.backends.' followed by one of
        # 'postgresql', 'mysql', 'sqlite3' or 'ado_mssql'.
        'ENGINE': 'django.db.backends.sqlite3',

        # The name of the database. If sqlite3, this should be an absolute
        # path.
        'NAME': db_name,

        # Not used with sqlite3
        'USER': '',

        # Not used with sqlite3
        'PASSWORD': '',

        # Set to an empty string for localhost.
        'HOST': '',

        # Set to an empty string for default
        'PORT': '',
    },
}
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s