Skip to content

Commit

Permalink
🐛 Fix a bug with postgres view that would display one or more row for…
Browse files Browse the repository at this point in the history
… the same skill/user couple
  • Loading branch information
Ked57 committed May 24, 2021
1 parent a890891 commit 37ecffc
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions hasura/migrations/1621852454428_run_sql_migration/up.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
CREATE OR REPLACE VIEW "public"."UsersCurrentSkillsAndDesires" AS
SELECT
"Skill"."id" AS "skillId",
"Skill"."categoryId",
"UserSkill"."userEmail",
"Skill"."name",
"UserSkill"."level",
"TechnicalAppetite"."level" AS "desire",
"UserSkill"."created_at"
FROM
"Skill"
JOIN
("UserSkill" JOIN "TechnicalAppetite"
ON "UserSkill"."skillId" = "TechnicalAppetite"."skillId"
AND "UserSkill"."userEmail" = "TechnicalAppetite"."userEmail"
AND "UserSkill"."created_at" = "TechnicalAppetite"."created_at"
) ON "Skill".id = "UserSkill"."skillId"
JOIN (
SELECT
"UserSkill"."userEmail",
"Skill"."id",
max("UserSkill"."created_at") AS "created_at"
FROM
"Skill"
JOIN
("UserSkill" JOIN "TechnicalAppetite"
ON "UserSkill"."skillId" = "TechnicalAppetite"."skillId"
AND "UserSkill"."userEmail" = "TechnicalAppetite"."userEmail"
AND "UserSkill"."created_at" = "TechnicalAppetite"."created_at"
) ON "Skill".id = "UserSkill"."skillId"
GROUP BY "UserSkill"."userEmail","Skill"."id"
) AS "Source"
ON "UserSkill"."skillId" = "Source"."id"
AND "UserSkill"."userEmail" = "Source"."userEmail"
AND "UserSkill"."created_at" = "Source"."created_at"
ORDER BY "UserSkill"."created_at" DESC;

0 comments on commit 37ecffc

Please sign in to comment.