Fix Statistics recorder migration path by dropping in pairs (#52453)
parent
5e9127ef7a
commit
74029a0948
|
@ -461,14 +461,19 @@ def _apply_update(engine, session, new_version, old_version):
|
||||||
# This dropped the statistics table, done again in version 18.
|
# This dropped the statistics table, done again in version 18.
|
||||||
pass
|
pass
|
||||||
elif new_version == 18:
|
elif new_version == 18:
|
||||||
# Recreate the statisticsmeta tables
|
# Recreate the statistics and statistics meta tables.
|
||||||
if sqlalchemy.inspect(engine).has_table(StatisticsMeta.__tablename__):
|
#
|
||||||
StatisticsMeta.__table__.drop(engine)
|
# Order matters! Statistics has a relation with StatisticsMeta,
|
||||||
StatisticsMeta.__table__.create(engine)
|
# so statistics need to be deleted before meta (or in pair 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(
|
||||||
|
bind=engine, tables=[Statistics.__table__, StatisticsMeta.__table__]
|
||||||
|
)
|
||||||
|
|
||||||
# Recreate the statistics table
|
StatisticsMeta.__table__.create(engine)
|
||||||
if sqlalchemy.inspect(engine).has_table(Statistics.__tablename__):
|
|
||||||
Statistics.__table__.drop(engine)
|
|
||||||
Statistics.__table__.create(engine)
|
Statistics.__table__.create(engine)
|
||||||
else:
|
else:
|
||||||
raise ValueError(f"No schema migration defined for version {new_version}")
|
raise ValueError(f"No schema migration defined for version {new_version}")
|
||||||
|
|
Loading…
Reference in New Issue