I design a game achievement system for a MySQL database. Each achievement has 3 levels and each level contains a different reward. Achievements and their levels and rewards are the same for every user.
Table achievement
:
id_achievement | title | description | level_1 | level_2 | level_3 | reward_1 | reward_2 | reward_3 |
---|
The description column will be VARCHAR
and contain a description of how to achieve the achievement with a placeholder for the level value. Each level will be an INT
(value needed to complete that level).
Table user_achievement
:
id_user | id_achievement | progress | reward_collected | achievement_completed |
---|
My idea is to calculate the level for an achievement by comparing progress to achievement’s level.
Please point out weaknesses and recommend improvements (efficiency, storage, etc.). One issue is if user does not collect their reward for completing an achievement’s level before completing the next, previous reward will be overridden/skipped.
2
Answers
Your initial design is a good start. However, you need to focus on some areas to improve your design efficiency and also to address the issue you mentioned. Some suggestions are mentioned below,
Achievement:
id_achievement (PK), title, description
Level:
id_level (PK), id_achievement (FK), level_number, requirement
Reward:
id_reward (PK), id_achievement (FK), level_number, reward_details
user_achievement_progress:
id_user (FK), id_level (FK), progress
user_reward_collection:
id_user (FK), id_reward (FK)
And also its mentioned that VARCHAR is being used, so make sure to have an appropriate length for column so that storage can be optimized.
You should use a normalized table that will need more tables, but keep the tabels clear of repattitions
Achievement
level
user_achievement
status