Ignore migration 127 error on MariaDB

Older MariaDB, and InnoDB with 4K page sizes [1], don't support a text fields
to have more than 767 bytes, which means that we cannot extend the quota_usage
_resource to 300 characters on migration 127.

Since this migration is to cover a corner case, we ignore the exception
during the migration if we are on a MySQL DB engine.

[1]: https://mariadb.com/kb/en/library/innodb-limitations/#page-sizes

Closes-Bug: #1808598
Change-Id: Id990b98f0ac7aaedf48a77ebee2b083fcbdaaee7
This commit is contained in:
Gorka Eguileor 2018-12-19 11:51:18 +01:00 committed by Sean McGinnis
parent 203db865a6
commit cea54bb544
No known key found for this signature in database
GPG Key ID: CE7EE4BFAF8D70C8
2 changed files with 23 additions and 1 deletions

View File

@ -21,7 +21,18 @@ def upgrade(migrate_engine):
prefix such as 'volumes_' or 'gigabytes_' to volume_type_name it
will exceed the db length limit.
"""
# On MariaDB, max length varies depending on the version and the InnoDB
# page size [1], so it is possible to have error 1071 ('Specified key was
# too long; max key length is 767 bytes"). Since this migration is to
# resolve a corner case, deployments with those DB versions won't be
# covered.
# [1]: https://mariadb.com/kb/en/library/innodb-limitations/#page-sizes
hide_failure = migrate_engine.name.startswith('mysql')
meta = MetaData(bind=migrate_engine)
quota_usages = Table('quota_usages', meta, autoload=True)
quota_usages.c.resource.alter(type=String(300))
try:
quota_usages.c.resource.alter(type=String(300))
except Exception:
if not hide_failure:
raise

View File

@ -469,6 +469,17 @@ class TestMysqlMigrations(test_fixtures.OpportunisticDBTestMixin,
count = noninnodb.scalar()
self.assertEqual(count, 0, "%d non InnoDB tables created" % count)
def _check_127(self, engine, data):
quota_usage_resource = db_utils.get_table(engine, 'quota_usages')
self.assertIn('resource', quota_usage_resource.c)
self.assertIsInstance(quota_usage_resource.c.resource.type,
self.VARCHAR_TYPE)
# Depending on the MariaDB version, and the page size, we may not have
# been able to change quota_usage_resource to 300 chars, it could still
# be 255.
self.assertIn(quota_usage_resource.c.resource.type.length,
(255, 300))
class TestPostgresqlMigrations(test_fixtures.OpportunisticDBTestMixin,
MigrationsMixin,