From 37ecffc0104c2914e93bd6e45864ba106bfb075a Mon Sep 17 00:00:00 2001 From: Ked57 Date: Mon, 24 May 2021 12:35:30 +0200 Subject: [PATCH] :bug: Fix a bug with postgres view that would display one or more row for the same skill/user couple --- .../1621852454428_run_sql_migration/up.sql | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 hasura/migrations/1621852454428_run_sql_migration/up.sql diff --git a/hasura/migrations/1621852454428_run_sql_migration/up.sql b/hasura/migrations/1621852454428_run_sql_migration/up.sql new file mode 100644 index 00000000..01fe84d2 --- /dev/null +++ b/hasura/migrations/1621852454428_run_sql_migration/up.sql @@ -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;