135 lines
3.6 KiB
Python
Executable File
135 lines
3.6 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
"""
|
|
Cleanup All Contacts
|
|
|
|
This script removes all contacts and related data from the database.
|
|
Use with caution as this will delete all data in the database.
|
|
|
|
Usage:
|
|
python cleanup_all_contacts.py
|
|
"""
|
|
|
|
import os
|
|
import sys
|
|
import argparse
|
|
from dotenv import load_dotenv
|
|
|
|
# Add parent directory to path to import utils
|
|
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
|
from utils.db_connector import DatabaseConnector
|
|
from utils.logger import setup_logger
|
|
|
|
# Load environment variables
|
|
load_dotenv()
|
|
|
|
# Setup logging
|
|
logger = setup_logger("cleanup_all_contacts")
|
|
|
|
def cleanup_all_data():
|
|
"""
|
|
Remove all contacts and related data from the database.
|
|
"""
|
|
logger.info("Cleaning up all contacts and related data")
|
|
|
|
db = DatabaseConnector()
|
|
|
|
# Delete all NFT holdings
|
|
query = """
|
|
DELETE FROM "NftHolding"
|
|
RETURNING id
|
|
"""
|
|
result = db.execute_query(query)
|
|
deleted_nft_holdings = len(result)
|
|
logger.info(f"Deleted {deleted_nft_holdings} NFT holdings")
|
|
|
|
# Delete all token holdings
|
|
query = """
|
|
DELETE FROM "TokenHolding"
|
|
RETURNING id
|
|
"""
|
|
result = db.execute_query(query)
|
|
deleted_token_holdings = len(result)
|
|
logger.info(f"Deleted {deleted_token_holdings} token holdings")
|
|
|
|
# Delete all DAO memberships
|
|
query = """
|
|
DELETE FROM "DaoMembership"
|
|
RETURNING id
|
|
"""
|
|
result = db.execute_query(query)
|
|
deleted_dao_memberships = len(result)
|
|
logger.info(f"Deleted {deleted_dao_memberships} DAO memberships")
|
|
|
|
# Delete all notes
|
|
query = """
|
|
DELETE FROM "Note"
|
|
RETURNING id
|
|
"""
|
|
result = db.execute_query(query)
|
|
deleted_notes = len(result)
|
|
logger.info(f"Deleted {deleted_notes} notes")
|
|
|
|
# Delete all tags on contacts
|
|
query = """
|
|
DELETE FROM "TagsOnContacts"
|
|
RETURNING "contactId"
|
|
"""
|
|
result = db.execute_query(query)
|
|
deleted_tags_on_contacts = len(result)
|
|
logger.info(f"Deleted {deleted_tags_on_contacts} tags on contacts")
|
|
|
|
# Delete all tags
|
|
query = """
|
|
DELETE FROM "Tag"
|
|
RETURNING id
|
|
"""
|
|
result = db.execute_query(query)
|
|
deleted_tags = len(result)
|
|
logger.info(f"Deleted {deleted_tags} tags")
|
|
|
|
# Delete all scraping jobs
|
|
query = """
|
|
DELETE FROM "ScrapingJob"
|
|
RETURNING id
|
|
"""
|
|
result = db.execute_query(query)
|
|
deleted_scraping_jobs = len(result)
|
|
logger.info(f"Deleted {deleted_scraping_jobs} scraping jobs")
|
|
|
|
# Delete all data sources
|
|
query = """
|
|
DELETE FROM "DataSource"
|
|
RETURNING id
|
|
"""
|
|
result = db.execute_query(query)
|
|
deleted_data_sources = len(result)
|
|
logger.info(f"Deleted {deleted_data_sources} data sources")
|
|
|
|
# Delete all contacts
|
|
query = """
|
|
DELETE FROM "Contact"
|
|
RETURNING id
|
|
"""
|
|
result = db.execute_query(query)
|
|
deleted_contacts = len(result)
|
|
logger.info(f"Deleted {deleted_contacts} contacts")
|
|
|
|
logger.info("Cleanup completed successfully")
|
|
|
|
def main():
|
|
"""Main entry point for the script."""
|
|
parser = argparse.ArgumentParser(description="Clean up all contacts and related data")
|
|
parser.add_argument("--confirm", action="store_true",
|
|
help="Confirm that you want to delete all data")
|
|
|
|
args = parser.parse_args()
|
|
|
|
if not args.confirm:
|
|
logger.warning("This script will delete ALL contacts and related data from the database.")
|
|
logger.warning("Run with --confirm to proceed with deletion.")
|
|
return
|
|
|
|
cleanup_all_data()
|
|
|
|
if __name__ == "__main__":
|
|
main() |