#!/usr/bin/env python3 """ Debug mem0migrations table issue """ import psycopg2 import vecs def debug_mem0migrations(): """Debug the mem0migrations table issue""" print("=" * 60) print("MEM0MIGRATIONS TABLE DEBUG") print("=" * 60) try: # Connect to database directly conn = psycopg2.connect("postgresql://supabase_admin:CzkaYmRvc26Y@localhost:5435/postgres") cur = conn.cursor() print("๐Ÿ” Examining mem0migrations table...") # Check if table exists cur.execute(""" SELECT column_name, data_type, character_maximum_length, is_nullable FROM information_schema.columns WHERE table_schema = 'vecs' AND table_name = 'mem0migrations' ORDER BY ordinal_position; """) columns = cur.fetchall() if columns: print("โœ… mem0migrations table exists with columns:") for col in columns: print(f" - {col[0]}: {col[1]} (nullable: {col[3]})") # Check vector dimension cur.execute("SELECT dimension FROM vecs.mem0migrations LIMIT 1;") try: result = cur.fetchone() if result: print(f" ๐Ÿ“ Vector dimension appears to be configured for: {len(result[0]) if result[0] else 'unknown'}") else: print(" ๐Ÿ“ Table is empty") except Exception as e: print(f" โŒ Cannot determine dimension: {e}") # Get record count cur.execute("SELECT COUNT(*) FROM vecs.mem0migrations;") count = cur.fetchone()[0] print(f" ๐Ÿ“Š Record count: {count}") else: print("โŒ mem0migrations table does not exist in vecs schema") print("\n๐Ÿงน Attempting to clean up corrupted collections...") # Connect with vecs connection_string = "postgresql://supabase_admin:CzkaYmRvc26Y@localhost:5435/postgres" db = vecs.create_client(connection_string) # Try to delete the problematic collections problematic_collections = ["mem0migrations", "mem0_vectors", "mem0_working_test"] for collection_name in problematic_collections: try: print(f" ๐Ÿ—‘๏ธ Attempting to delete: {collection_name}") db.delete_collection(collection_name) print(f" โœ… Successfully deleted: {collection_name}") except Exception as e: print(f" โš ๏ธ Could not delete {collection_name}: {e}") # Verify cleanup print("\n๐Ÿ“‹ Collections after cleanup:") collections = db.list_collections() for col in collections: print(f" - {col.name} (dim: {col.dimension})") cur.close() conn.close() print("\n๐Ÿงช Testing fresh collection creation...") test_collection = db.get_or_create_collection(name="fresh_test", dimension=1536) print(f"โœ… Created fresh collection: {test_collection.name}") # Clean up test db.delete_collection("fresh_test") print("โœ… Cleaned up test collection") except Exception as e: print(f"โŒ Debug failed: {str(e)}") import traceback traceback.print_exc() if __name__ == "__main__": debug_mem0migrations()