forked from stadust/pointercrate
-
Notifications
You must be signed in to change notification settings - Fork 1
/
20200227174850_view_cleanup.down.sql
66 lines (56 loc) · 2.86 KB
/
20200227174850_view_cleanup.down.sql
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
-- This file should undo anything in `up.sql`
CREATE VIEW records_pds AS -- records with player, demon and submitter
SELECT records.id, records.progress, records.video, records.status_, records.notes,
players.id AS player_id, players.name AS player_name, players.banned AS player_banned,
demons.id AS demon_id, demons.name AS demon_name, demons.position,
submitters.submitter_id, submitters.banned AS submitter_banned
FROM records
INNER JOIN submitters
ON records.submitter = submitters.submitter_id
INNER JOIN players
ON records.player = players.id
INNER JOIN demons
ON demons.id = records.demon;
CREATE VIEW records_pd AS -- records with player and demon
SELECT records.id, records.progress, records.video, records.status_, records.submitter AS submitter_id,
players.id AS player_id, players.name AS player_name, players.banned AS player_banned,
demons.id AS demon_id, demons.name AS demon_name, demons.position
FROM records
INNER JOIN players
ON records.player = players.id
INNER JOIN demons
ON demons.id = records.demon;
-- for minimal representation
CREATE VIEW records_p AS -- records with player
SELECT records.id, records.progress, records.video, records.status_, records.demon,
players.id AS player_id, players.name AS player_name, players.banned AS player_banned
FROM records
INNER JOIN players
ON records.player = players.id;
CREATE VIEW records_d AS -- records with demon
SELECT records.id, records.progress, records.video, records.status_, records.player,
demons.id AS demon_id, demons.name AS demon_name, demons.position
FROM records
INNER JOIN demons
ON demons.id = records.demon;
CREATE VIEW demons_pv AS -- demons with publisher and verifier
SELECT demons.id, demons.position, demons.name, demons.requirement, demons.video,
publishers.id AS publisher_id, publishers.name AS publisher_name, publishers.banned AS publisher_banned,
verifiers.id AS verifier_id, verifiers.name AS verifier_name, verifiers.banned AS verifier_banned
FROM demons
INNER JOIN players AS verifiers
ON verifiers.id = demons.verifier
INNER JOIN players AS publishers
ON publishers.id = demons.publisher;
CREATE VIEW demons_p AS -- demons with publisher
SELECT demons.id, demons.position, demons.name, demons.video,
publishers.id AS publisher_id, publishers.name AS publisher_name, publishers.banned AS publisher_banned
FROM demons
INNER JOIN players AS publishers
ON publishers.id = demons.publisher;
CREATE VIEW players_n AS -- players with nationality
SELECT players.id, players.name, players.banned,
nationalities.iso_country_code, nationalities.nation
FROM players
LEFT OUTER JOIN nationalities
ON players.nationality = nationalities.iso_country_code;