Skip to content

Commit

Permalink
Select active season by date (#33)
Browse files Browse the repository at this point in the history
  • Loading branch information
BlackYps authored Sep 30, 2021
1 parent 0151ca7 commit b7614c3
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
3 changes: 3 additions & 0 deletions migrations/V006__add_season_end_date.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
SET time_zone='+00:00';

UPDATE league_season SET end_date = "2021-10-31 23:59:00" WHERE league_season.id>2;
5 changes: 3 additions & 2 deletions service/league_service/league_service.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import asyncio
from collections import defaultdict
from datetime import datetime
from typing import Dict

import aiocron
from aio_pika import IncomingMessage
from sqlalchemy import and_, select
from sqlalchemy import and_, between, select
from sqlalchemy.dialects.mysql import insert

from service import config
Expand Down Expand Up @@ -67,7 +68,7 @@ async def update_data(self):
.outerjoin(league)
.outerjoin(leaderboard)
)
.where(league_season.c.end_date == None)
.where(between(datetime.now(), league_season.c.start_date, league_season.c.end_date))
)
result = await conn.execute(sql)
division_rows = await result.fetchall()
Expand Down
5 changes: 3 additions & 2 deletions tests/data/test-data.sql
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@ INSERT INTO league (id, technical_name, name_key, description_key) VALUES

INSERT INTO league_season (id, league_id, leaderboard_id, name_key, start_date, end_date) VALUES
(1, 1, 1, "season.1", NOW() - interval 2 year, NOW() - interval 1 year),
(2, 1, 1, "season.2", NOW() - interval 1 year, NULL),
(3, 2, 2, "season.3", NOW() - interval 2 year, NULL);
(2, 1, 1, "season.2", NOW() - interval 1 year, NOW() + interval 1 year),
(3, 2, 2, "season.3", NOW() - interval 2 year, NOW() + interval 1 year),
(4, 1, 1, "season.4", NOW() + interval 1 year, NOW() + interval 2 year);

INSERT INTO league_season_division (id, league_season_id, division_index, name_key, description_key) VALUES
(1, 1, 1, "L1D1", "description_key"),
Expand Down

0 comments on commit b7614c3

Please sign in to comment.