#!/usr/bin/env python
"""删除所有 mem0 相关的表"""

import psycopg2
from utils.settings import CHECKPOINT_DB_URL

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

# 查找所有 mem0 开头的表
cursor.execute("""
    SELECT tablename FROM pg_tables
    WHERE schemaname = 'public' AND tablename LIKE 'mem0_%'
""")

tables = cursor.fetchall()
print('找到的表:', tables)

# 删除每个表
for (table,) in tables:
    cursor.execute(f'DROP TABLE IF EXISTS {table} CASCADE')
    print(f'已删除: {table}')

conn.commit()
cursor.close()
conn.close()
print('删除完成')
