Browse Source

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-5459a7552a

Depends-on: I1a8244edae47b04b7b1fed54e577d6534945bcd8
Closes-bug: #1776527
Change-Id: I48a103e28d86128ea84466da4d9d6faab1dd9a9d
Mike Bayer 10 months ago
parent
commit
43af1cf083

+ 1
- 1
lower-constraints.txt View File

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

+ 0
- 20
oslo_db/sqlalchemy/test_migrations.py View File

@@ -482,26 +482,6 @@ class ModelsMigrationsSync(object):
482 482
                 isinstance(meta_def.arg, expr.False_) and insp_def == "0"
483 483
             )
484 484
 
485
-        impl_type = meta_col.type
486
-        if isinstance(impl_type, types.Variant):
487
-            impl_type = impl_type.load_dialect_impl(bind.dialect)
488
-        if isinstance(impl_type, (sqlalchemy.Integer, sqlalchemy.BigInteger)):
489
-            if meta_def is None or insp_def is None:
490
-                return meta_def != insp_def
491
-            insp_def = insp_def.strip("'")
492
-            return meta_def.arg != insp_def
493
-
494
-    @_compare_server_default.dispatch_for('postgresql')
495
-    def _compare_server_default(bind, meta_col, insp_def, meta_def):
496
-        if isinstance(meta_col.type, sqlalchemy.Enum):
497
-            if meta_def is None or insp_def is None:
498
-                return meta_def != insp_def
499
-            return insp_def != "'%s'::%s" % (meta_def.arg, meta_col.type.name)
500
-        elif isinstance(meta_col.type, sqlalchemy.String):
501
-            if meta_def is None or insp_def is None:
502
-                return meta_def != insp_def
503
-            return insp_def != "'%s'::character varying" % meta_def.arg
504
-
505 485
     FKInfo = collections.namedtuple('fk_info', ['constrained_columns',
506 486
                                                 'referred_table',
507 487
                                                 'referred_columns'])

+ 5
- 0
oslo_db/tests/sqlalchemy/test_migrations.py View File

@@ -203,6 +203,7 @@ class ModelsMigrationSyncMixin(test_base._DbTestCase):
203 203
             sa.Column('defaulttest4', sa.Enum('first', 'second',
204 204
                                               name='testenum'),
205 205
                       server_default="first"),
206
+            sa.Column("defaulttest5", sa.Integer, server_default=sa.text('0')),
206 207
             sa.Column('variant', sa.BigInteger()),
207 208
             sa.Column('variant2', sa.BigInteger(), server_default='0'),
208 209
             sa.Column('fk_check', sa.String(36), nullable=False),
@@ -233,6 +234,8 @@ class ModelsMigrationSyncMixin(test_base._DbTestCase):
233 234
             defaulttest4 = sa.Column('defaulttest4', sa.Enum('first', 'second',
234 235
                                                              name='testenum'),
235 236
                                      server_default="first")
237
+            defaulttest5 = sa.Column("defaulttest5",
238
+                                     sa.Integer, server_default=sa.text('0'))
236 239
             variant = sa.Column(sa.BigInteger().with_variant(
237 240
                 sa.Integer(), 'sqlite'))
238 241
             variant2 = sa.Column(sa.BigInteger().with_variant(
@@ -284,6 +287,7 @@ class ModelsMigrationSyncMixin(test_base._DbTestCase):
284 287
             sa.Column('defaulttest4',
285 288
                       sa.Enum('first', 'second', name='testenum'),
286 289
                       server_default="first"),
290
+            sa.Column("defaulttest5", sa.Integer, server_default=sa.text('0')),
287 291
             sa.Column('fk_check', sa.String(36), nullable=False),
288 292
             sa.UniqueConstraint('spam', 'foo', name='uniq_cons'),
289 293
             sa.ForeignKeyConstraint(['fk_check'], ['table.fk_check']),
@@ -330,6 +334,7 @@ class ModelsMigrationSyncMixin(test_base._DbTestCase):
330 334
             sa.Column('defaulttest4',
331 335
                       sa.Enum('first', 'second', name='testenum'),
332 336
                       server_default="first"),
337
+            sa.Column("defaulttest5", sa.Integer, server_default=sa.text('0')),
333 338
             sa.Column('variant', sa.String(10)),
334 339
             sa.Column('fk_check', sa.String(36), nullable=False),
335 340
             sa.UniqueConstraint('spam', 'foo', name='uniq_cons'),

+ 1
- 1
requirements.txt View File

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

Loading…
Cancel
Save