From 9d9ab5c18727c80339bbd43c83de35d9c04c7c0f Mon Sep 17 00:00:00 2001 From: lee Date: Tue, 4 Jan 2022 18:37:57 +0000 Subject: [PATCH 1/5] docs: adding sql templates to the db documentation --- docs/db/sql.md | 187 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 187 insertions(+) create mode 100644 docs/db/sql.md diff --git a/docs/db/sql.md b/docs/db/sql.md new file mode 100644 index 00000000..d711e43f --- /dev/null +++ b/docs/db/sql.md @@ -0,0 +1,187 @@ +## Example of SQL queries + +### sign up export + +```sql +-- query for **SINGUP** +SELECT DISTINCT + u.id, + u."githubLogin", + u.attrs ->> 'email' as email, + u.attrs ->> 'image' as image, + u.attrs ->> 'lastName' as "last-name", + u.attrs ->> 'firstName' as "firstName", + u."createdAt" as "account-creation-date" +FROM public.user u +WHERE u.id NOT IN (SELECT "userId" FROM public.user_role) +AND u.id NOT IN (SELECT "userId" FROM public.progress p WHERE p."userId"=u.id); +``` + +### Toad export + +```sql +-- query for **TOAD** +-- With g AS (SELECT r.attrs ->> 'games' as games, r."userId" FROM public.result r) +-- SELECT * FROM json_array_elements(g); +SELECT DISTINCT + u.id, + "githubLogin", + u.attrs ->> 'name' as name, + u.attrs ->> 'email' as email, + u.attrs ->> 'image' as image, + u.attrs ->> 'gender' as gender, + u.attrs ->> 'country' as country, + u.attrs ->> 'language' as language, + u.attrs ->> 'lastName' as "last-name", + u.attrs ->> 'firstName' as "firstName", + u.attrs ->> 'dateOfBirth' as "date-of-birth", + u.attrs ->> 'environment' as environment, + u.attrs ->> 'general-conditionsAcceptedname' as "general-conditions-accepted", + u."createdAt" as "account-creation-date", + r.attrs ->> 'score' as "game-score", + r.attrs ->> 'allowedAttempts' as "allowed-attempts", + r.attrs ->> 'games' as games +FROM public.user u +LEFT JOIN public.result r ON u.id=r."userId" AND r.path LIKE '%/onboarding/games' +WHERE r."type"='admin_selection' +AND u.id NOT IN (SELECT "userId" FROM public.user_role) +AND r.grade IS NULL +AND r.attrs ->> 'games' IS NOT NULL +ORDER BY r.attrs ->> 'score' ASC; +``` + +### Administration export + +```sql +-- query for **administration** +SELECT DISTINCT + u.id, + u."githubLogin", + r.attrs ->> 'name' as name, + r.attrs ->> 'email' as email, + r.attrs ->> 'image' as image, + r.attrs ->> 'gender' as gender, + r.attrs ->> 'country' as country, + r.attrs ->> 'language' as language, + r.attrs ->> 'firstName' as "first-name", + r.attrs ->> 'lastName' as "last-name", + r.attrs ->> 'discordId' as "discord-id", + r.attrs ->> 'addressCity' as "address-city", + r.attrs ->> 'dateOfBirth' as "date-of-birth", + r.attrs ->> 'environment' as environment, + r.attrs ->> 'medicalInfo' as "medical-info" , + r.attrs ->> 'discordLogin' as "discord-login" , + r.attrs ->> 'placeOfBirth' as "place-of-birth" , + r.attrs ->> 'addressStreet' as "address-street" , + r.attrs ->> 'addressCountry' as "address-country" , + r.attrs ->> 'countryOfBirth' as "country-of-birth" , + r.attrs ->> 'chart01Accepted' as "chart-01-accepted" , + r.attrs ->> 'id-cardUploadId' as "id-card-uploadId", + r.attrs ->> 'addressPostalCode' as "address-postal-code" , + r.attrs ->> 'emergencyLastName' as "emergency-last-name" , + r.attrs ->> 'emergencyFirstName' as "emergency-first-name" , + r.attrs ->> 'regulationAccepted' as "regulation-accepted" , + r.attrs ->> 'emergencyAffiliation' as "emergency-affiliation" , + r.attrs ->> 'addressComplementStreet' as "address-complement-street" , + r.attrs ->> 'general-conditionsAccepted' as "general-conditions-accepted", + u."createdAt" as "account-creation-date", + r.attrs ->> 'phase' as phase, + COUNT(p.id) as attempts +FROM public.user u +LEFT JOIN public.result r ON u.id=r."userId" AND r.path LIKE '%/onboarding/administration' AND r.grade IS NULL +LEFT JOIN public.progress p ON u.id=p."userId" AND p.path LIKE '%/onboarding/administration' +WHERE r."type"='admin_selection' +AND u.id NOT IN (SELECT "userId" FROM public.user_role) +GROUP BY u.id, r.attrs; +``` + +### xp per user per activity + + +```sql +-- user | xp | last activity : with parent association, "this may be stupid to put the path alrady as the parent!" +WITH xp_user AS ( + SELECT + u."githubLogin", + xp.amount, + xp.path, + xp."eventParentId" + FROM public.user u + LEFT JOIN public.xp_by_event xp ON xp."userId"=u.id + WHERE xp.amount IS NOT NULL + ORDER BY u."githubLogin" ASC +) +SELECT + xu."githubLogin", + xu.amount, + xu.path, + e.path as "parent-path" +FROM xp_user xu +LEFT JOIN public.event e ON e.id=xu."eventParentId"; +``` + +### user per xp + +```sql +-- user per xp +SELECT + u.id, + u."githubLogin", + u.attrs ->> 'name' as name, + u.attrs ->> 'email' as email, + u.attrs ->> 'image' as image, + u.attrs ->> 'gender' as gender, + u.attrs ->> 'country' as country, + u.attrs ->> 'language' as language, + u.attrs ->> 'lastName' as "last-name", + u.attrs ->> 'firstName' as "firstName", + u.attrs ->> 'dateOfBirth' as "date-of-birth", + u.attrs ->> 'environment' as environment, + u.attrs ->> 'general-conditionsAcceptedname' as "general-conditions-accepted", + u."createdAt" as "account-creation-date", + xp.amount as "xp-amount" +FROM public.user u, public.xp xp +WHERE u.id=xp."userId" +ORDER BY xp.amount DESC; +``` + +### group status + +```sql +-- group status +SELECT + u."githubLogin", + g.path, + g.status +FROM public.user u, public."group" g +WHERE u.id=g."captainId" +ORDER BY u."githubLogin" ASC; +``` + +### group progresses + +```sql +-- group progresses +WITH progress_group AS ( + SELECT + p.path, + p.grade, + p."isDone", + p.campus, + g."captainId", + g.status + FROM public.progress p + LEFT JOIN public."group" g ON g.id=p."groupId" +) +SELECT DISTINCT + u."githubLogin", + pg.status as "group-status", + pg.path, + pg.grade, + pg."isDone", + pg.campus +FROM public.user u +LEFT JOIN progress_group pg ON "captainId"=u.id +WHERE pg.path IS NOT NULL +ORDER BY u."githubLogin" ASC; +``` \ No newline at end of file From 83395eb17905917d65f774c2cb09d5f1065ffe72 Mon Sep 17 00:00:00 2001 From: lee Date: Wed, 5 Jan 2022 14:19:45 +0000 Subject: [PATCH 2/5] adding description for each query --- docs/db/sql.md | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/docs/db/sql.md b/docs/db/sql.md index d711e43f..5c212d2c 100644 --- a/docs/db/sql.md +++ b/docs/db/sql.md @@ -1,9 +1,10 @@ ## Example of SQL queries -### sign up export +### sign up + +The following query returns the users that are currently in the sign up process. ```sql --- query for **SINGUP** SELECT DISTINCT u.id, u."githubLogin", @@ -17,7 +18,9 @@ WHERE u.id NOT IN (SELECT "userId" FROM public.user_role) AND u.id NOT IN (SELECT "userId" FROM public.progress p WHERE p."userId"=u.id); ``` -### Toad export +### Toad + +The following query returns the users that are currently in the toad process. The information includes user and games info ```sql -- query for **TOAD** @@ -50,7 +53,9 @@ AND r.attrs ->> 'games' IS NOT NULL ORDER BY r.attrs ->> 'score' ASC; ``` -### Administration export +### Administration + +The following query returns the users currently in the administration process. All information about the user, the number of attempts and current phase. ```sql -- query for **administration** @@ -97,9 +102,9 @@ GROUP BY u.id, r.attrs; ### xp per user per activity +The following query returns the amount of xp per user and per activity ```sql --- user | xp | last activity : with parent association, "this may be stupid to put the path alrady as the parent!" WITH xp_user AS ( SELECT u."githubLogin", @@ -122,6 +127,8 @@ LEFT JOIN public.event e ON e.id=xu."eventParentId"; ### user per xp +The following query returns the amount of xp per user + ```sql -- user per xp SELECT @@ -147,6 +154,8 @@ ORDER BY xp.amount DESC; ### group status +The following query returns the groups status per captain + ```sql -- group status SELECT @@ -160,6 +169,8 @@ ORDER BY u."githubLogin" ASC; ### group progresses +The following query returns the progress per group + ```sql -- group progresses WITH progress_group AS ( From f60122657b1a519ada8644576b472090e7cba9c4 Mon Sep 17 00:00:00 2001 From: Christopher Fremond <34804391+Frenchris@users.noreply.github.com> Date: Fri, 7 Jan 2022 15:23:38 +0000 Subject: [PATCH 3/5] Update sql.md punctuations and typos. --- docs/db/sql.md | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/docs/db/sql.md b/docs/db/sql.md index 5c212d2c..1c325cc0 100644 --- a/docs/db/sql.md +++ b/docs/db/sql.md @@ -20,7 +20,7 @@ AND u.id NOT IN (SELECT "userId" FROM public.progress p WHERE p."userId"=u.id); ### Toad -The following query returns the users that are currently in the toad process. The information includes user and games info +The following query returns the users that are currently in the toad process. The information includes user and games information. ```sql -- query for **TOAD** @@ -55,7 +55,7 @@ ORDER BY r.attrs ->> 'score' ASC; ### Administration -The following query returns the users currently in the administration process. All information about the user, the number of attempts and current phase. +The following query returns the users currently in the administration process. This includes all information about the user, the number of attempts and current phase. ```sql -- query for **administration** @@ -102,7 +102,7 @@ GROUP BY u.id, r.attrs; ### xp per user per activity -The following query returns the amount of xp per user and per activity +The following query returns the amount of xp per user and per activity. ```sql WITH xp_user AS ( @@ -127,7 +127,7 @@ LEFT JOIN public.event e ON e.id=xu."eventParentId"; ### user per xp -The following query returns the amount of xp per user +The following query returns the amount of xp per user. ```sql -- user per xp @@ -154,7 +154,7 @@ ORDER BY xp.amount DESC; ### group status -The following query returns the groups status per captain +The following query returns the groups status per captain. ```sql -- group status @@ -169,7 +169,7 @@ ORDER BY u."githubLogin" ASC; ### group progresses -The following query returns the progress per group +The following query returns the progress per group. ```sql -- group progresses @@ -195,4 +195,4 @@ FROM public.user u LEFT JOIN progress_group pg ON "captainId"=u.id WHERE pg.path IS NOT NULL ORDER BY u."githubLogin" ASC; -``` \ No newline at end of file +``` From e28de619a81eddde8c9b9f0ce6aa696f71b3357e Mon Sep 17 00:00:00 2001 From: Chris Date: Thu, 13 Jan 2022 23:04:15 +0000 Subject: [PATCH 4/5] added intro --- docs/db/sql.md | 31 ++++++++++++++++++++++++++++--- 1 file changed, 28 insertions(+), 3 deletions(-) diff --git a/docs/db/sql.md b/docs/db/sql.md index 1c325cc0..c363e082 100644 --- a/docs/db/sql.md +++ b/docs/db/sql.md @@ -1,6 +1,31 @@ -## Example of SQL queries +## Introduction -### sign up +This documentation is a quickstart guide for the use of metabase in a school server. + +Pre-requisites: + +- An access account given by your administrator. +- A basic knowledge of SQL + +### Where to enter your SQL queries + +The path to metabase is {DOMAIN}/metabase + +After loggin with valid credentials this is where you land, +In the bottom section `OUR DATA` + +- Click on the `metabase` database. + +- A folder `public` should appear among others. Click on it. + +At this point you can see all tables of the public sql database +To execute a query, simply click on the top right button `write SQL` + +Following are examples of SQL queries to help you get you started. + +## Examples of SQL queries + +### Sign up The following query returns the users that are currently in the sign up process. @@ -106,7 +131,7 @@ The following query returns the amount of xp per user and per activity. ```sql WITH xp_user AS ( - SELECT + SELECT u."githubLogin", xp.amount, xp.path, From 603a4e82dc6fa8c68f78a625a5d19e734e0388b9 Mon Sep 17 00:00:00 2001 From: Chris Date: Thu, 13 Jan 2022 23:08:23 +0000 Subject: [PATCH 5/5] correction --- docs/db/sql.md | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/docs/db/sql.md b/docs/db/sql.md index c363e082..ec14aef0 100644 --- a/docs/db/sql.md +++ b/docs/db/sql.md @@ -5,21 +5,21 @@ This documentation is a quickstart guide for the use of metabase in a school ser Pre-requisites: - An access account given by your administrator. -- A basic knowledge of SQL +- A basic knowledge of SQL. ### Where to enter your SQL queries -The path to metabase is {DOMAIN}/metabase +The path to metabase is `{DOMAIN}/metabase` . After loggin with valid credentials this is where you land, -In the bottom section `OUR DATA` +In the bottom section `OUR DATA`. - Click on the `metabase` database. - A folder `public` should appear among others. Click on it. -At this point you can see all tables of the public sql database -To execute a query, simply click on the top right button `write SQL` +At this point you can see all tables of the public sql database. +To execute a query, simply click on the top right button `write SQL`. Following are examples of SQL queries to help you get you started. @@ -49,8 +49,6 @@ The following query returns the users that are currently in the toad process. Th ```sql -- query for **TOAD** --- With g AS (SELECT r.attrs ->> 'games' as games, r."userId" FROM public.result r) --- SELECT * FROM json_array_elements(g); SELECT DISTINCT u.id, "githubLogin", @@ -80,7 +78,7 @@ ORDER BY r.attrs ->> 'score' ASC; ### Administration -The following query returns the users currently in the administration process. This includes all information about the user, the number of attempts and current phase. +The following query returns the users currently in the administration process. This includes all information about the user, the number of attempts and the current phase. ```sql -- query for **administration** @@ -125,7 +123,7 @@ AND u.id NOT IN (SELECT "userId" FROM public.user_role) GROUP BY u.id, r.attrs; ``` -### xp per user per activity +### Xp per user per activity The following query returns the amount of xp per user and per activity. @@ -150,7 +148,7 @@ FROM xp_user xu LEFT JOIN public.event e ON e.id=xu."eventParentId"; ``` -### user per xp +### Xp per user The following query returns the amount of xp per user. @@ -177,7 +175,7 @@ WHERE u.id=xp."userId" ORDER BY xp.amount DESC; ``` -### group status +### Group status per captain The following query returns the groups status per captain. @@ -192,7 +190,7 @@ WHERE u.id=g."captainId" ORDER BY u."githubLogin" ASC; ``` -### group progresses +### Group progresses The following query returns the progress per group.