From 337d8803050e77e88bc73547f2e862cdb80dd188 Mon Sep 17 00:00:00 2001 From: David Szotten Date: Fri, 17 Jun 2016 12:54:57 -0400 Subject: [PATCH] Include DateTime.timezone in autogen type comparisons Change-Id: I2e5b380625ec45d5ebc0bc74daf9cf9e05f0155a Pull-request: https://github.com/zzzeek/alembic/pull/26 --- alembic/ddl/impl.py | 10 +++++++++- docs/build/changelog.rst | 7 +++++++ tests/test_autogen_diffs.py | 10 ++++++++++ 3 files changed, 26 insertions(+), 1 deletion(-) diff --git a/alembic/ddl/impl.py b/alembic/ddl/impl.py index d87a2fcb..56b4d59c 100644 --- a/alembic/ddl/impl.py +++ b/alembic/ddl/impl.py @@ -350,8 +350,16 @@ def _integer_compare(t1, t2): ) return t1_small_or_big != t2_small_or_big + +def _datetime_compare(t1, t2): + return ( + t1.timezone != t2.timezone + ) + + _type_comparators = { sqltypes.String: _string_compare, sqltypes.Numeric: _numeric_compare, - sqltypes.Integer: _integer_compare + sqltypes.Integer: _integer_compare, + sqltypes.DateTime: _datetime_compare, } diff --git a/docs/build/changelog.rst b/docs/build/changelog.rst index ebd54fda..cd9ce411 100644 --- a/docs/build/changelog.rst +++ b/docs/build/changelog.rst @@ -15,6 +15,13 @@ Changelog :paramref:`.op.alter_column.postgresql_using` parameter. Pull request courtesy Frazer McLean. + .. change: + :tags: feature, autogenerate + + Autogenerate with type comparison enabled will pick up on the timezone + setting changing between DateTime types. Pull request courtesy + David Szotten. + .. changelog:: :version: 0.8.7 :released: July 26, 2016 diff --git a/tests/test_autogen_diffs.py b/tests/test_autogen_diffs.py index c2c385de..04c9e967 100644 --- a/tests/test_autogen_diffs.py +++ b/tests/test_autogen_diffs.py @@ -630,6 +630,16 @@ class CompareTypeSpecificityTest(TestBase): is_(impl.compare_type(Column('x', t5), Column('x', t2)), True) is_(impl.compare_type(Column('x', t1), Column('x', t4)), True) + def test_datetime(self): + t1 = DateTime() + t2 = DateTime(timezone=False) + t3 = DateTime(timezone=True) + + impl = self._fixture() + is_(impl.compare_type(Column('x', t1), Column('x', t2)), False) + is_(impl.compare_type(Column('x', t1), Column('x', t3)), True) + is_(impl.compare_type(Column('x', t2), Column('x', t3)), True) + class AutogenerateCustomCompareTypeTest(AutogenTest, TestBase): __only_on__ = 'sqlite' -- 2.47.2