From f96085e5b3ec8931cf6eb06c4b1dae3b82967340 Mon Sep 17 00:00:00 2001 From: Kapil Viren Ahuja Date: Tue, 21 Feb 2017 14:09:09 +0530 Subject: reference queries for updating roster with match's FK --- ref_queries/update_roster_match_relationship.sql | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 ref_queries/update_roster_match_relationship.sql diff --git a/ref_queries/update_roster_match_relationship.sql b/ref_queries/update_roster_match_relationship.sql new file mode 100644 index 0000000..a9c8cdc --- /dev/null +++ b/ref_queries/update_roster_match_relationship.sql @@ -0,0 +1,21 @@ +-- i am thinking how fast slow this will be and if we should do this in DB. +-- maybe we need a script to run a cursor and update records - dont know... +-- a few runs on 35K records was closing my server connection on my shitty laptop + +-- this will update all roster with match_apiId +update "roster" +set "match_apiId" = match."apiId" +from match +where (roster."apiId" = roster_1 or roster."apiId" = roster_2) + + +-- this is same as before however should only pick empty records +update "roster" +set "match_apiId" = match."apiId" +from match +where roster."match_apiId" is not null and (roster."apiId" = roster_1 or roster."apiId" = roster_2) + + + +-- this should always return a count of 2 for each match_apiId :) +select "match_apiId", count(*) from roster group by "match_apiId" -- cgit v1.3.1 From 2309c313b648e06b3c441ab8aafd845939dedc48 Mon Sep 17 00:00:00 2001 From: Kapil Viren Ahuja Date: Sat, 25 Feb 2017 18:34:41 +0530 Subject: fixing last bit of model (refactoring phase 1) (#19) --- queries/match.sql | 6 +++--- queries/participant.sql | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/queries/match.sql b/queries/match.sql index 5dfa692..a07652f 100644 --- a/queries/match.sql +++ b/queries/match.sql @@ -7,9 +7,9 @@ attributes->>'gameMode' AS "gameMode", COALESCE(NULLIF(attributes->>'patchVersion', ''), '0') AS "patchVersion", attributes->>'shardId' AS "shardId", attributes->'stats'->>'endGameReason' AS "endGameReason", -attributes->'stats'->>'queue' AS "queue" --, +attributes->'stats'->>'queue' AS "queue" , ---relationships->'rosters'->'data'->0->>'id' as "roster_1", ---relationships->'rosters'->'data'->1->>'id' as "roster_2" +relationships->'rosters'->'data'->0->>'id' as "roster_1", +relationships->'rosters'->'data'->1->>'id' as "roster_2" FROM "match" diff --git a/queries/participant.sql b/queries/participant.sql index d1d81ce..b7685a9 100644 --- a/queries/participant.sql +++ b/queries/participant.sql @@ -1,7 +1,7 @@ SELECT id AS "apiId", -relationships->'player'->'data'->>'id' AS "playerId", +relationships->'player'->'data'->>'id' AS "player_apiId", attributes->>'actor' AS "hero", (attributes->'stats'->>'assists')::int AS "assists", @@ -25,4 +25,4 @@ attributes->'stats'->'itemSells' AS "itemSells", attributes->'stats'->'itemUses' AS "itemUses", attributes->'stats'->'items' AS "items" -FROM "participant" +FROM participant -- cgit v1.3.1