Ignore migrate versioning tables in utf8 sanity check

The migration version tables for alembic and sqlalchemy-migrate should
not be validated to be utf8. This is because these tools are not
explicitly part of the database schema defined in the projects. In certain
configurations it is not possible to ensure these tables will be utf8
character set unless a change to the my.cnf or explicit character set
on table creation is specified.

Change-Id: Ib5c0f93c788afda92aad862e50dc086dc39605f1
Closes-Bug: #1301036
This commit is contained in:
Morgan Fainberg 2014-04-01 17:56:13 -07:00
parent 087578b7a0
commit a83bfb9f57
2 changed files with 22 additions and 2 deletions

View File

@ -213,8 +213,15 @@ def _db_schema_sanity_check(engine):
'where TABLE_SCHEMA=%s and '
'TABLE_COLLATION NOT LIKE "%%utf8%%"')
table_names = [res[0] for res in engine.execute(onlyutf8_sql,
engine.url.database)]
# NOTE(morganfainberg): exclude the sqlalchemy-migrate and alembic
# versioning tables from the tables we need to verify utf8 status on.
# Non-standard table names are not supported.
EXCLUDED_TABLES = ['migrate_version', 'alembic_version']
table_names = [res[0] for res in
engine.execute(onlyutf8_sql, engine.url.database) if
res[0].lower() not in EXCLUDED_TABLES]
if len(table_names) > 0:
raise ValueError(_('Tables "%s" have non utf8 collation, '
'please make sure all tables are CHARSET=utf8'

View File

@ -196,3 +196,16 @@ class TestMigrationCommon(test_base.DbTestCase):
self.assertRaises(ValueError, migration._db_schema_sanity_check,
mock_eng)
def test_db_sanity_table_not_utf8_exclude_migrate_tables(self):
with mock.patch.object(self, 'engine') as mock_eng:
type(mock_eng).name = mock.PropertyMock(return_value='mysql')
# NOTE(morganfainberg): Check both lower and upper case versions
# of the migration table names (validate case insensitivity in
# the sanity check.
mock_eng.execute.return_value = [['migrate_version', 'latin1'],
['alembic_version', 'latin1'],
['MIGRATE_VERSION', 'latin1'],
['ALEMBIC_VERSION', 'latin1']]
migration._db_schema_sanity_check(mock_eng)