Set autoincrement to False when modifying to non-Integer datatype

Starting in SQLAlchemy 1.1, the rules for when "autoincrement=True"
may be set on a column are more strict.  The migrate tests are
testing the alteration of a column from Integer to String
and then regenerating; this means we need to set autoincrement
to False as well.   A related issue in SQLAlchemy 1.1 is
also being fixed (see https://bitbucket.org/zzzeek/sqlalchemy/issues/3835/),
however this fix is not needed in order for the tests to pass here.

Change-Id: Ibd3a75fff13312411df87e17b6e5764865d69728
This commit is contained in:
Mike Bayer 2016-10-20 17:47:19 -04:00
parent d58469a6ae
commit e9175a37ce
2 changed files with 21 additions and 2 deletions

View File

@ -353,8 +353,14 @@ class ColumnDelta(six.with_metaclass(MyMeta, DictMixin, sqlalchemy.schema.Schema
self.process_column(self.result_column)
# create an instance of class type if not yet
if 'type' in diffs and callable(self.result_column.type):
if 'type' in diffs:
if callable(self.result_column.type):
self.result_column.type = self.result_column.type()
if self.result_column.autoincrement and \
not issubclass(
self.result_column.type._type_affinity,
sqlalchemy.Integer):
self.result_column.autoincrement = False
# add column to the table
if self.table is not None and self.alter_metadata:

View File

@ -687,12 +687,25 @@ class TestColumnChange(fixture.DB):
self.assertTrue(isinstance(self.table.c.id.type, Integer))
self.assertEqual(self.table.c.id.nullable, False)
# SQLAlchemy 1.1 adds a third state to "autoincrement" called
# "auto".
self.assertTrue(self.table.c.id.autoincrement in ('auto', True))
if not self.engine.name == 'firebird':
self.table.c.id.alter(type=String(20))
self.assertEqual(self.table.c.id.nullable, False)
# a rule makes sure that autoincrement is set to False
# when we change off of Integer
self.assertEqual(self.table.c.id.autoincrement, False)
self.refresh_table(self.table.name)
self.assertTrue(isinstance(self.table.c.id.type, String))
# note that after reflection, "autoincrement" is likely
# to change back to a database-generated value. Should be
# False or "auto". if True, it's a bug; at least one of these
# exists prior to SQLAlchemy 1.1.3
@fixture.usedb()
def test_default(self):
"""Can change a column's server_default value (DefaultClauses only)