From: Mike Bayer Date: Wed, 29 Jun 2016 20:22:24 +0000 (-0400) Subject: Don't remove None for default schema of None X-Git-Tag: rel_0_8_7~7 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=cad2dafa730f0d33a57a6f7483f8f08b297f277c;p=thirdparty%2Fsqlalchemy%2Falembic.git Don't remove None for default schema of None 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 --- diff --git a/alembic/autogenerate/compare.py b/alembic/autogenerate/compare.py index a4e5f7bd..1b721b03 100644 --- a/alembic/autogenerate/compare.py +++ b/alembic/autogenerate/compare.py @@ -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] diff --git a/docs/build/changelog.rst b/docs/build/changelog.rst index ed4e29d5..1308a293 100644 --- a/docs/build/changelog.rst +++ b/docs/build/changelog.rst @@ -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 diff --git a/tests/test_autogen_diffs.py b/tests/test_autogen_diffs.py index 6887058f..c2c385de 100644 --- a/tests/test_autogen_diffs.py +++ b/tests/test_autogen_diffs.py @@ -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', )