18 lines
641 B
Python
18 lines
641 B
Python
import os
|
|
import asyncio
|
|
import asyncpg
|
|
|
|
def get_database_url():
|
|
# Replace 'postgresql+asyncpg' with 'postgresql' for asyncpg compatibility
|
|
return os.getenv("DATABASE_URL", "postgresql://servicemanager:servicemanager123@servicemanager-db:5432/servicemanager").replace("postgresql+asyncpg", "postgresql")
|
|
|
|
async def test_connection():
|
|
try:
|
|
conn = await asyncpg.connect(get_database_url())
|
|
print("Connection to the database was successful!")
|
|
await conn.close()
|
|
except Exception as e:
|
|
print(f"Failed to connect to the database: {e}")
|
|
|
|
if __name__ == "__main__":
|
|
asyncio.run(test_connection()) |