diff --git a/engineapi/alembic/versions/cc80e886e153_added_leaderboard_versions_table_and_.py b/engineapi/alembic/versions/cc80e886e153_added_leaderboard_versions_table_and_.py index bdc773f6f..515d638c7 100644 --- a/engineapi/alembic/versions/cc80e886e153_added_leaderboard_versions_table_and_.py +++ b/engineapi/alembic/versions/cc80e886e153_added_leaderboard_versions_table_and_.py @@ -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", @@ -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" diff --git a/engineapi/engineapi/models.py b/engineapi/engineapi/models.py index c60ee0de1..c516cde29 100644 --- a/engineapi/engineapi/models.py +++ b/engineapi/engineapi/models.py @@ -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"], [