Hi all,

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:

  password_map={"app":{'username': passwords.LIVE_USERNAME,
                       'passwd': passwords.LIVE_PASSWORD,
                       'host': 'app'},
                "app_dev":{'username': passwords.DEV_USERNAME,
                           'passwd': passwords.DEV_PASSWORD,
                           'host': 'app_dev"}}

  _connection = connectionForURI(
      "mysql://%(username)s:%(passwd)s@%(host)s/%(db)s" %
      {'username': password_map[Config.DB_NAME]['username'],
       'passwd': password_map[Config.DB_NAME]['passwd'],
       'db': Config.DB_NAME,
       'host': password_map[Config.DB_NAME]['host']})

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:

  @classmethod
  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)
    else:
      raise ValueError("database must be one of ('app', 'live', "
                       "'app-dev', 'dev')")

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?

Thanks,
Molly