MCPcopy Create free account
hub / github.com/TextGeneratorio/text-generator.io / test_connections

Function test_connections

migrate_to_postgres.py:33–71  ·  view source on GitHub ↗

Test both database connections

(logger)

Source from the content-addressed store, hash-verified

31
32
33def test_connections(logger):
34 """Test both database connections"""
35 logger.info("Testing database connections...")
36
37 # Test PostgreSQL connection
38 try:
39 from sqlalchemy import text
40
41 from questions.db_models_postgres import SessionLocal, create_tables
42
43 db = SessionLocal()
44 db.execute(text("SELECT 1"))
45 db.close()
46 logger.info("✅ PostgreSQL connection successful")
47
48 # Ensure tables exist
49 create_tables()
50 logger.info("✅ PostgreSQL tables created/verified")
51
52 except Exception as e:
53 logger.error(f"❌ PostgreSQL connection failed: {e}")
54 return False
55
56 # Test Google Cloud NDB connection
57 try:
58 from questions.db_models import Document as NDBDocument
59 from questions.db_models import client
60
61 with client.context():
62 # Try to query one document to test connection
63 NDBDocument.query().fetch(1)
64 logger.info("✅ Google Cloud NDB connection successful")
65
66 except Exception as e:
67 logger.error(f"❌ Google Cloud NDB connection failed: {e}")
68 logger.error("Make sure GOOGLE_APPLICATION_CREDENTIALS is set correctly")
69 return False
70
71 return True
72
73
74def migrate_documents(logger) -> int:

Callers 1

mainFunction · 0.70

Calls 2

create_tablesFunction · 0.90
closeMethod · 0.45

Tested by

no test coverage detected