feat: add support for versioned achievement, leaderboard, and rich presence logic #2995
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I fixed a ticket yesterday and realized how crazy it was that I was leaving a backup of the logic in the comments section. It seems this is a regular practice that developers are currently doing. That's what led me down this rabbit hole.
This PR begins the process of double-writing achievement, leaderboard, and RP logic to the
triggers
table. This will ultimately lead to:How It Works
The
triggers
table has the following structure:These are the key columns to pay attention to:
triggerable_type
- What kind of asset is this? Current possible values areachievement
,leaderboard
, andgame
(rich presence).triggerable_id
- What is the ID of the asset? (achievement ID, leaderboard ID, game ID)user_id
- Who made this change?version
- Nullable, and increments from 1 -> 2 -> 3 -> N. If an achievement has never been published, its version will always benull
. Once it is published, the version is automatically set to 1. After every update, the version increments, regardless of who updated it.parent_id
- Forms a linked list of a triggerable's version history. If the current version is 2,parent_id
will point to the row whereversion
is 1.conditions
- Mem, MemAddr, RichPresencePatch.type
,stat
,stat_goal
, andstat_format
are not currently being written to.For achievements:
For leaderboards:
For rich presence:
How to Test This PR
First, you'll need to sync all the existing trigger logic to your
triggers
table (which should currently be empty):Now, just create and update logic for triggerable assets as you normally do. You should observe changes being made in the
triggers
table.Caveats
triggers
table. It does its best to try to preservecreated_at
andupdated_at
timestamps from triggerable asset and system comment model values.Open Questions
triggers
table, which could kind of be like a commit message?Next Steps
Mem
,MemAddr
, andRichPresencePatch
. Read these values from thetriggers
table.Prior Art
Documented migration which added the
triggers
table: https://github.com/RetroAchievements/RAWeb/blob/6bb51893178da57f26b4a8fd5bc715a9e17e7e9a/database/migrations/platform/2018_10_01_000001_create_triggers_table.php