Cherry pick oslo-incubator db fixes
The patch cherrypicks 2 fixes related to utf8 migration: * Ib5c0f93c788afda92aad862e50dc086dc39605f1: Ignore migrate versioning tables in utf8 sanity check * I7f271d846141ac72dde3fb0d12159b125018eb2c: Make table utf-8 charset checking be optional for DB migration Change-Id: Icb811e846c05f863a42611054f2e3f30a47573db Closes-Bug: #1301036
This commit is contained in:
parent
4c94cdc3f1
commit
4f9b62a2a5
|
@ -200,7 +200,7 @@ def patch_migrate():
|
||||||
sqlite.SQLiteConstraintGenerator)
|
sqlite.SQLiteConstraintGenerator)
|
||||||
|
|
||||||
|
|
||||||
def db_sync(abs_path, version=None, init_version=0):
|
def db_sync(abs_path, version=None, init_version=0, sanity_check=True):
|
||||||
"""Upgrade or downgrade a database.
|
"""Upgrade or downgrade a database.
|
||||||
|
|
||||||
Function runs the upgrade() or downgrade() functions in change scripts.
|
Function runs the upgrade() or downgrade() functions in change scripts.
|
||||||
|
@ -210,7 +210,9 @@ def db_sync(abs_path, version=None, init_version=0):
|
||||||
If None - database will update to the latest
|
If None - database will update to the latest
|
||||||
available version.
|
available version.
|
||||||
:param init_version: Initial database version
|
:param init_version: Initial database version
|
||||||
|
:param sanity_check: Require schema sanity checking for all tables
|
||||||
"""
|
"""
|
||||||
|
|
||||||
if version is not None:
|
if version is not None:
|
||||||
try:
|
try:
|
||||||
version = int(version)
|
version = int(version)
|
||||||
|
@ -220,7 +222,8 @@ def db_sync(abs_path, version=None, init_version=0):
|
||||||
|
|
||||||
current_version = db_version(abs_path, init_version)
|
current_version = db_version(abs_path, init_version)
|
||||||
repository = _find_migrate_repo(abs_path)
|
repository = _find_migrate_repo(abs_path)
|
||||||
_db_schema_sanity_check()
|
if sanity_check:
|
||||||
|
_db_schema_sanity_check()
|
||||||
if version is None or version > current_version:
|
if version is None or version > current_version:
|
||||||
return versioning_api.upgrade(get_engine(), repository, version)
|
return versioning_api.upgrade(get_engine(), repository, version)
|
||||||
else:
|
else:
|
||||||
|
@ -236,8 +239,15 @@ def _db_schema_sanity_check():
|
||||||
'where TABLE_SCHEMA=%s and '
|
'where TABLE_SCHEMA=%s and '
|
||||||
'TABLE_COLLATION NOT LIKE "%%utf8%%"')
|
'TABLE_COLLATION NOT LIKE "%%utf8%%"')
|
||||||
|
|
||||||
table_names = [res[0] for res in engine.execute(onlyutf8_sql,
|
# NOTE(morganfainberg): exclude the sqlalchemy-migrate and alembic
|
||||||
engine.url.database)]
|
# 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:
|
if len(table_names) > 0:
|
||||||
raise ValueError(_('Tables "%s" have non utf8 collation, '
|
raise ValueError(_('Tables "%s" have non utf8 collation, '
|
||||||
'please make sure all tables are CHARSET=utf8'
|
'please make sure all tables are CHARSET=utf8'
|
||||||
|
|
Loading…
Reference in New Issue