Skip to content

Commit

Permalink
drop old leaderboard tables
Browse files Browse the repository at this point in the history
  • Loading branch information
b9r5 committed Dec 15, 2024
1 parent 8e59226 commit af0e820
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 42 deletions.
42 changes: 0 additions & 42 deletions src/discord-cluster-manager/leaderboard_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ def connect(self) -> bool:
else psycopg2.connect(**self.connection_params)
)
self.cursor = self.connection.cursor()
self._create_tables()
return True
except Error as e:
print(f"Error connecting to PostgreSQL: {e}")
Expand All @@ -49,47 +48,6 @@ def disconnect(self):
if self.connection:
self.connection.close()

def _create_tables(self):
"""Create necessary tables if they don't exist"""
create_table_query = """
CREATE TABLE IF NOT EXISTS leaderboard (
id SERIAL PRIMARY KEY,
name TEXT UNIQUE NOT NULL,
deadline TIMESTAMP NOT NULL,
reference_code TEXT NOT NULL
);
"""

create_submission_table_query = """
CREATE TABLE IF NOT EXISTS submissions (
submission_id SERIAL PRIMARY KEY,
leaderboard_id TEXT NOT NULL,
submission_name VARCHAR(255) NOT NULL,
user_id TEXT NOT NULL,
code TEXT NOT NULL,
submission_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
submission_score DOUBLE PRECISION NOT NULL,
FOREIGN KEY (leaderboard_id) REFERENCES leaderboard(name)
);
"""

create_run_information_table_query = """
CREATE TABLE IF NOT EXISTS runinfo (
submission_id INTEGER NOT NULL,
stdout TEXT,
ncu_output TEXT,
FOREIGN KEY (submission_id) REFERENCES submissions(submission_id)
);
"""

try:
self.cursor.execute(create_table_query)
self.cursor.execute(create_submission_table_query)
self.cursor.execute(create_run_information_table_query)
self.connection.commit()
except Error as e:
print(f"Error creating table: {e}")

def __enter__(self):
"""Context manager entry"""
self.connect()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
"""
This migration drops tables in the public schema that we were previously
creating. The leaderboard tables are now in the leaderboard schema, so we dont'
need the tables in the public schema any more. I think the CASCADE clauses will
cause the sequences owned by the old tables to be dropped, but if not we'll need
another migration.
"""

from yoyo import step

__depends__ = {'20241208_01_p3yuR-initial-leaderboard-schema'}

steps = [
step("DROP TABLE IF EXISTS public.leaderboard CASCADE"),
step("DROP TABLE IF EXISTS public.submissions CASCADE"),
step("DROP TABLE IF EXISTS public.runinfo CASCADE")
]

0 comments on commit af0e820

Please sign in to comment.