-
Notifications
You must be signed in to change notification settings - Fork 106
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[AUD-1345] Fix favorite playlist profile completion challenge (#2366)
* [AUD-1345] Fix favorite playlist profile completion challenge * Update comment
- Loading branch information
1 parent
0a5f4e0
commit 483c942
Showing
3 changed files
with
292 additions
and
2 deletions.
There are no files selected for viewing
80 changes: 80 additions & 0 deletions
80
discovery-provider/alembic/versions/8e4dda8255fd_fix_profile_completion_challenge_.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
"""fix_profile_completion_challenge_playlist_favorite | ||
Revision ID: 8e4dda8255fd | ||
Revises: a6d2e50a8efa | ||
Create Date: 2022-01-21 20:19:05.992646 | ||
""" | ||
import sqlalchemy as sa | ||
from alembic import op | ||
|
||
# revision identifiers, used by Alembic. | ||
revision = "8e4dda8255fd" | ||
down_revision = "a6d2e50a8efa" | ||
branch_labels = None | ||
depends_on = None | ||
|
||
|
||
def upgrade(): | ||
pass | ||
connection = op.get_bind() | ||
connection.execute( | ||
""" | ||
begin; | ||
-- This migration serves to repair missing state in | ||
-- challenge_profile_completion where previously playlist favorites (saves) | ||
-- did not update the challenge. | ||
-- | ||
-- First, update challenge_profile_completion rows to account | ||
-- for playlist saves. | ||
-- By joining against the saves table for all playlist saves, | ||
-- we can achieve this and only modify rows where users have done | ||
-- a playlist save. | ||
-- | ||
-- Second, use that result to update (recalculate) user_challenges | ||
-- for users that were updated in the first step. | ||
-- | ||
with updated as ( | ||
update challenge_profile_completion | ||
set favorites = true | ||
from saves | ||
where | ||
challenge_profile_completion.user_id = saves.user_id and | ||
saves.is_current = true and | ||
(saves.save_type = 'playlist' or saves.save_type = 'album') and | ||
challenge_profile_completion.favorites = false | ||
returning challenge_profile_completion.* | ||
) | ||
update user_challenges | ||
set | ||
is_complete=( | ||
updated.profile_description and | ||
updated.profile_name and | ||
updated.profile_picture and | ||
updated.profile_cover_photo and | ||
updated.follows and | ||
updated.favorites and | ||
updated.reposts | ||
), | ||
current_step_count=( | ||
cast(updated.profile_description as int) + | ||
cast(updated.profile_name as int) + | ||
cast(updated.profile_picture as int) + | ||
cast(updated.profile_cover_photo as int) + | ||
cast(updated.follows as int) + | ||
cast(updated.favorites as int) + | ||
cast(updated.reposts as int) | ||
) | ||
from updated | ||
where | ||
user_challenges.user_id = updated.user_id; | ||
commit; | ||
""" | ||
) | ||
|
||
|
||
def downgrade(): | ||
# This migration mutates state and has no relevant down migration | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters