Skip to content

Commit

Permalink
remove unused DB environment variables
Browse files Browse the repository at this point in the history
  • Loading branch information
b9r5 committed Dec 22, 2024
1 parent 68e3ba6 commit 16c4527
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 61 deletions.
13 changes: 1 addition & 12 deletions src/discord-cluster-manager/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,6 @@
DISCORD_DEBUG_CLUSTER_STAGING_ID,
DISCORD_DEBUG_TOKEN,
DISCORD_TOKEN,
POSTGRES_DATABASE,
POSTGRES_HOST,
POSTGRES_PASSWORD,
POSTGRES_PORT,
POSTGRES_USER,
init_environment,
)
from discord import app_commands
Expand Down Expand Up @@ -46,13 +41,7 @@ def __init__(self, debug_mode=False):
)
self.tree.add_command(self.leaderboard_group)

self.leaderboard_db = LeaderboardDB(
POSTGRES_HOST,
POSTGRES_DATABASE,
POSTGRES_USER,
POSTGRES_PASSWORD,
POSTGRES_PORT,
)
self.leaderboard_db = LeaderboardDB()

async def setup_hook(self):
logger.info(f"Syncing commands for staging guild {DISCORD_CLUSTER_STAGING_ID}")
Expand Down
5 changes: 0 additions & 5 deletions src/discord-cluster-manager/consts.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,4 @@ class ModalGPU(Enum):
GITHUB_REPO = os.getenv("GITHUB_REPO")

# PostgreSQL-specific constants
POSTGRES_HOST = os.getenv("POSTGRES_HOST")
POSTGRES_DATABASE = os.getenv("POSTGRES_DATABASE")
POSTGRES_USER = os.getenv("POSTGRES_USER")
POSTGRES_PASSWORD = os.getenv("POSTGRES_PASSWORD")
POSTGRES_PORT = os.getenv("POSTGRES_PORT")
DATABASE_URL = os.getenv("DATABASE_URL")
50 changes: 6 additions & 44 deletions src/discord-cluster-manager/leaderboard_db.py
Original file line number Diff line number Diff line change
@@ -1,46 +1,22 @@
from typing import Optional

import psycopg2
from consts import (
DATABASE_URL,
POSTGRES_DATABASE,
POSTGRES_HOST,
POSTGRES_PASSWORD,
POSTGRES_PORT,
POSTGRES_USER,
)
from consts import DATABASE_URL
from psycopg2 import Error
from utils import LeaderboardItem, SubmissionItem


class LeaderboardDB:
def __init__(
self,
host: str,
database: str,
user: str,
password: str,
port: str = "5432"
):
"""Initialize database connection parameters"""
self.connection_params = {
"host": host,
"database": database,
"user": user,
"password": password,
"port": port,
}
def __init__(self):
self.connection: Optional[psycopg2.extensions.connection] = None
self.cursor: Optional[psycopg2.extensions.cursor] = None

def connect(self) -> bool:
"""Establish connection to the database"""
try:
self.connection = (
psycopg2.connect(DATABASE_URL, sslmode="require")
if DATABASE_URL
else psycopg2.connect(**self.connection_params)
)
if not DATABASE_URL:
raise ValueError("DATABASE_URL is not defined.")
self.connection = psycopg2.connect(DATABASE_URL, sslmode="require")
self.cursor = self.connection.cursor()
return True
except Error as e:
Expand Down Expand Up @@ -170,20 +146,6 @@ def get_leaderboard_submissions(


if __name__ == "__main__":
print(
POSTGRES_HOST,
POSTGRES_DATABASE,
POSTGRES_USER,
POSTGRES_PASSWORD,
POSTGRES_PORT,
)

leaderboard_db = LeaderboardDB(
POSTGRES_HOST,
POSTGRES_DATABASE,
POSTGRES_USER,
POSTGRES_PASSWORD,
POSTGRES_PORT,
)
leaderboard_db = LeaderboardDB()
leaderboard_db.connect()
leaderboard_db.disconnect()

0 comments on commit 16c4527

Please sign in to comment.