]> git.ipfire.org Git - thirdparty/sqlalchemy/alembic.git/commitdiff
- The :meth:`.MigrationContext.stamp` method, added as part of the
authorMike Bayer <mike_mp@zzzcomputing.com>
Tue, 9 Jun 2015 15:40:34 +0000 (11:40 -0400)
committerMike Bayer <mike_mp@zzzcomputing.com>
Tue, 9 Jun 2015 15:40:34 +0000 (11:40 -0400)
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

alembic/migration.py
docs/build/changelog.rst
tests/test_version_table.py

index d94db2e2e268aba7e03ea24068856da67afb865c..9b46052057053cbd8aeb6357d2fb27e92ba1e82a 100644 (file)
@@ -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)
index e11713a1dcadb7d343f614ec5195b3c7d7897ce4..9c06825459fb53499114828235af9eaf3a025f4c 100644 (file)
@@ -6,6 +6,16 @@ Changelog
 .. 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
index 704bb317ee607783d509de926e08adf17600ccbf..92cb447c2101e1550ef92bc02f4137e380239241 100644 (file)
@@ -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