Merge pull request #1397 from freqtrade/fix/db_migration

Drop indexes on renamed table during migration
This commit is contained in:
Misagh 2018-12-09 11:15:02 +01:00 committed by GitHub
commit 7e476e6144
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 0 deletions

View File

@ -100,6 +100,9 @@ def check_migrate(engine) -> None:
# Schema migration necessary # Schema migration necessary
engine.execute(f"alter table trades rename to {table_back_name}") engine.execute(f"alter table trades rename to {table_back_name}")
# drop indexes on backup table
for index in inspector.get_indexes(table_back_name):
engine.execute(f"drop index {index['name']}")
# let SQLAlchemy create the schema as required # let SQLAlchemy create the schema as required
_DECL_BASE.metadata.create_all(engine) _DECL_BASE.metadata.create_all(engine)

View File

@ -446,6 +446,8 @@ def test_migrate_new(mocker, default_conf, fee, caplog):
# Create table using the old format # Create table using the old format
engine.execute(create_table_old) engine.execute(create_table_old)
engine.execute("create index ix_trades_is_open on trades(is_open)")
engine.execute("create index ix_trades_pair on trades(pair)")
engine.execute(insert_table_old) engine.execute(insert_table_old)
# fake previous backup # fake previous backup