From: Mike Bayer Date: Wed, 21 Sep 2016 15:28:40 +0000 (-0400) Subject: Support explicit "base" in --sql mode. X-Git-Tag: rel_0_8_9~8 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=3a984411ccbd1c84140e57c1a4a5e66ba04b739a;p=thirdparty%2Fsqlalchemy%2Falembic.git Support explicit "base" in --sql mode. Fix bug where "alembic upgrade base:head --sql" would fail. Behavior is now equivalent to "alembic upgrade head --sql". Change-Id: Ic730541c3ce6af01fe892811fd3cc6643e0459a6 Fixes: #388 --- diff --git a/alembic/__init__.py b/alembic/__init__.py index 94ed0637..03a8384e 100644 --- a/alembic/__init__.py +++ b/alembic/__init__.py @@ -1,6 +1,6 @@ from os import path -__version__ = '0.8.8' +__version__ = '0.8.9' package_dir = path.abspath(path.dirname(__file__)) diff --git a/alembic/runtime/migration.py b/alembic/runtime/migration.py index 352737ec..a0b386df 100644 --- a/alembic/runtime/migration.py +++ b/alembic/runtime/migration.py @@ -230,7 +230,9 @@ class MigrationContext(object): """ if self.as_sql: start_from_rev = self._start_from_rev - if start_from_rev is not None and self.script: + if start_from_rev == 'base': + start_from_rev = None + elif start_from_rev is not None and self.script: start_from_rev = \ self.script.get_revision(start_from_rev).revision diff --git a/docs/build/changelog.rst b/docs/build/changelog.rst index 7fdfd620..fef24e5e 100644 --- a/docs/build/changelog.rst +++ b/docs/build/changelog.rst @@ -3,6 +3,15 @@ Changelog ========== +.. changelog:: + :version: 0.8.9 + + .. change:: + :tags: bug, versioning + + Fixed bug where the "base" specifier, as in "base:head", could not + be used explicitly when ``--sql`` mode was present. + .. changelog:: :version: 0.8.8 :released: September 12, 2016 diff --git a/tests/test_command.py b/tests/test_command.py index d20412d5..49cdaf2a 100644 --- a/tests/test_command.py +++ b/tests/test_command.py @@ -434,6 +434,24 @@ class UpgradeDowngradeStampTest(TestBase): assert "DROP STEP 2" in buf.getvalue() assert "DROP STEP 1" not in buf.getvalue() + def test_none_to_head_sql(self): + with capture_context_buffer() as buf: + command.upgrade(self.cfg, "head", sql=True) + assert "CREATE TABLE alembic_version" in buf.getvalue() + assert "UPDATE alembic_version" in buf.getvalue() + assert "CREATE STEP 1" in buf.getvalue() + assert "CREATE STEP 2" in buf.getvalue() + assert "CREATE STEP 3" in buf.getvalue() + + def test_base_to_head_sql(self): + with capture_context_buffer() as buf: + command.upgrade(self.cfg, "base:head", sql=True) + assert "CREATE TABLE alembic_version" in buf.getvalue() + assert "UPDATE alembic_version" in buf.getvalue() + assert "CREATE STEP 1" in buf.getvalue() + assert "CREATE STEP 2" in buf.getvalue() + assert "CREATE STEP 3" in buf.getvalue() + def test_sql_stamp_from_rev(self): with capture_context_buffer() as buf: command.stamp(self.cfg, "%s:head" % self.a, sql=True)