Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1,109 changes: 1,000 additions & 109 deletions server/db/migration/V1__tables.sql

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public class DatabaseQueryServiceImpl implements DatabaseQueryService {
@Value("${service.seconds-to-timeout}")
private int secondsToTimeout;

private static List<CachedToken> cachedTokens = new ArrayList<>();
private static final List<CachedToken> cachedTokens = new ArrayList<>();

private static final String PAGINATION_WRAPPER = "select * from (\n%s\n) alias limit %s offset %s";
private static final String PAGINATION_COUNT = "select count(*) from (\n%s\n) alias";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ insert into
c2.name region,
(
select
coalesce(max(continentRank), 0)
coalesce(max(continent_rank), 0)
from
RanksAverage r
inner join users u on u.wca_id = r.personId
inner join Countries c on c.iso2 = u.country_iso2
ranks_average r
inner join users u on u.wca_id = r.person_id
inner join countries c on c.iso2 = u.country_iso2
where
c.continent_id = c2.id
and r.event_id = e.id
Expand Down Expand Up @@ -75,7 +75,7 @@ select
from
events e
left join users u on e.`rank` < 900 -- Filter by active ranks
left join RanksAverage r on r.eventId = e.id
left join ranks_average r on r.event_id = e.id
and r.person_id = u.wca_id
left join countries c on c.iso2 = u.country_iso2
left join continents c2 on c.continent_id = c2.id
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ select
select
c2.name
from
Countries c
left join Continents c2 on c.continentId = c2.id
countries c
left join continents c2 on c.continent_id = c2.id
where
u.country_iso2 = c.iso2
) region,
Expand All @@ -52,9 +52,9 @@ select
) result_type,
sum(
case
when continentRank is null
or continentRank = 0 then default_rank
else r.continentRank
when continent_rank is null
or continent_rank = 0 then default_rank
else r.continent_rank
end
) overall,
json_arrayagg(
Expand All @@ -63,22 +63,22 @@ select
json_object('id', e.id, 'name', e.name, 'rank', e.rank),
'regionalRank',
case
when continentRank is null
or continentRank = 0 then default_rank
else r.continentRank
when continent_rank is null
or continent_rank = 0 then default_rank
else r.continent_rank
end,
'completed',
continentRank is not null
and continentRank > 0
continent_rank is not null
and continent_rank > 0
)
) events
from
Events e
events e
left join users u on e.`rank` < 900 -- Filter by active ranks
left join RanksSingle r on r.eventId = e.id
and r.personId = u.wca_id
left join Countries c on c.iso2 = u.country_iso2
left join Continents c2 on c.continentId = c2.id
left join ranks_single r on r.event_id = e.id
and r.person_id = u.wca_id
left join countries c on c.iso2 = u.country_iso2
left join continents c2 on c.continent_id = c2.id
left join default_ranks dr on dr.event_id = e.id
and dr.region = c2.name
where
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,17 @@ insert into
c2.iso2 region,
(
select
coalesce(max(countryRank), 0)
coalesce(max(country_rank), 0)
from
RanksAverage r
inner join users u on u.wca_id = r.personId
ranks_average r
inner join users u on u.wca_id = r.person_id
where
r.eventId = e.id
r.event_id = e.id
and u.country_iso2 = c2.iso2
) + 1 default_rank
from
Events e,
Countries c2
events e,
countries c2
where
e.`rank` < 900
)
Expand All @@ -33,7 +33,7 @@ select
select
c.name
from
Countries c
countries c
where
u.country_iso2 = c.iso2
) region,
Expand All @@ -50,9 +50,9 @@ select
) result_type,
sum(
case
when countryRank is null
or countryRank = 0 then default_rank
else r.countryRank
when country_rank is null
or country_rank = 0 then default_rank
else r.country_rank
end
) overall,
json_arrayagg(
Expand All @@ -61,21 +61,21 @@ select
json_object('id', e.id, 'name', e.name, 'rank', e.rank),
'regionalRank',
case
when countryRank is null
or countryRank = 0 then default_rank
else r.countryRank
when country_rank is null
or country_rank = 0 then default_rank
else r.country_rank
end,
'completed',
countryRank is not null
and countryRank > 0
country_rank is not null
and country_rank > 0
)
) events
from
Events e
events e
left join users u on e.`rank` < 900 -- Filter by active ranks
left join RanksAverage r on r.eventId = e.id
and r.personId = u.wca_id
left join Countries c on c.iso2 = u.country_iso2
left join ranks_average r on r.event_id = e.id
and r.person_id = u.wca_id
left join countries c on c.iso2 = u.country_iso2
left join default_ranks dr on dr.event_id = e.id
and dr.region = c.iso2
where
Expand All @@ -85,9 +85,9 @@ where
select
1
from
RanksAverage ra2
ranks_average ra2
where
ra2.eventId = e.id
ra2.event_id = e.id
)
group by
wca_id
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ insert into
coalesce(max(country_rank), 0)
from
ranks_single r
inner join persons p on p.wca_id = r.personId
inner join persons p on p.wca_id = r.person_id
where
r.event_id = e.id
and p.country_id = c2.iso2
Expand All @@ -42,8 +42,8 @@ select
'Country'
) region_type,
wca_id,
u.name,
country_iso2,
p.name,
country_id,
(
select
'Single'
Expand All @@ -61,9 +61,9 @@ select
json_object('id', e.id, 'name', e.name, 'rank', e.rank),
'regionalRank',
case
when countryRank is null
when country_rank is null
or country_rank = 0 then default_rank
else r.countryRank
else r.country_rank
end,
'completed',
country_rank is not null
Expand All @@ -73,12 +73,14 @@ select
from
events e
left join persons p on e.`rank` < 900 -- Filter by active ranks
left join ranks_single r on r.eventId = e.id
left join ranks_single r on r.event_id = e.id
and r.person_id = p.wca_id
left join countries c on c.id = p.country_id
left join default_ranks dr on dr.event_id = e.id
and dr.region = c.id
where
wca_id is not null
group by
wca_id
wca_id,
country_id,
name
Original file line number Diff line number Diff line change
Expand Up @@ -34,31 +34,32 @@ select
'World'
) region_type,
wca_id,
u.name,
country_iso2,
p.name,
country_id,
(
select
'Average'
) result_type,
sum(coalesce(r.worldRank, default_rank)) overall,
sum(coalesce(r.world_rank, default_rank)) overall,
json_arrayagg(
json_object(
'event',
json_object('id', e.id, 'name', e.name, 'rank', e.rank),
'regionalRank',
coalesce(r.worldRank, default_rank),
coalesce(r.world_rank, default_rank),
'completed',
r.worldRank is not null
r.world_rank is not null
)
) events
from
events e
left join users u on e.`rank` < 900 -- Filter by active ranks
left join persons p on e.`rank` < 900 -- Filter by active ranks
left join ranks_average r on r.event_id = e.id
and r.person_id = u.wca_id
and r.person_id = p.wca_id
left join default_ranks dr on dr.event_id = e.id
where
wca_id is not null
and sub_id = 1
and exists (
-- Some events has no averages and this excludes them to avoid adding 1 into the sum
select
Expand All @@ -69,4 +70,6 @@ where
ra2.event_id = e.id
)
group by
wca_id
wca_id,
p.name,
p.country_id
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ insert into
from
ranks_single r
where
r.eventId = e.id
r.event_id = e.id
) + 1 default_rank
from
events e
Expand All @@ -34,8 +34,8 @@ select
'World'
) region_type,
wca_id,
u.name,
country_iso2,
p.name,
country_id,
(
select
'Single'
Expand All @@ -53,11 +53,14 @@ select
) events
from
events e
left join users u on e.`rank` < 900 -- Filter by active ranks
left join persons p on e.`rank` < 900 -- Filter by active ranks
left join ranks_single r on r.event_id = e.id
and r.person_id = u.wca_id
and r.person_id = p.wca_id
left join default_ranks dr on dr.event_id = e.id
where
wca_id is not null
and sub_id = 1
group by
wca_id
wca_id,
p.name,
p.country_id
Loading