Spaces:
Sleeping
Sleeping
| #!/usr/bin/env python3 | |
| """ | |
| Verification script to ensure Supabase is configured and will be used for all future data. | |
| Run this after migration to confirm everything is set up correctly. | |
| """ | |
| import os | |
| import sys | |
| from pathlib import Path | |
| from dotenv import load_dotenv | |
| # Add backend to path | |
| backend_dir = Path(__file__).resolve().parent | |
| sys.path.insert(0, str(backend_dir)) | |
| load_dotenv() | |
| from backend.api.storage.rules_store import RulesStore | |
| from backend.api.storage.analytics_store import AnalyticsStore | |
| def main(): | |
| print("=" * 70) | |
| print("Supabase Configuration Verification") | |
| print("=" * 70) | |
| print() | |
| # Check environment variables | |
| print("1. Checking Environment Variables:") | |
| postgres_url = os.getenv("POSTGRESQL_URL") | |
| supabase_url = os.getenv("SUPABASE_URL") | |
| supabase_key = os.getenv("SUPABASE_SERVICE_KEY") | |
| has_postgres = bool(postgres_url) | |
| has_supabase_api = bool(supabase_url and supabase_key) | |
| if has_postgres: | |
| masked = postgres_url[:30] + "..." + postgres_url[-20:] if len(postgres_url) > 50 else postgres_url | |
| print(f" β POSTGRESQL_URL is set: {masked}") | |
| else: | |
| print(" β POSTGRESQL_URL is not set") | |
| if supabase_url: | |
| print(f" β SUPABASE_URL is set: {supabase_url[:50]}...") | |
| else: | |
| print(" β SUPABASE_URL is not set") | |
| if supabase_key: | |
| if len(supabase_key) > 100: | |
| print(f" β SUPABASE_SERVICE_KEY is set: {supabase_key[:20]}... ({len(supabase_key)} chars)") | |
| else: | |
| print(f" β οΈ SUPABASE_SERVICE_KEY seems incomplete ({len(supabase_key)} chars, expected 200+)") | |
| else: | |
| print(" β SUPABASE_SERVICE_KEY is not set") | |
| print() | |
| # Check RulesStore | |
| print("2. Checking RulesStore Configuration:") | |
| try: | |
| rules_store = RulesStore() | |
| if rules_store.use_supabase: | |
| print(" β RulesStore is using Supabase") | |
| print(f" π¦ Backend: Supabase (REST API)") | |
| else: | |
| print(" β RulesStore is using SQLite (not Supabase)") | |
| print(" β οΈ Future rules will be saved to SQLite, not Supabase!") | |
| print() | |
| print(" To fix:") | |
| print(" - Set SUPABASE_URL and SUPABASE_SERVICE_KEY in .env") | |
| except Exception as e: | |
| print(f" β Error initializing RulesStore: {e}") | |
| print() | |
| # Check AnalyticsStore | |
| print("3. Checking AnalyticsStore Configuration:") | |
| try: | |
| analytics_store = AnalyticsStore() | |
| if analytics_store.use_supabase: | |
| print(" β AnalyticsStore is using Supabase") | |
| print(f" π¦ Backend: Supabase (REST API)") | |
| else: | |
| print(" β AnalyticsStore is using SQLite (not Supabase)") | |
| print(" β οΈ Future analytics will be saved to SQLite, not Supabase!") | |
| print() | |
| print(" To fix:") | |
| if has_postgres: | |
| print(" - POSTGRESQL_URL is set, but AnalyticsStore needs SUPABASE_URL + SUPABASE_SERVICE_KEY") | |
| else: | |
| print(" - Set SUPABASE_URL and SUPABASE_SERVICE_KEY in .env") | |
| except Exception as e: | |
| print(f" β Error initializing AnalyticsStore: {e}") | |
| print() | |
| # Summary | |
| print("4. Summary:") | |
| rules_ok = rules_store.use_supabase if 'rules_store' in locals() else False | |
| analytics_ok = analytics_store.use_supabase if 'analytics_store' in locals() else False | |
| if rules_ok and analytics_ok: | |
| print(" β All systems configured to use Supabase!") | |
| print(" β Future data will be saved to Supabase") | |
| print() | |
| print(" π‘ Next steps:") | |
| print(" 1. Restart your FastAPI/MCP services to apply changes") | |
| print(" 2. Test by adding a rule or generating analytics") | |
| print(" 3. Verify data appears in Supabase Dashboard β Table Editor") | |
| elif rules_ok or analytics_ok: | |
| print(" β οΈ Partial configuration:") | |
| if rules_ok: | |
| print(" β Rules will use Supabase") | |
| else: | |
| print(" β Rules will use SQLite") | |
| if analytics_ok: | |
| print(" β Analytics will use Supabase") | |
| else: | |
| print(" β Analytics will use SQLite") | |
| print() | |
| print(" To fully migrate to Supabase:") | |
| print(" - Ensure SUPABASE_URL and SUPABASE_SERVICE_KEY are set in .env") | |
| print(" - Restart your services") | |
| else: | |
| print(" β Not configured for Supabase") | |
| print(" β οΈ All data will be saved to SQLite") | |
| print() | |
| print(" To migrate to Supabase:") | |
| print(" 1. Set SUPABASE_URL and SUPABASE_SERVICE_KEY in .env") | |
| print(" 2. Restart your services") | |
| print(" 3. Run this verification again") | |
| print() | |
| print("=" * 70) | |
| if __name__ == "__main__": | |
| main() | |