]> git.ipfire.org Git - thirdparty/sqlalchemy/alembic.git/commitdiff
Don't remove None for default schema of None
authorMike Bayer <mike_mp@zzzcomputing.com>
Wed, 29 Jun 2016 20:22:24 +0000 (16:22 -0400)
committerMike Bayer <mike_mp@zzzcomputing.com>
Wed, 29 Jun 2016 20:22:24 +0000 (16:22 -0400)
Fixed bug in autogen where if the DB connection sends the default
schema as "None", this "None" would be removed from the list of
schemas to check if include_schemas were set.  This could possibly
impact using include_schemas with SQLite.

Change-Id: I553cdbbe2cfaa5228d86019e14f7c9f56231f295

alembic/autogenerate/compare.py
docs/build/changelog.rst
tests/test_autogen_diffs.py

index a4e5f7bde80a5362e400e8d38b786206ed95a380..1b721b037136a48ad2deb61727b0b9b65c9747c0 100644 (file)
@@ -39,8 +39,8 @@ def _produce_net_changes(autogen_context, upgrade_ops):
         # replace default schema name with None
         schemas.discard("information_schema")
         # replace the "default" schema with None
-        schemas.add(None)
         schemas.discard(default_schema)
+        schemas.add(None)
     else:
         schemas = [None]
 
index ed4e29d53745197cbc9b9794da36156d19330153..1308a293352df924b7c9907311460d8404a3d150 100644 (file)
@@ -6,6 +6,14 @@ Changelog
 .. changelog::
     :version: 0.8.7
 
+    .. change::
+      :tags: bug, autogenerate
+
+      Fixed bug in autogen where if the DB connection sends the default
+      schema as "None", this "None" would be removed from the list of
+      schemas to check if include_schemas were set.  This could possibly
+      impact using include_schemas with SQLite.
+
     .. change::
       :tags: bug, batch
 
index 6887058fa81151160d0c432cf7e33a90027ed6dd..c2c385de395813161849ec3bbf71f0d37ec2583a 100644 (file)
@@ -14,7 +14,7 @@ from alembic.migration import MigrationContext
 from alembic.testing import TestBase
 from alembic.testing import config
 from alembic.testing import assert_raises_message
-from alembic.testing.mock import Mock
+from alembic.testing.mock import Mock, patch
 from alembic.testing import eq_, is_, is_not_
 from alembic.util import CommandError
 from ._autogen_fixtures import AutogenTest, AutogenFixtureTest
@@ -188,6 +188,35 @@ class AutogenDefaultSchemaTest(AutogenFixtureTest, TestBase):
         eq_(diffs[0][1].c.keys(), ['x'])
 
 
+class AutogenDefaultSchemaIsNoneTest(AutogenFixtureTest, TestBase):
+    __only_on__ = 'sqlite'
+
+    def setUp(self):
+        super(AutogenDefaultSchemaIsNoneTest, self).setUp()
+
+        # prerequisite
+        eq_(self.bind.dialect.default_schema_name, None)
+
+    def test_no_default_schema(self):
+
+        m1 = MetaData()
+        m2 = MetaData()
+
+        Table('a', m1, Column('x', String(50)))
+        Table('a', m2, Column('x', String(50)))
+
+        def _include_object(obj, name, type_, reflected, compare_to):
+            if type_ == "table":
+                return name in 'a' and obj.schema != 'main'
+            else:
+                return True
+
+        diffs = self._fixture(
+            m1, m2, include_schemas=True,
+            object_filters=_include_object)
+        eq_(len(diffs), 0)
+
+
 class ModelOne(object):
     __requires__ = ('unique_constraint_reflection', )