#!/usr/bin/env python
"""Drop all mem0-related tables"""

import psycopg2
from utils.settings import CHECKPOINT_DB_URL

conn = psycopg2.connect(CHECKPOINT_DB_URL)
cursor = conn.cursor()

# Find all tables starting with mem0
cursor.execute("""
    SELECT tablename FROM pg_tables
    WHERE schemaname = 'public' AND tablename LIKE 'mem0_%'
""")

tables = cursor.fetchall()
print('Found tables:', tables)

# Drop each table
for (table,) in tables:
    cursor.execute(f'DROP TABLE IF EXISTS {table} CASCADE')
    print(f'Dropped: {table}')

conn.commit()
cursor.close()
conn.close()
print('Drop completed')
