Skip to content

Commit

Permalink
go back to asyncpg
Browse files Browse the repository at this point in the history
  • Loading branch information
pawelros authored and MattBlack85 committed May 15, 2024
1 parent 9841b68 commit 369297b
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 5 deletions.
1 change: 1 addition & 0 deletions Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ pyyaml = "*"
isort = "*"
psycopg2 = "*"
boto3 = "*"
asyncpg = "*"

[dev-packages]

Expand Down
50 changes: 49 additions & 1 deletion Pipfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 8 additions & 4 deletions pg-migration-tool/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
import threading

import boto3
import psycopg2
import asyncpg
import yaml
from psycopg2 import DatabaseError
from asyncpg.exceptions._base import PostgresError
from textual import on
from textual.app import App, ComposeResult
from textual.containers import Horizontal
Expand Down Expand Up @@ -88,17 +88,21 @@ async def check_connection_for_db(self, db, label) -> bool:
self.query_one(label).update(f"{label} Running connection test...")

try:
await asyncio.to_thread(psycopg2.connect,
await asyncpg.connect(
timeout=5,
database=db["db_database_name"],
user=db["db_username"],
password=db_password,
host=db["db_connection_host"],
)
self.query_one(label).update(f"{label} {db["db_connection_host"]} connection successful.")
return True
except DatabaseError as e:
except PostgresError as e:
self.query_one(label).update(f"{label} {db["db_connection_host"]} connection failed: {e}")
return False
except TimeoutError as e:
self.query_one(label).update(f"{label} {db["db_connection_host"]} connection timed out.")
return False

async def decrypt_password(self, db, label) -> str:
self.query_one(label).update(f"{label} Decrypting db password...")
Expand Down

0 comments on commit 369297b

Please sign in to comment.