-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: flow_user_progress migration (#467)
Co-authored-by: David Pešička <61206880+pesickadavid@users.noreply.github.com>
- Loading branch information
1 parent
11c6e9b
commit 05bbff1
Showing
1 changed file
with
35 additions
and
14 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -1,20 +1,41 @@ | ||
-- Custom SQL migration file, put you code below! -- | ||
WITH | ||
CTE AS ( | ||
SELECT | ||
E.USER_HASH, | ||
E.FLOW_ID, | ||
E.EVENT_TIME, | ||
ROW_NUMBER() OVER ( | ||
PARTITION BY | ||
E.USER_HASH, | ||
E.FLOW_ID | ||
ORDER BY | ||
E.EVENT_TIME DESC | ||
) AS RN | ||
FROM | ||
EVENT E | ||
WHERE | ||
NOT EXISTS ( | ||
SELECT | ||
FUP.USER_HASH | ||
FROM | ||
FLOW_USER_PROGRESS FUP | ||
WHERE | ||
E.USER_HASH = FUP.USER_HASH | ||
AND E.FLOW_ID = FUP.FLOW_ID | ||
) | ||
AND E.EVENT_TYPE IN ('finishFlow', 'cancelFlow') | ||
AND E.USER_HASH IS NOT NULL | ||
) | ||
|
||
|
||
INSERT INTO | ||
FLOW_USER_PROGRESS (USER_HASH, FLOW_ID, UPDATED_AT) | ||
SELECT | ||
E.USER_HASH, | ||
E.FLOW_ID, | ||
E.EVENT_TIME | ||
USER_HASH, | ||
FLOW_ID, | ||
EVENT_TIME | ||
FROM | ||
EVENT E | ||
CTE | ||
WHERE | ||
NOT EXISTS ( | ||
SELECT | ||
FUP.USER_HASH | ||
FROM | ||
FLOW_USER_PROGRESS FUP | ||
WHERE | ||
E.USER_HASH = FUP.USER_HASH | ||
) | ||
AND E.EVENT_TYPE IN ('finishFlow', 'cancelFlow') | ||
AND E.USER_HASH IS NOT NULL | ||
RN = 1 |