From: Mike Bayer Date: Sun, 30 Sep 2012 16:57:29 +0000 (-0400) Subject: - [bug] Fixed the "multidb" template which was badly out X-Git-Tag: rel_0_4_0~7 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=52e7547724587465cafc7d2af1e5961e3365ad76;p=thirdparty%2Fsqlalchemy%2Falembic.git - [bug] Fixed the "multidb" template which was badly out of date. It now generates revision files using the configuration to determine the different upgrade_() methods needed as well, instead of needing to hardcode these. Huge thanks to BryceLohr for doing the heavy lifting here. #71 --- diff --git a/CHANGES b/CHANGES index 3ee614e5..598c9695 100644 --- a/CHANGES +++ b/CHANGES @@ -5,6 +5,13 @@ front-ends can re-use the argument parsing built in. #70 +- [bug] Fixed the "multidb" template which was badly out + of date. It now generates revision files using + the configuration to determine the different + upgrade_() methods needed as well, instead of + needing to hardcode these. Huge thanks to + BryceLohr for doing the heavy lifting here. #71 + - [bug] Fixed the regexp that was checking for .py files in the version directory to allow any .py file through. Previously it was doing some kind of defensive checking, diff --git a/alembic/command.py b/alembic/command.py index 75e3aa80..c6bc3dc4 100644 --- a/alembic/command.py +++ b/alembic/command.py @@ -65,7 +65,8 @@ def revision(config, message=None, autogenerate=False, sql=False): script = ScriptDirectory.from_config(config) template_args = { - 'config': config # Let templates use config for e.g. multiple databases + 'config': config # Let templates use config for + # e.g. multiple databases } imports = set() diff --git a/alembic/templates/multidb/env.py b/alembic/templates/multidb/env.py index 90bc0dbd..76f39824 100644 --- a/alembic/templates/multidb/env.py +++ b/alembic/templates/multidb/env.py @@ -11,7 +11,7 @@ USE_TWOPHASE = False # access to the values within the .ini file in use. config = context.config -# Interpret the config file for Python logging. +# Interpret the config file for Python logging. # This line sets up loggers basically. fileConfig(config.config_file_name) logger = logging.getLogger(__name__) @@ -108,7 +108,6 @@ def run_migrations_online(): downgrade_token="%s_downgrades", target_metadata=target_metadata.get(name) ) - context.execute("-- running migrations for database %s" % name) context.run_migrations(engine_name=name) if USE_TWOPHASE: diff --git a/alembic/templates/multidb/script.py.mako b/alembic/templates/multidb/script.py.mako index 582492bb..1e7f79a4 100644 --- a/alembic/templates/multidb/script.py.mako +++ b/alembic/templates/multidb/script.py.mako @@ -25,9 +25,12 @@ def downgrade(engine_name): eval("downgrade_%s" % engine_name)() <% - db_names = context.get("config").get_main_option("databases") + db_names = config.get_main_option("databases") %> +## generate an "upgrade_() / downgrade_()" function +## for each database name in the ini file. + % for db_name in re.split(r',\s*', db_names): def upgrade_${db_name}():