From: Mike Bayer Date: Tue, 20 Dec 2011 21:10:01 +0000 (-0500) Subject: - [bug] Fix autogenerate so that "pass" is X-Git-Tag: rel_0_1_1~8 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9fdcfb6de4d59709085f27e5e37e82dc0d478b41;p=thirdparty%2Fsqlalchemy%2Falembic.git - [bug] Fix autogenerate so that "pass" is generated between the two comments if no net migrations were present. --- diff --git a/CHANGES b/CHANGES index ff9f4dfe..68789a2c 100644 --- a/CHANGES +++ b/CHANGES @@ -1,13 +1,17 @@ 0.1.1 ===== -- Clean up file write operations so that +- [bug] Clean up file write operations so that file handles are closed. -- PyPy is supported. +- [feature] PyPy is supported. -- Python 2.5 is supported, needs +- [feature] Python 2.5 is supported, needs __future__.with_statement +- [bug] Fix autogenerate so that "pass" is + generated between the two comments + if no net migrations were present. + 0.1.0 ===== - Initial release. Status of features: diff --git a/alembic/autogenerate.py b/alembic/autogenerate.py index 31eafee8..3ddf773c 100644 --- a/alembic/autogenerate.py +++ b/alembic/autogenerate.py @@ -222,12 +222,16 @@ def _produce_upgrade_commands(diffs, autogen_context): buf = [] for diff in diffs: buf.append(_invoke_command("upgrade", diff, autogen_context)) + if not buf: + buf = ["pass"] return "\n".join(buf) def _produce_downgrade_commands(diffs, autogen_context): buf = [] for diff in diffs: buf.append(_invoke_command("downgrade", diff, autogen_context)) + if not buf: + buf = ["pass"] return "\n".join(buf) def _invoke_command(updown, args, autogen_context): diff --git a/tests/test_autogenerate.py b/tests/test_autogenerate.py index 721f86fd..6b0308ff 100644 --- a/tests/test_autogenerate.py +++ b/tests/test_autogenerate.py @@ -137,7 +137,23 @@ class AutogenerateDiffTest(TestCase): eq_(diffs[7][0][5], False) - + def test_render_nothing(self): + context.configure( + connection = self.bind.connect(), + compare_type = True, + compare_server_default = True, + target_metadata=self.m1 + ) + template_args = {} + autogenerate.produce_migration_diffs(template_args, self.autogen_context) + eq_(re.sub(r"u'", "'", template_args['upgrades']), +"""### commands auto generated by Alembic - please adjust! ### + pass + ### end Alembic commands ###""") + eq_(re.sub(r"u'", "'", template_args['downgrades']), +"""### commands auto generated by Alembic - please adjust! ### + pass + ### end Alembic commands ###""") def test_render_diffs(self): """test a full render including indentation"""