Make table utf-8 charset checking be optional for DB migration
Add an option to the migration db_sync call to allow a project to disable the check for utf8 encoding on all tables. This allows the project to fix problems automatically via a migration, which otherwise would not be possible because the utf8 check would stop them from running migrations. Change-Id: I7f271d846141ac72dde3fb0d12159b125018eb2c Closes-bug: #1279000 Signed-off-by: Zhi Yan Liu <zhiyanl@cn.ibm.com>
This commit is contained in:
parent
72e7498e6c
commit
f7705f3a7d
|
@ -168,7 +168,7 @@ def patch_migrate():
|
|||
sqlite.SQLiteConstraintGenerator)
|
||||
|
||||
|
||||
def db_sync(engine, abs_path, version=None, init_version=0):
|
||||
def db_sync(engine, abs_path, version=None, init_version=0, sanity_check=True):
|
||||
"""Upgrade or downgrade a database.
|
||||
|
||||
Function runs the upgrade() or downgrade() functions in change scripts.
|
||||
|
@ -179,7 +179,9 @@ def db_sync(engine, abs_path, version=None, init_version=0):
|
|||
If None - database will update to the latest
|
||||
available version.
|
||||
:param init_version: Initial database version
|
||||
:param sanity_check: Require schema sanity checking for all tables
|
||||
"""
|
||||
|
||||
if version is not None:
|
||||
try:
|
||||
version = int(version)
|
||||
|
@ -189,7 +191,8 @@ def db_sync(engine, abs_path, version=None, init_version=0):
|
|||
|
||||
current_version = db_version(engine, abs_path, init_version)
|
||||
repository = _find_migrate_repo(abs_path)
|
||||
_db_schema_sanity_check(engine)
|
||||
if sanity_check:
|
||||
_db_schema_sanity_check(engine)
|
||||
if version is None or version > current_version:
|
||||
return versioning_api.upgrade(engine, repository, version)
|
||||
else:
|
||||
|
|
|
@ -176,6 +176,18 @@ class TestMigrationCommon(test_base.DbTestCase):
|
|||
|
||||
mock_sanity.assert_called_once()
|
||||
|
||||
def test_db_sync_sanity_skipped(self):
|
||||
with contextlib.nested(
|
||||
mock.patch.object(migration, '_find_migrate_repo'),
|
||||
mock.patch.object(migration, '_db_schema_sanity_check'),
|
||||
mock.patch.object(versioning_api, 'downgrade')
|
||||
) as (mock_find_repo, mock_sanity, mock_downgrade):
|
||||
|
||||
mock_find_repo.return_value = self.return_value
|
||||
migration.db_sync(self.engine, self.path, self.test_version, False)
|
||||
|
||||
mock_sanity.assert_not_called()
|
||||
|
||||
def test_db_sanity_table_not_utf8(self):
|
||||
with mock.patch.object(self, 'engine') as mock_eng:
|
||||
type(mock_eng).name = mock.PropertyMock(return_value='mysql')
|
||||
|
|
Loading…
Reference in New Issue