Skip to content

Commit 174eb8e

Browse files
committed
Adding sql helper scripts
1 parent a88d0f8 commit 174eb8e

File tree

4 files changed

+103
-1
lines changed

4 files changed

+103
-1
lines changed

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,12 @@ revert migrations with
9393
diesel migration revert
9494
```
9595
96+
Use sqlformat:
97+
```
98+
pip install sqlparse
99+
sqlformat --reindent queue_history.sql -o queue_history.sql
100+
```
101+
96102
97103
Install debuggin extensions for React and Redux
98104
(Chrome)

dangerous_queries.sql

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/*
2+
WIP
3+
https://stackoverflow.com/questions/14498143/postgres-update-from-left-join
4+
*/
5+
begin;
6+
update queues q
7+
set q.locked=true
8+
from (select *
9+
from user_events
10+
where date(user_events.time) > (current_date - '1 year'::interval)) u
11+
where q.id = u.queue_id
12+
and u.user_id is null;
13+
rollback;
14+
15+
\echo '\n\n\nGetting the queues that has had no entries during the last 24 months, candidates for hide/delete'
16+
begin;
17+
update queues
18+
set hiding=true
19+
from queues q
20+
left join
21+
(select *
22+
from user_events
23+
where date(user_events.time) > (current_date - '2 year'::interval)) u on q.id = u.queue_id
24+
where u.user_id is null;
25+
rollback;
26+

queue_history.sql

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
\c queuesystem \echo '\n\n\nGetting all time count for the amount of users of the queue system'
2+
select count (u.ugkthid)
3+
from users u;
4+
5+
\echo '\n\n\nGetting all time count for the amount times people entered the queue system'
6+
select count(distinct u.id)
7+
from user_events u
8+
where u.left_queue=false;
9+
10+
\echo '\n\n\nGetting all the amount unique people entered the queue system during the last 12 months'
11+
select count(distinct us.id)
12+
from user_events u
13+
inner join users us on us.id = u.user_id
14+
where u.left_queue=false
15+
and date(u.time) > (current_date - '1 year'::interval);
16+
17+
\echo '\n\n\nGetting all the amount times people entered the queue system during the last 12 months'
18+
select count(distinct u.id)
19+
from user_events u
20+
where u.left_queue=false
21+
and date(u.time) > (current_date - '1 year'::interval);
22+
23+
\echo '\n\n\nGetting the queues that has had no entries during the last year, candidates for lock/hide'
24+
select q.name
25+
from queues q
26+
left join
27+
(select *
28+
from user_events
29+
where date(user_events.time) > (current_date - '1 year'::interval)) u on q.id = u.queue_id
30+
where u.user_id is null;
31+
32+
\echo '\n\n\nGetting the queues that has had no entries during the last 24 months, candidates for hide/delete'
33+
select q.name
34+
from queues q
35+
left join
36+
(select *
37+
from user_events
38+
where date(user_events.time) > (current_date - '2 year'::interval)) u on q.id = u.queue_id
39+
where u.user_id is null;
40+
41+
\echo '\n\n\nGetting the queues that has had no entries ever, candidates for delete'
42+
select q.name
43+
from queues q
44+
left join user_events u on q.id = u.queue_id
45+
where u.user_id is null;
46+
47+
/*
48+
May 2021 list
49+
PPM
50+
Beslut
51+
Automat
52+
DD2419
53+
Xmlpub
54+
Dbtek
55+
OOP
56+
MI
57+
pallinda
58+
maskin
59+
IR
60+
Sprakt
61+
Sudata
62+
DD2380
63+
DM2518
64+
PDC Summer School
65+
prgciteh
66+
DT1130
67+
Semant
68+
DD1346
69+
Qmisk
70+
*/

src/routes/queue_entries.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::db::{self};
1+
use crate::db;
22

33
use rocket_contrib::json::JsonValue;
44

0 commit comments

Comments
 (0)