mirror of
https://github.com/home-assistant/core.git
synced 2025-07-10 06:47:09 +00:00
Handle mysql index/column already exists during migration (#37064)
This commit is contained in:
parent
d9a3b04e30
commit
cc8e0ef942
@ -4,7 +4,7 @@ import os
|
|||||||
|
|
||||||
from sqlalchemy import Table, text
|
from sqlalchemy import Table, text
|
||||||
from sqlalchemy.engine import reflection
|
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 .models import SCHEMA_VERSION, Base, SchemaChanges
|
||||||
from .util import session_scope
|
from .util import session_scope
|
||||||
@ -87,6 +87,13 @@ def _create_index(engine, table_name, index_name):
|
|||||||
_LOGGER.warning(
|
_LOGGER.warning(
|
||||||
"Index %s already exists on %s, continuing", index_name, table_name
|
"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)
|
_LOGGER.debug("Finished creating %s", index_name)
|
||||||
|
|
||||||
@ -178,7 +185,7 @@ def _add_columns(engine, table_name, columns_def):
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
return
|
return
|
||||||
except OperationalError:
|
except (InternalError, OperationalError):
|
||||||
# Some engines support adding all columns at once,
|
# Some engines support adding all columns at once,
|
||||||
# this error is when they don't
|
# this error is when they don't
|
||||||
_LOGGER.info("Unable to use quick column add. Adding 1 by 1.")
|
_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():
|
if "duplicate" not in str(err).lower():
|
||||||
raise
|
raise
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user