Handle mysql index/column already exists during migration (#37064)

This commit is contained in:
J. Nick Koston 2020-06-24 11:55:13 -05:00 committed by GitHub
parent d9a3b04e30
commit cc8e0ef942
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -4,7 +4,7 @@ import os
from sqlalchemy import Table, text
from sqlalchemy.engine import reflection
from sqlalchemy.exc import OperationalError, SQLAlchemyError
from sqlalchemy.exc import InternalError, OperationalError, SQLAlchemyError
from .models import SCHEMA_VERSION, Base, SchemaChanges
from .util import session_scope
@ -87,6 +87,13 @@ def _create_index(engine, table_name, index_name):
_LOGGER.warning(
"Index %s already exists on %s, continuing", index_name, table_name
)
except InternalError as err:
if "duplicate" not in str(err).lower():
raise
_LOGGER.warning(
"Index %s already exists on %s, continuing", index_name, table_name
)
_LOGGER.debug("Finished creating %s", index_name)
@ -178,7 +185,7 @@ def _add_columns(engine, table_name, columns_def):
)
)
return
except OperationalError:
except (InternalError, OperationalError):
# Some engines support adding all columns at once,
# this error is when they don't
_LOGGER.info("Unable to use quick column add. Adding 1 by 1.")
@ -192,7 +199,7 @@ def _add_columns(engine, table_name, columns_def):
)
)
)
except OperationalError as err:
except (InternalError, OperationalError) as err:
if "duplicate" not in str(err).lower():
raise