mirror of
https://github.com/laoxong/nofx.git
synced 2026-06-04 09:58:22 +08:00
fix: use local sqlite3 to clear trading data before starting services
This commit is contained in:
+17
-11
@@ -167,25 +167,31 @@ start_services() {
|
|||||||
echo -e "${GREEN}✓ Services started${NC}"
|
echo -e "${GREEN}✓ Services started${NC}"
|
||||||
}
|
}
|
||||||
|
|
||||||
# Clear trading data via container (called after services are ready)
|
# Clear trading data (called before services start)
|
||||||
clear_trading_data() {
|
clear_trading_data() {
|
||||||
if [ "$CLEAR_TRADING_DATA" != "yes" ]; then
|
if [ "$CLEAR_TRADING_DATA" != "yes" ]; then
|
||||||
return 0
|
return 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo -e "${YELLOW}Clearing trading data tables via container...${NC}"
|
local db_file="data/data.db"
|
||||||
|
|
||||||
# Wait a moment for database to be ready
|
if [ ! -f "$db_file" ]; then
|
||||||
sleep 2
|
echo -e "${YELLOW}Database file not found, skipping...${NC}"
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
|
||||||
# Execute SQL to clear tables via docker exec
|
echo -e "${YELLOW}Clearing trading data tables...${NC}"
|
||||||
$COMPOSE_CMD exec -T backend sh -c "sqlite3 /app/data/data.db 'DELETE FROM trader_fills; DELETE FROM trader_orders; DELETE FROM trader_positions;'" 2>/dev/null
|
|
||||||
|
|
||||||
if [ $? -eq 0 ]; then
|
if command -v sqlite3 &> /dev/null; then
|
||||||
echo -e "${GREEN}✓ Trading data tables cleared${NC}"
|
sqlite3 "$db_file" 'DELETE FROM trader_fills; DELETE FROM trader_orders; DELETE FROM trader_positions;'
|
||||||
|
if [ $? -eq 0 ]; then
|
||||||
|
echo -e "${GREEN}✓ Trading data tables cleared${NC}"
|
||||||
|
else
|
||||||
|
echo -e "${RED}Failed to clear trading data${NC}"
|
||||||
|
fi
|
||||||
else
|
else
|
||||||
echo -e "${RED}Failed to clear trading data. You can manually run:${NC}"
|
echo -e "${RED}sqlite3 not found. Please install sqlite3 and run manually:${NC}"
|
||||||
echo -e "${BLUE} $COMPOSE_CMD exec backend sqlite3 /app/data/data.db 'DELETE FROM trader_fills; DELETE FROM trader_orders; DELETE FROM trader_positions;'${NC}"
|
echo -e "${BLUE} sqlite3 data/data.db 'DELETE FROM trader_fills; DELETE FROM trader_orders; DELETE FROM trader_positions;'${NC}"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -279,9 +285,9 @@ main() {
|
|||||||
generate_env
|
generate_env
|
||||||
pull_images
|
pull_images
|
||||||
ask_clear_trading_data
|
ask_clear_trading_data
|
||||||
|
clear_trading_data
|
||||||
start_services
|
start_services
|
||||||
wait_for_services
|
wait_for_services
|
||||||
clear_trading_data
|
|
||||||
print_success
|
print_success
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user