""" Fix Supabase Tables for GAIA Memory This module applies monkey patches to memory classes to ensure they use the correct tables. It also ensures that all required tables exist in Supabase. NOTICE: This is a proxy file that re-exports from the consolidated implementation. Please use imports from 'memory' module directly in new code instead of importing from this file. Usage: from memory.fix_supabase_tables import apply_monkey_patch, ensure_tables_exist """ import logging from memory.supabase_memory_consolidated import ( SupabaseMemory, ConversationMemory, ResultCache, WorkingMemory, verify_tables_exist ) from agent.config import get_memory_config logging.basicConfig( level=logging.INFO, format="%(asctime)s - %(name)s - %(levelname)s - %(message)s" ) logger = logging.getLogger("fix_supabase_tables") def apply_monkey_patch() -> bool: """ Apply monkey patches to memory classes to ensure they use the correct tables. This is now handled by the consolidated implementation. Returns: bool: True if the patches were applied successfully, False otherwise """ logger.info("Using consolidated implementation with proper table handling...") # The consolidated implementation already ensures correct table usage, # so we just need to return True here for backward compatibility return True def ensure_tables_exist() -> bool: """ Ensure all required tables exist in Supabase. Returns: bool: True if all tables exist, False otherwise """ logger.info("Ensuring all required tables exist using consolidated implementation...") try: memory_config = get_memory_config() memory_config["enabled"] = True memory = SupabaseMemory(config=memory_config) return verify_tables_exist(memory) except Exception as e: logger.error(f"Error ensuring tables exist: {str(e)}") return False def test_tables() -> bool: """ Test all memory tables by exercising their APIs. Returns: bool: True if all tests pass, False otherwise """ logger.info("Testing memory tables...") try: memory_config = get_memory_config() memory_config["enabled"] = True memory = SupabaseMemory(config=memory_config) # Test conversation memory conversation = ConversationMemory(memory, "test-conversation") conversation.add_message("user", "test message") messages = conversation.get_messages() if not messages or messages[0].get("content") != "test message": logger.error(f"Conversation memory test failed") return False conversation.clear() logger.info("✅ Conversation memory test passed") # Test result cache cache = ResultCache(memory) cache.cache_result("test_query", "test_answer") result = cache.get_result("test_query") if result != "test_answer": logger.error(f"Result cache test failed") return False cache.clear() logger.info("✅ Result cache test passed") # Test working memory working = WorkingMemory(memory, "test-session") working.store_intermediate_result("test_key", "test_value") result = working.get_intermediate_result("test_key") if result != "test_value": logger.error(f"Working memory test failed") return False working.clear() logger.info("✅ Working memory test passed") logger.info("✅ All memory table tests passed") return True except Exception as e: logger.error(f"Error testing memory tables: {str(e)}") return False if __name__ == "__main__": if apply_monkey_patch() and ensure_tables_exist(): if test_tables(): logger.info("All memory tables fixed and tested successfully") import sys sys.exit(0) else: logger.error("Memory table tests failed") import sys sys.exit(1) else: logger.error("Failed to fix memory tables") import sys sys.exit(1)