-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1352 from SplitTime/oveson/use-scopes-in-lottery-…
…division Use scopes in lottery division
- Loading branch information
Showing
11 changed files
with
68 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
db/migrate/20241220002632_update_lotteries_division_rankings_to_version_2.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
class UpdateLotteriesDivisionRankingsToVersion2 < ActiveRecord::Migration[7.0] | ||
def change | ||
update_view :lotteries_division_rankings, version: 2, revert_to_version: 1 | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
with ranked_draws as ( | ||
select lottery_tickets.lottery_entrant_id, | ||
rank() over division_window as division_rank | ||
from lottery_tickets | ||
join lottery_draws on lottery_draws.lottery_ticket_id = lottery_tickets.id | ||
join lottery_entrants on lottery_entrants.id = lottery_tickets.lottery_entrant_id | ||
window division_window as ( | ||
partition by lottery_entrants.lottery_division_id | ||
order by case | ||
when withdrawn is false or withdrawn is null then 0 | ||
when withdrawn is true then 1 end, | ||
lottery_draws.created_at | ||
) | ||
) | ||
|
||
select lottery_entrants.id as lottery_entrant_id, | ||
lottery_divisions.name as division_name, | ||
division_rank, | ||
-- accepted: 0 | ||
-- waitlisted: 1 | ||
-- drawn_beyond_waitlist: 2 | ||
-- not_drawn: 3 | ||
-- withdrawn: 4 | ||
case | ||
when lottery_entrants.withdrawn then 4 | ||
when division_rank <= maximum_entries then 0 | ||
when division_rank <= maximum_entries + maximum_wait_list then 1 | ||
when division_rank is not null then 2 | ||
else 3 end as draw_status | ||
from lottery_entrants | ||
left join ranked_draws on ranked_draws.lottery_entrant_id = lottery_entrants.id | ||
join lottery_divisions on lottery_entrants.lottery_division_id = lottery_divisions.id | ||
; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters