- Delete obsolete files: data_fetcher_old.py, market_old.py, base_strategy.py (root), strategy_sma_cross.py, and old architecture remnants (address_monitor.py, position_monitor.py, trade_log.py, wallet_data.py, whale_tracker.py) - Delete zero-byte Docker artifacts and runtime files (clp_hedger.log, clp_hedger/hedge_status.json) - Move one-off utility scripts to scripts/ directory - Move example/template files to .temp/ directory - Update .gitignore: add entries for clp_hedger.log, clp_hedger/hedge_status.json, Docker layer hash files, Using, Running, and backups/ - Update .dockerignore: add clp_hedger.log, clp_hedger/hedge_status.json, backups/ - Create example config files: _data/strategies.json.example, _data/backtesting_conf.json.example, _data/coin_precision.json.example - Update GEMINI.md: remove outdated session summaries and duplicate review section - Update review.md: add cleanup status section, update remaining recommendations - Update MIGRATION_PLAN.md: mark completed phases, update file references - Update DOCKER_MIGRATION_GUIDE.md: update import_csv.py path reference
57 lines
1.9 KiB
Python
57 lines
1.9 KiB
Python
import sqlite3
|
|
import logging
|
|
import os
|
|
|
|
from logging_utils import setup_logging
|
|
|
|
def cleanup_market_cap_tables():
|
|
"""
|
|
Scans the database and drops all tables related to market cap data
|
|
to allow for a clean refresh.
|
|
"""
|
|
setup_logging('normal', 'DBCleanup')
|
|
db_path = os.path.join("_data", "market_data.db")
|
|
|
|
if not os.path.exists(db_path):
|
|
logging.error(f"Database file not found at '{db_path}'. Nothing to clean.")
|
|
return
|
|
|
|
logging.info(f"Connecting to database at '{db_path}'...")
|
|
try:
|
|
with sqlite3.connect(db_path) as conn:
|
|
cursor = conn.cursor()
|
|
|
|
# Find all tables that were created by the market cap fetcher
|
|
cursor.execute("""
|
|
SELECT name FROM sqlite_master
|
|
WHERE type='table'
|
|
AND (name LIKE '%_market_cap' OR name LIKE 'TOTAL_%')
|
|
""")
|
|
|
|
tables_to_drop = cursor.fetchall()
|
|
|
|
if not tables_to_drop:
|
|
logging.info("No market cap tables found to clean up. Database is already clean.")
|
|
return
|
|
|
|
logging.warning(f"Found {len(tables_to_drop)} market cap tables to remove...")
|
|
|
|
for table in tables_to_drop:
|
|
table_name = table[0]
|
|
try:
|
|
logging.info(f"Dropping table: {table_name}...")
|
|
conn.execute(f'DROP TABLE IF EXISTS "{table_name}"')
|
|
except Exception as e:
|
|
logging.error(f"Failed to drop table {table_name}: {e}")
|
|
|
|
conn.commit()
|
|
logging.info("--- Database cleanup complete ---")
|
|
|
|
except sqlite3.Error as e:
|
|
logging.error(f"A database error occurred: {e}")
|
|
except Exception as e:
|
|
logging.error(f"An unexpected error occurred: {e}")
|
|
|
|
if __name__ == "__main__":
|
|
cleanup_market_cap_tables()
|