fix: Add cleanup migration for erroneous records in applet_events (M2-9237) #1858
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.
📝 Description
🔗 Jira Ticket M2-9237
Note
This PR should not be reviewed until this ticket has been prioritised
This PR adds a migration that moves the erroneous entries in the
applet_events
table to a temporary table calledapplet_events_cleanup
for eventual permanent deletion. This should fix failed data exports in applets with deleted activities/flows before the implementation of M2 9161.Prior to the implementation of that ticket, rows were created in the applet_events table linking activities/flows (and their events) with versions of the applet they don't exist in. The downstream effect of this is that the API endpoint that returns applet schedule history fails because the query returns
NULL
values for the result of the JOINs with theactivity_histories
andflow_histories
tables for these rows🪤 Peer Testing
Important
Start this test before running the migration
Prepare
applet_events
table representing the deleted items linked to the new applet versionTo do this, we will first need to identify the IDs of the deleted activity and flow. Run this query to get a rundown of the history of the applet (replace the applet ID)
This should give a result like this
These are the entities are are interested in:
Now let's insert new rows into applet_events
Here we're using the event history ID of New Activity 2 (which already has a row in applet_events for applet version 2) for the insert
Test
alembic upgrade head
✏️ Notes
N/A