Skip to content

Commit

Permalink
allow duplicate ranking
Browse files Browse the repository at this point in the history
  • Loading branch information
ipdae committed Sep 26, 2024
1 parent a2cf27d commit e83f520
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 2 deletions.
16 changes: 16 additions & 0 deletions tests/models_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,19 @@ def test_as_schema(fx_session):
ranking=2,
rewards=[reward_amount.as_schema()],
)


def test_duplicate_ranking(fx_session):
for i in range(2):
reward = WorldBossReward()
avatar_address = f"avatar_address_{i}"
agent_address = f"agent_address_{i}"
reward.avatar_address = avatar_address
reward.agent_address = agent_address
reward.raid_id = 1
reward.ranking = 1
fx_session.add(reward)
fx_session.commit()
assert (
fx_session.query(WorldBossReward).filter_by(ranking=1, raid_id=1).count() == 2
)
3 changes: 1 addition & 2 deletions world_boss/app/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,7 @@ class WorldBossReward(Base):
amounts = relationship("WorldBossRewardAmount", back_populates="reward")

__table_args__ = (
UniqueConstraint(raid_id, avatar_address, agent_address),
UniqueConstraint(raid_id, ranking),
UniqueConstraint(raid_id, avatar_address, agent_address, ranking),
)

def as_dict(self) -> dict:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
"""allow duplicate ranking
Revision ID: 9ebe656fc708
Revises: 4321181b2dfb
Create Date: 2024-09-26 11:28:43.980961
"""
from alembic import op

# revision identifiers, used by Alembic.
revision = "9ebe656fc708"
down_revision = "4321181b2dfb"
branch_labels = None
depends_on = None


def upgrade():
op.drop_constraint(
"world_boss_reward_raid_id_avatar_address_agent_address_key",
"world_boss_reward",
)
op.drop_constraint("world_boss_reward_raid_id_ranking_key", "world_boss_reward")
op.create_unique_constraint(
"world_boss_reward_raid_id_avatar_address_agent_address_ranking_key",
"world_boss_reward",
["raid_id", "avatar_address", "agent_address", "ranking"],
)


def downgrade():
op.drop_constraint(
"world_boss_reward_raid_id_avatar_address_agent_address_ranking_key",
"world_boss_reward",
)
op.create_unique_constraint(
"world_boss_reward_raid_id_avatar_address_agent_address_key",
"world_boss_reward",
["raid_id", "avatar_address", "agent_address"],
)
op.create_unique_constraint(
"world_boss_reward_raid_id_ranking_key",
"world_boss_reward",
["raid_id", "ranking"],
)

0 comments on commit e83f520

Please sign in to comment.