]> git.ipfire.org Git - thirdparty/sqlalchemy/alembic.git/commitdiff
Include DateTime.timezone in autogen type comparisons
authorDavid Szotten <davidszotten@gmail.com>
Fri, 17 Jun 2016 16:54:57 +0000 (12:54 -0400)
committerMike Bayer <mike_mp@zzzcomputing.com>
Mon, 22 Aug 2016 21:50:35 +0000 (17:50 -0400)
Change-Id: I2e5b380625ec45d5ebc0bc74daf9cf9e05f0155a
Pull-request: https://github.com/zzzeek/alembic/pull/26

alembic/ddl/impl.py
docs/build/changelog.rst
tests/test_autogen_diffs.py

index d87a2fcb0ae6da29022e7bdb21605001e6c28aea..56b4d59c9ca065222d3d23d108fdef7b19800e9b 100644 (file)
@@ -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,
 }
index ebd54fdace9daec96d4866443a4bd48c167404f4..cd9ce411db1e3ec0ca5eccc89298511faf1f3379 100644 (file)
@@ -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
index c2c385de395813161849ec3bbf71f0d37ec2583a..04c9e9671511c87c3ec66b9742bd51de7159108d 100644 (file)
@@ -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'