def _walk_versions(self, conf, initial_version=0): # Determine latest version script from the repo, then # upgrade from 1 through to the latest, with no data # in the databases. This just checks that the schema itself # upgrades successfully. # Assert we are not under version control... self.assertRaises(exception.DatabaseMigrationError, migration_api.db_version, conf) # Place the database under version control migration_api.version_control(conf, version=initial_version) cur_version = migration_api.db_version(conf) self.assertEqual(initial_version, cur_version) for version in xrange(initial_version + 1, TestMigrations.REPOSITORY.latest + 1): migration_api.db_sync(conf, version) cur_version = migration_api.db_version(conf) self.assertEqual(cur_version, version) # Now walk it back down to 0 from the latest, testing # the downgrade paths. for version in reversed( xrange(0, TestMigrations.REPOSITORY.latest)): migration_api.downgrade(conf, version) cur_version = migration_api.db_version(conf) self.assertEqual(cur_version, version)
def _walk_versions(self, conf, initial_version=0): # Determine latest version script from the repo, then # upgrade from 1 through to the latest, with no data # in the databases. This just checks that the schema itself # upgrades successfully. # Assert we are not under version control... self.assertRaises(exception.DatabaseMigrationError, migration_api.db_version, conf) # Place the database under version control migration_api.version_control(conf, version=initial_version) cur_version = migration_api.db_version(conf) self.assertEqual(initial_version, cur_version) for version in xrange(initial_version + 1, TestMigrations.REPOSITORY.latest + 1): migration_api.db_sync(conf, version) cur_version = migration_api.db_version(conf) self.assertEqual(cur_version, version) # Now walk it back down to 0 from the latest, testing # the downgrade paths. for version in reversed(xrange(0, TestMigrations.REPOSITORY.latest)): migration_api.downgrade(conf, version) cur_version = migration_api.db_version(conf) self.assertEqual(cur_version, version)
def configure_db(options): """ Establish the database, create an engine if needed, and register the models. :param options: Mapping of configuration options """ global _ENGINE if not _ENGINE: debug = config.get_option( options, 'debug', type='bool', default=False) verbose = config.get_option( options, 'verbose', type='bool', default=False) timeout = config.get_option( options, 'sql_idle_timeout', type='int', default=3600) _ENGINE = create_engine(options['sql_connection'], pool_recycle=timeout) logger = logging.getLogger('sqlalchemy.engine') if debug: logger.setLevel(logging.DEBUG) elif verbose: logger.setLevel(logging.INFO) migration.db_sync(options)