-
Notifications
You must be signed in to change notification settings - Fork 0
/
export.bash
106 lines (83 loc) · 2.42 KB
/
export.bash
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#!/usr/bin/env bash
# missing isClubOrganiser
psql nzclubs -c "\copy (SELECT
ac.id AS id, ac.email,
aa.password as \"passHash\",
ac.full_name as name,
ac.region
FROM accounts_cuberprofile ac
LEFT JOIN accounts_account aa
ON ac.user_id=aa.id
ORDER BY id
) TO 'User.csv' DELIMITER ',' CSV HEADER;"
# combine venue+venue_details into venue
# remove time from date
# missing isPublished
psql nzclubs -c "\copy (SELECT
id,
name,
venue,
venue_details,
address AS location,
description,
contact_email AS contact,
competitor_limit AS \"competitorLimit\",
\"startTime\" AS date,
club_id AS \"clubId\",
registration_link AS \"externalRegistrationLink\"
FROM competitions_competition
) TO 'Meetup.csv' DELIMITER ',' CSV HEADER;"
psql nzclubs -c "\copy (SELECT
cco.competition_id AS \"meetupId\",
cco.cuberprofile_id AS \"userId\"
FROM competitions_competition_organizers cco
UNION
SELECT
ccd.competition_id AS \"meetupId\",
ccd.cuberprofile_id AS \"userId\"
FROM competitions_competition_delegates as ccd
ORDER BY \"meetupId\"
) TO 'MeetupToUser.csv' DELIMITER ',' CSV HEADER;"
psql nzclubs -c "\copy (SELECT
cr.cuber_id as \"userId\",
cr.comp_id as \"meetupId\",
ARRAY_AGG(cee.puzzle) as \"registeredEvents\"
FROM competitions_registration cr
INNER JOIN competitions_registration_events ce
ON cr.id = ce.registration_id
INNER JOIN competitions_event cee
ON ce.event_id=cee.id
GROUP BY cr.comp_id, cr.cuber_id
ORDER BY cr.cuber_id
) TO 'UserInMeetup.csv' DELIMITER ',' CSV HEADER;"
psql nzclubs -c "\copy (SELECT id,name FROM organizers_club ORDER BY id) TO 'Club.csv' DELIMITER ',' CSV HEADER;"
psql nzclubs -c "\copy (SELECT
id,
\"startTime\" AS \"startDate\",
\"endTime\" AS \"endDate\",
puzzle,
format,
proceed AS \"proceedNumber\",
comp_id AS \"meetupId\"
FROM competitions_event
ORDER BY id
) TO 'Round.csv' DELIMITER ',' CSV HEADER;"
psql nzclubs -c "\copy (SELECT
id,
event_id AS \"roundId\",
cuber_id AS \"userId\",
result
FROM competitions_submission
) TO 'Result.csv' DELIMITER ',' CSV HEADER;"
# map solve id to index, start from 0
# combine penalty
psql nzclubs -c "\copy (SELECT
id,
time,
penalty,
submission_id AS \"resultId\"
FROM competitions_solve
ORDER BY submission_id, id
) TO 'Solve.csv' DELIMITER ',' CSV HEADER;"
tar cvf exports.tar *.csv
rm *.csv