def upgrade(pkg, sql=False): """Upgrade to a later version.""" from alembic.config import Config from alembic.environment import EnvironmentContext if ':' in pkg: pkg, rev = pkg.split(':', 1) else: rev = 'head' script = ScriptDirectory(pkg) env = EnvironmentContext(Config(''), script) conn = ptah.get_base().metadata.bind.connect() def upgrade(revision, context): return script._upgrade_revs(rev, revision) env.configure( connection=conn, fn=upgrade, as_sql=sql, starting_rev=None, destination_rev=rev, ) mc = env._migration_context env._migration_context = MigrationContext(pkg, conn.dialect, conn, mc.opts) with env: try: with env.begin_transaction(): env.run_migrations() finally: conn.close()
def test_migration_context_has_config(self): env = self._fixture() env.configure(url="sqlite://") ctx = env._migration_context is_(ctx.config, self.cfg) ctx = MigrationContext(ctx.dialect, None, {}) is_(ctx.config, None)