1
0
mirror of https://gitlab.com/MoonTestUse1/AdministrationItDepartmens.git synced 2025-08-14 00:25:46 +02:00
Files
MoonTestUse1 bdf4ae9d70 Fix database
2025-01-07 05:26:33 +06:00

30 lines
1.1 KiB
Python

"""Database connection check script"""
import sys
from sqlalchemy import create_engine, text
from sqlalchemy.exc import SQLAlchemyError
def check_database_connection(database_url: str) -> bool:
"""Check database connection"""
try:
engine = create_engine(database_url)
with engine.connect() as connection:
result = connection.execute(text("SELECT 1"))
print(f"Successfully connected to {database_url}")
return True
except SQLAlchemyError as error:
print(f"Error connecting to {database_url}: {error}")
return False
if __name__ == "__main__":
# URL для основной базы данных
main_db_url = "postgresql://postgres:postgres@localhost:5432/app"
# URL для тестовой базы данных
test_db_url = "postgresql://postgres:postgres@localhost:5432/test_app"
main_ok = check_database_connection(main_db_url)
test_ok = check_database_connection(test_db_url)
if not (main_ok and test_ok):
sys.exit(1)
print("All database connections are successful!")