Skip to content

Commit

Permalink
Fix unique constrain on leaderboard scores to remove unique address a…
Browse files Browse the repository at this point in the history
…nd add unique version number.
  • Loading branch information
Andrey committed Nov 20, 2023
1 parent 5f90fc4 commit 0eb6c3e
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,14 @@ def upgrade():
"leaderboard_scores",
sa.Column("leaderboard_version_number", sa.DECIMAL(), nullable=True),
)
op.drop_constraint(
"uq_leaderboard_scores_leaderboard_id", "leaderboard_scores", type_="unique"
)
op.create_unique_constraint(
op.f("uq_leaderboard_scores_leaderboard_id"),
"leaderboard_scores",
["leaderboard_id", "address", "leaderboard_version_number"],
)
op.drop_constraint(
"fk_leaderboard_scores_leaderboard_id_leaderboards",
"leaderboard_scores",
Expand Down Expand Up @@ -111,6 +119,16 @@ def downgrade():
["id"],
ondelete="CASCADE",
)
op.drop_constraint(
op.f("uq_leaderboard_scores_leaderboard_id"),
"leaderboard_scores",
type_="unique",
)
op.create_unique_constraint(
"uq_leaderboard_scores_leaderboard_id",
"leaderboard_scores",
["leaderboard_id", "address"],
)
op.drop_column("leaderboard_scores", "leaderboard_version_number")
op.drop_index(
op.f("ix_leaderboard_versions_created_at"), table_name="leaderboard_versions"
Expand Down
2 changes: 1 addition & 1 deletion engineapi/engineapi/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@ class LeaderboardVersion(Base): # type: ignore
class LeaderboardScores(Base): # type: ignore
__tablename__ = "leaderboard_scores"
__table_args__ = (
UniqueConstraint("leaderboard_id", "address"),
UniqueConstraint("leaderboard_id", "address", "leaderboard_version_number"),
ForeignKeyConstraint(
["leaderboard_id", "leaderboard_version_number"],
[
Expand Down

0 comments on commit 0eb6c3e

Please sign in to comment.