From a7216e627988e62c7883eef4282785c30b3b5048 Mon Sep 17 00:00:00 2001 From: Matthias Date: Fri, 21 May 2021 20:53:38 +0200 Subject: [PATCH] SQLite does not know drop column --- tests/test_persistence.py | 48 ++++++++++++++++++++++++++++++++++++--- 1 file changed, 45 insertions(+), 3 deletions(-) diff --git a/tests/test_persistence.py b/tests/test_persistence.py index 38fe3ff94..2949fdfe9 100644 --- a/tests/test_persistence.py +++ b/tests/test_persistence.py @@ -7,7 +7,7 @@ from unittest.mock import MagicMock import arrow import pytest -from sqlalchemy import create_engine +from sqlalchemy import create_engine, inspect from freqtrade import constants from freqtrade.exceptions import DependencyException, OperationalException @@ -629,11 +629,53 @@ def test_migrate_new(mocker, default_conf, fee, caplog): caplog.clear() # Drop latest column - engine.execute("alter table orders drop column average") + engine.execute("alter table orders rename to orders_bak") + inspector = inspect(engine) + + for index in inspector.get_indexes('orders_bak'): + engine.execute(f"drop index {index['name']}") + # Recreate table + engine.execute(""" + CREATE TABLE orders ( + id INTEGER NOT NULL, + ft_trade_id INTEGER, + ft_order_side VARCHAR NOT NULL, + ft_pair VARCHAR NOT NULL, + ft_is_open BOOLEAN NOT NULL, + order_id VARCHAR NOT NULL, + status VARCHAR, + symbol VARCHAR, + order_type VARCHAR, + side VARCHAR, + price FLOAT, + amount FLOAT, + filled FLOAT, + remaining FLOAT, + cost FLOAT, + order_date DATETIME, + order_filled_date DATETIME, + order_update_date DATETIME, + PRIMARY KEY (id), + CONSTRAINT _order_pair_order_id UNIQUE (ft_pair, order_id), + FOREIGN KEY(ft_trade_id) REFERENCES trades (id) + ) + """ + ) + + engine.execute(""" + insert into orders ( id, ft_trade_id, ft_order_side, ft_pair, ft_is_open, order_id, status, + symbol, order_type, side, price, amount, filled, remaining, cost, order_date, + order_filled_date, order_update_date) + select id, ft_trade_id, ft_order_side, ft_pair, ft_is_open, order_id, status, + symbol, order_type, side, price, amount, filled, remaining, cost, order_date, + order_filled_date, order_update_date + from orders_bak + """) + # Run init to test migration init_db(default_conf['db_url'], default_conf['dry_run']) - assert log_has("trying orders_bak0", caplog) + assert log_has("trying orders_bak1", caplog) orders = Order.query.all() assert len(orders) == 2