I'm trying to determine the best way to toggle between my test and live dbs, and I've hit a bit of a wall. I'm using MySQL 5.0.22 and SQLObject 0.7, and since I'm in a corporate environment, neither of those is likely to change any time soon.
My setup is as follows:
I've got two dbs, which I'll call app and app_dev, living on different hosts and accessed by different users. My connection is set up is in my model as follows:
_connection = connectionForURI(
I set up my unit tests like this:
from <package> import Config
Config.DB_NAME = app_dev
from <package> import model
This isn't an especially good practice, and I'm trying to figure out how to change my connection after I import my model.
My original thought was to set up a class method to toggle back and forth:
def changeDatabase(cls, database):
"""Toggles between live and dev databases.
database: string, one of ("app", "live", "app-dev", "dev").
if database in ["app", "live"]:
cls._connection = connectionForURI(cls.live_connection_string)
elif database in ["app-dev", "dev"]:
cls._connection = connectionForURI(cls.dev_connection_string)
raise ValueError("database must be one of ('app', 'live', "
However, this method results in a lost connection to the second DB. Is there a better way to switch between different connections? Would a hub help, or is that only for managing multiple connections to the same db across threads?