Implement database migration to other system

This commit is contained in:
Matthias 2022-05-09 19:26:38 +02:00
parent c3b0f6b64b
commit 0958c06b84
2 changed files with 36 additions and 1 deletions

View File

@ -1,9 +1,40 @@
import logging
from typing import Any, Dict from typing import Any, Dict
from freqtrade.configuration.config_setup import setup_utils_configuration from freqtrade.configuration.config_setup import setup_utils_configuration
from freqtrade.enums.runmode import RunMode from freqtrade.enums.runmode import RunMode
logger = logging.getLogger(__name__)
def start_db_convert(args: Dict[str, Any]) -> None: def start_db_convert(args: Dict[str, Any]) -> None:
from sqlalchemy.orm import make_transient
from freqtrade.persistence import Trade, init_db
from freqtrade.persistence.pairlock import PairLock
config = setup_utils_configuration(args, RunMode.UTIL_NO_EXCHANGE) config = setup_utils_configuration(args, RunMode.UTIL_NO_EXCHANGE)
pass
init_db(config['db_url'], False)
session_target = Trade._session
init_db(config['db_url_from'], False)
# print(f"{id(sessionA)=}, {id(sessionB)=}")
trade_count = 0
pairlock_count = 0
for trade in Trade.get_trades():
trade_count += 1
make_transient(trade)
for o in trade.orders:
make_transient(o)
session_target.add(trade)
session_target.commit()
for pairlock in PairLock.query:
pairlock_count += 1
make_transient(pairlock)
session_target.add(pairlock)
session_target.commit()
logger.info(f"Migrated {trade_count} Trades, and {pairlock_count} Pairlocks.")

View File

@ -147,6 +147,10 @@ class Configuration:
config.update({'db_url': self.args['db_url']}) config.update({'db_url': self.args['db_url']})
logger.info('Parameter --db-url detected ...') logger.info('Parameter --db-url detected ...')
self._args_to_config(config, argname='db_url_from',
logstring='Parameter --db-url-from detected ...')
if config.get('force_entry_enable', False): if config.get('force_entry_enable', False):
logger.warning('`force_entry_enable` RPC message enabled.') logger.warning('`force_entry_enable` RPC message enabled.')