t1.scale is not None and
t1.scale != t2.scale
)
+
+
+def _integer_compare(t1, t2):
+ t1_small_or_big = (
+ 'S' if isinstance(t1, sqltypes.SmallInteger)
+ else 'B' if isinstance(t1, sqltypes.BigInteger) else 'I'
+ )
+ t2_small_or_big = (
+ 'S' if isinstance(t2, sqltypes.SmallInteger)
+ else 'B' if isinstance(t2, sqltypes.BigInteger) else 'I'
+ )
+ return t1_small_or_big != t2_small_or_big
+
_type_comparators = {
sqltypes.String: _string_compare,
- sqltypes.Numeric: _numeric_compare
+ sqltypes.Numeric: _numeric_compare,
+ sqltypes.Integer: _integer_compare
}
from sqlalchemy import MetaData, Column, Table, Integer, String, Text, \
Numeric, CHAR, ForeignKey, INTEGER, Index, UniqueConstraint, \
TypeDecorator, CheckConstraint, text, PrimaryKeyConstraint, \
- ForeignKeyConstraint
+ ForeignKeyConstraint, VARCHAR, DECIMAL, DateTime, BigInteger, BIGINT, \
+ SmallInteger
from sqlalchemy.types import NULLTYPE
from sqlalchemy.engine.reflection import Inspector
eq_(diffs[10][3].name, 'pw')
+class CompareTypeSpecificityTest(TestBase):
+ def _fixture(self):
+ from alembic.ddl import impl
+ from sqlalchemy.engine import default
+
+ return impl.DefaultImpl(
+ default.DefaultDialect(), None, False, True, None, {})
+
+ def test_string(self):
+ t1 = String(30)
+ t2 = String(40)
+ t3 = VARCHAR(30)
+ t4 = Integer
+
+ impl = self._fixture()
+ is_(impl.compare_type(Column('x', t3), Column('x', t1)), False)
+ is_(impl.compare_type(Column('x', t3), Column('x', t2)), True)
+ is_(impl.compare_type(Column('x', t3), Column('x', t4)), True)
+
+ def test_numeric(self):
+ t1 = Numeric(10, 5)
+ t2 = Numeric(12, 5)
+ t3 = DECIMAL(10, 5)
+ t4 = DateTime
+
+ impl = self._fixture()
+ is_(impl.compare_type(Column('x', t3), Column('x', t1)), False)
+ is_(impl.compare_type(Column('x', t3), Column('x', t2)), True)
+ is_(impl.compare_type(Column('x', t3), Column('x', t4)), True)
+
+ def test_integer(self):
+ t1 = Integer()
+ t2 = SmallInteger()
+ t3 = BIGINT()
+ t4 = String()
+ t5 = INTEGER()
+ t6 = BigInteger()
+
+ impl = self._fixture()
+ is_(impl.compare_type(Column('x', t5), Column('x', t1)), False)
+ is_(impl.compare_type(Column('x', t3), Column('x', t1)), True)
+ is_(impl.compare_type(Column('x', t3), Column('x', t6)), False)
+ is_(impl.compare_type(Column('x', t3), Column('x', t2)), True)
+ is_(impl.compare_type(Column('x', t5), Column('x', t2)), True)
+ is_(impl.compare_type(Column('x', t1), Column('x', t4)), True)
+
+
class AutogenerateCustomCompareTypeTest(AutogenTest, TestBase):
__only_on__ = 'sqlite'