diff options
author | Mike Bayer <mike_mp@zzzcomputing.com> | 2015-06-09 11:40:34 -0400 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2015-06-09 11:40:34 -0400 |
commit | 541cbd26b5b86ce445f2065b60d28fdcbbb299a9 (patch) | |
tree | 993ff46d418439f2db6bf51430b98f2a9ab93581 | |
parent | 229f86723be4404c1bff3a63d97ab9f32ba93b0b (diff) | |
download | alembic-541cbd26b5b86ce445f2065b60d28fdcbbb299a9.tar.gz |
- The :meth:`.MigrationContext.stamp` method, added as part of the
versioning refactor in 0.7 as a more granular version of
:func:`.command.stamp`, now includes the "create the alembic_version
table if not present" step in the same way as the command version,
which was previously omitted.
fixes #300
-rw-r--r-- | alembic/migration.py | 2 | ||||
-rw-r--r-- | docs/build/changelog.rst | 10 | ||||
-rw-r--r-- | tests/test_version_table.py | 19 |
3 files changed, 30 insertions, 1 deletions
diff --git a/alembic/migration.py b/alembic/migration.py index d94db2e..9b46052 100644 --- a/alembic/migration.py +++ b/alembic/migration.py @@ -264,6 +264,8 @@ class MigrationContext(object): """ heads = self.get_current_heads() + if not self.as_sql and not heads: + self._ensure_version_table() head_maintainer = HeadMaintainer(self, heads) for step in script_directory._stamp_revs(revision, heads): head_maintainer.update_to_step(step) diff --git a/docs/build/changelog.rst b/docs/build/changelog.rst index e11713a..9c06825 100644 --- a/docs/build/changelog.rst +++ b/docs/build/changelog.rst @@ -7,6 +7,16 @@ Changelog :version: 0.7.7 .. change:: + :tags: bug, environment + :tickets: 300 + + The :meth:`.MigrationContext.stamp` method, added as part of the + versioning refactor in 0.7 as a more granular version of + :func:`.command.stamp`, now includes the "create the alembic_version + table if not present" step in the same way as the command version, + which was previously omitted. + + .. change:: :tags: bug, autogenerate :tickets: 298 diff --git a/tests/test_version_table.py b/tests/test_version_table.py index 704bb31..92cb447 100644 --- a/tests/test_version_table.py +++ b/tests/test_version_table.py @@ -1,5 +1,5 @@ from alembic.testing.fixtures import TestBase - +from alembic.testing import mock from alembic.testing import config, eq_, assert_raises, assert_raises_message from sqlalchemy import Table, MetaData, Column, String @@ -126,6 +126,23 @@ class TestMigrationContext(TestBase): 'as_sql': True}) eq_(context.get_current_heads(), ('q', )) + def test_stamp_api_creates_table(self): + context = self.make_one(connection=self.connection) + assert ( + 'alembic_version' + not in Inspector(self.connection).get_table_names()) + + script = mock.Mock(_stamp_revs=lambda revision, heads: [ + _up(None, 'a', True), + _up(None, 'b', True) + ]) + + context.stamp(script, 'b') + eq_(context.get_current_heads(), ('a', 'b')) + assert ( + 'alembic_version' + in Inspector(self.connection).get_table_names()) + class UpdateRevTest(TestBase): __backend__ = True |