Remove most server_default comparison logic

Added a new test case that covers comparison of a MySQL server default
defined as text("0") in the model as well as in the database.   The
MySQL default comaprison logic in oslo.db was not accommodating of the
model side here being a text() construct.   As modern Alembic
versions supports most of the use cases tested here,
remove all server defaut comparison logic except for the boolean
comparison workaround.

Alembic minimum is bumped to 0.9.6; the issue repaired between
0.8.10 and 0.9.6 is http://alembic.zzzcomputing.com/en/latest/
changelog.html#change-5459a7552a17d8b658f0f710bedf6da0

Depends-on: I1a8244edae47b04b7b1fed54e577d6534945bcd8
Closes-bug: #1776527
Change-Id: I48a103e28d86128ea84466da4d9d6faab1dd9a9d
This commit is contained in:
Mike Bayer 2018-06-12 13:08:36 -04:00 committed by Tony Breeds
parent 4c70002578
commit 43af1cf083
4 changed files with 7 additions and 22 deletions

View File

@ -1,4 +1,4 @@
alembic==0.8.10
alembic==0.9.6
appdirs==1.3.0
Babel==2.3.4
bandit==1.4.0

View File

@ -482,26 +482,6 @@ class ModelsMigrationsSync(object):
isinstance(meta_def.arg, expr.False_) and insp_def == "0"
)
impl_type = meta_col.type
if isinstance(impl_type, types.Variant):
impl_type = impl_type.load_dialect_impl(bind.dialect)
if isinstance(impl_type, (sqlalchemy.Integer, sqlalchemy.BigInteger)):
if meta_def is None or insp_def is None:
return meta_def != insp_def
insp_def = insp_def.strip("'")
return meta_def.arg != insp_def
@_compare_server_default.dispatch_for('postgresql')
def _compare_server_default(bind, meta_col, insp_def, meta_def):
if isinstance(meta_col.type, sqlalchemy.Enum):
if meta_def is None or insp_def is None:
return meta_def != insp_def
return insp_def != "'%s'::%s" % (meta_def.arg, meta_col.type.name)
elif isinstance(meta_col.type, sqlalchemy.String):
if meta_def is None or insp_def is None:
return meta_def != insp_def
return insp_def != "'%s'::character varying" % meta_def.arg
FKInfo = collections.namedtuple('fk_info', ['constrained_columns',
'referred_table',
'referred_columns'])

View File

@ -203,6 +203,7 @@ class ModelsMigrationSyncMixin(test_base._DbTestCase):
sa.Column('defaulttest4', sa.Enum('first', 'second',
name='testenum'),
server_default="first"),
sa.Column("defaulttest5", sa.Integer, server_default=sa.text('0')),
sa.Column('variant', sa.BigInteger()),
sa.Column('variant2', sa.BigInteger(), server_default='0'),
sa.Column('fk_check', sa.String(36), nullable=False),
@ -233,6 +234,8 @@ class ModelsMigrationSyncMixin(test_base._DbTestCase):
defaulttest4 = sa.Column('defaulttest4', sa.Enum('first', 'second',
name='testenum'),
server_default="first")
defaulttest5 = sa.Column("defaulttest5",
sa.Integer, server_default=sa.text('0'))
variant = sa.Column(sa.BigInteger().with_variant(
sa.Integer(), 'sqlite'))
variant2 = sa.Column(sa.BigInteger().with_variant(
@ -284,6 +287,7 @@ class ModelsMigrationSyncMixin(test_base._DbTestCase):
sa.Column('defaulttest4',
sa.Enum('first', 'second', name='testenum'),
server_default="first"),
sa.Column("defaulttest5", sa.Integer, server_default=sa.text('0')),
sa.Column('fk_check', sa.String(36), nullable=False),
sa.UniqueConstraint('spam', 'foo', name='uniq_cons'),
sa.ForeignKeyConstraint(['fk_check'], ['table.fk_check']),
@ -330,6 +334,7 @@ class ModelsMigrationSyncMixin(test_base._DbTestCase):
sa.Column('defaulttest4',
sa.Enum('first', 'second', name='testenum'),
server_default="first"),
sa.Column("defaulttest5", sa.Integer, server_default=sa.text('0')),
sa.Column('variant', sa.String(10)),
sa.Column('fk_check', sa.String(36), nullable=False),
sa.UniqueConstraint('spam', 'foo', name='uniq_cons'),

View File

@ -3,7 +3,7 @@
# process, which may cause wedges in the gate later.
pbr!=2.1.0,>=2.0.0 # Apache-2.0
alembic>=0.8.10 # MIT
alembic>=0.9.6 # MIT
debtcollector>=1.2.0 # Apache-2.0
oslo.i18n>=3.15.3 # Apache-2.0
oslo.config>=5.2.0 # Apache-2.0