Skip to content

Commit b2cfa1a

Browse files
authored
drop old leaderboard tables (#53)
1 parent 8e59226 commit b2cfa1a

File tree

2 files changed

+17
-42
lines changed

2 files changed

+17
-42
lines changed

src/discord-cluster-manager/leaderboard_db.py

Lines changed: 0 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ def connect(self) -> bool:
3636
else psycopg2.connect(**self.connection_params)
3737
)
3838
self.cursor = self.connection.cursor()
39-
self._create_tables()
4039
return True
4140
except Error as e:
4241
print(f"Error connecting to PostgreSQL: {e}")
@@ -49,47 +48,6 @@ def disconnect(self):
4948
if self.connection:
5049
self.connection.close()
5150

52-
def _create_tables(self):
53-
"""Create necessary tables if they don't exist"""
54-
create_table_query = """
55-
CREATE TABLE IF NOT EXISTS leaderboard (
56-
id SERIAL PRIMARY KEY,
57-
name TEXT UNIQUE NOT NULL,
58-
deadline TIMESTAMP NOT NULL,
59-
reference_code TEXT NOT NULL
60-
);
61-
"""
62-
63-
create_submission_table_query = """
64-
CREATE TABLE IF NOT EXISTS submissions (
65-
submission_id SERIAL PRIMARY KEY,
66-
leaderboard_id TEXT NOT NULL,
67-
submission_name VARCHAR(255) NOT NULL,
68-
user_id TEXT NOT NULL,
69-
code TEXT NOT NULL,
70-
submission_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
71-
submission_score DOUBLE PRECISION NOT NULL,
72-
FOREIGN KEY (leaderboard_id) REFERENCES leaderboard(name)
73-
);
74-
"""
75-
76-
create_run_information_table_query = """
77-
CREATE TABLE IF NOT EXISTS runinfo (
78-
submission_id INTEGER NOT NULL,
79-
stdout TEXT,
80-
ncu_output TEXT,
81-
FOREIGN KEY (submission_id) REFERENCES submissions(submission_id)
82-
);
83-
"""
84-
85-
try:
86-
self.cursor.execute(create_table_query)
87-
self.cursor.execute(create_submission_table_query)
88-
self.cursor.execute(create_run_information_table_query)
89-
self.connection.commit()
90-
except Error as e:
91-
print(f"Error creating table: {e}")
92-
9351
def __enter__(self):
9452
"""Context manager entry"""
9553
self.connect()
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
"""
2+
This migration drops tables in the public schema that we were previously
3+
creating. The leaderboard tables are now in the leaderboard schema, so we dont'
4+
need the tables in the public schema any more. I think the CASCADE clauses will
5+
cause the sequences owned by the old tables to be dropped, but if not we'll need
6+
another migration.
7+
"""
8+
9+
from yoyo import step
10+
11+
__depends__ = {'20241208_01_p3yuR-initial-leaderboard-schema'}
12+
13+
steps = [
14+
step("DROP TABLE IF EXISTS public.leaderboard CASCADE"),
15+
step("DROP TABLE IF EXISTS public.submissions CASCADE"),
16+
step("DROP TABLE IF EXISTS public.runinfo CASCADE")
17+
]

0 commit comments

Comments
 (0)