-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
rename problem table to leaderboard (#64)
* rename problem table to leaderboard * changes to make ruff happy
- Loading branch information
Showing
2 changed files
with
58 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
src/discord-cluster-manager/migrations/20241221_01_54Oeg-rename-problem-table.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
""" | ||
This migration renames the table leaderboard.problem to leaderboard.leaderboard, | ||
and renames associated foreign keys, indexes, and constraints. | ||
""" | ||
|
||
from yoyo import step | ||
|
||
__depends__ = {'20241214_01_M62BX-drop-old-leaderboard-tables'} | ||
|
||
steps = [ | ||
# Rename leaderboard.problem to leaderboard.leaderboard: | ||
step("ALTER TABLE leaderboard.problem RENAME TO leaderboard"), | ||
step(""" | ||
ALTER SEQUENCE leaderboard.problem_id_seq | ||
RENAME TO leaderboard_id_seq | ||
"""), | ||
step("ALTER INDEX leaderboard.problem_pkey RENAME TO leaderboard_pkey"), | ||
step(""" | ||
ALTER TABLE leaderboard.leaderboard | ||
RENAME CONSTRAINT problem_name_key | ||
TO leaderboard_name_key | ||
"""), | ||
|
||
# Rename a column in leaderboard.submission: | ||
step(""" | ||
ALTER TABLE leaderboard.submission | ||
RENAME COLUMN problem_id | ||
TO leaderboard_id | ||
"""), | ||
step(""" | ||
ALTER TABLE leaderboard.submission | ||
RENAME CONSTRAINT submission_problem_id_fkey | ||
TO submission_leaderboard_id_fkey | ||
"""), | ||
|
||
# We need to update the name for the index | ||
# leaderboard.submission_problem_id_idx. We can't just rename the index, | ||
# because the index definition refers to the old column name, problem_id. | ||
# This might be confusing, so we drop and re-create the index: | ||
step("DROP INDEX leaderboard.submission_problem_id_idx"), | ||
step(""" | ||
CREATE INDEX submission_leaderboard_id_idx | ||
ON leaderboard.submission (leaderboard_id) | ||
""") | ||
] |