Correct migration to recorder schema 18 (#57165)

This commit is contained in:
Erik Montnemery 2021-10-06 13:29:42 +02:00 committed by GitHub
parent 9d84d41f81
commit 8337baa354
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -470,17 +470,20 @@ def _apply_update(instance, session, new_version, old_version): # noqa: C901
elif new_version == 18: elif new_version == 18:
# Recreate the statistics and statistics meta tables. # Recreate the statistics and statistics meta tables.
# #
# Order matters! Statistics has a relation with StatisticsMeta, # Order matters! Statistics and StatisticsShortTerm have a relation with
# so statistics need to be deleted before meta (or in pair depending # StatisticsMeta, so statistics need to be deleted before meta (or in pair
# on the SQL backend); and meta needs to be created before statistics. # depending on the SQL backend); and meta needs to be created before statistics.
if sqlalchemy.inspect(engine).has_table(
StatisticsMeta.__tablename__
) or sqlalchemy.inspect(engine).has_table(Statistics.__tablename__):
Base.metadata.drop_all( Base.metadata.drop_all(
bind=engine, tables=[Statistics.__table__, StatisticsMeta.__table__] bind=engine,
tables=[
StatisticsShortTerm.__table__,
Statistics.__table__,
StatisticsMeta.__table__,
],
) )
StatisticsMeta.__table__.create(engine) StatisticsMeta.__table__.create(engine)
StatisticsShortTerm.__table__.create(engine)
Statistics.__table__.create(engine) Statistics.__table__.create(engine)
elif new_version == 19: elif new_version == 19:
# This adds the statistic runs table, insert a fake run to prevent duplicating # This adds the statistic runs table, insert a fake run to prevent duplicating
@ -527,14 +530,6 @@ def _apply_update(instance, session, new_version, old_version): # noqa: C901
# so statistics need to be deleted before meta (or in pair depending # so statistics need to be deleted before meta (or in pair depending
# on the SQL backend); and meta needs to be created before statistics. # on the SQL backend); and meta needs to be created before statistics.
if engine.dialect.name == "oracle": if engine.dialect.name == "oracle":
if (
sqlalchemy.inspect(engine).has_table(StatisticsMeta.__tablename__)
or sqlalchemy.inspect(engine).has_table(Statistics.__tablename__)
or sqlalchemy.inspect(engine).has_table(StatisticsRuns.__tablename__)
or sqlalchemy.inspect(engine).has_table(
StatisticsShortTerm.__tablename__
)
):
Base.metadata.drop_all( Base.metadata.drop_all(
bind=engine, bind=engine,
tables=[ tables=[