diff --git a/alembic/versions/2024-10-13_01-30_88e673b84a4c_separate_orders_for_tasks.py b/alembic/versions/2024-10-13_01-30_88e673b84a4c_separate_orders_for_tasks.py index 04c5593..b03a03a 100644 --- a/alembic/versions/2024-10-13_01-30_88e673b84a4c_separate_orders_for_tasks.py +++ b/alembic/versions/2024-10-13_01-30_88e673b84a4c_separate_orders_for_tasks.py @@ -5,6 +5,7 @@ Create Date: 2024-10-13 01:30:18.842558 """ + from collections import defaultdict from typing import Sequence, Union @@ -20,11 +21,7 @@ def fetch_order_data(s: Session, order_id: int): - order_data = s.execute( - select(column("room_id")) - .select_from(table("orders")) - .where(column("id") == order_id) - ).one() + order_data = s.execute(select(column("room_id")).select_from(table("orders")).where(column("id") == order_id)).one() executors = s.execute( select(column("user_id"), column("order_number")) .select_from(table("executors")) @@ -35,14 +32,13 @@ def fetch_order_data(s: Session, order_id: int): def clone_order(s: Session, order_data, executors): new_order_id = s.scalar( - insert(table("orders", column('room_id'))) - .values(room_id=order_data[0]) - .returning(column('id')) + insert(table("orders", column("room_id"))).values(room_id=order_data[0]).returning(column("id")) ) s.execute( - insert(table("executors", column("user_id"), column("order_id"), column("order_number"))) - .values(order_id=new_order_id), - [{"user_id": e[0], "order_number": e[1]} for e in executors] + insert(table("executors", column("user_id"), column("order_id"), column("order_number"))).values( + order_id=new_order_id + ), + [{"user_id": e[0], "order_number": e[1]} for e in executors], ) return new_order_id @@ -51,9 +47,7 @@ def upgrade() -> None: with Session(bind=op.get_bind()) as session: periodic_tasks: defaultdict[int, list[int]] = defaultdict(list) pairs = session.execute( - select(column("id"), column("order_id")) - .select_from(table("tasks")) - .where(column("order_id").isnot(None)) + select(column("id"), column("order_id")).select_from(table("tasks")).where(column("order_id").isnot(None)) ).all() for task_id, order_id in pairs: periodic_tasks[order_id].append(task_id) @@ -69,7 +63,7 @@ def upgrade() -> None: .values(order_id=new_order_id) .where(column("id") == task_id) ) - + # same for manual tasks manual_tasks: defaultdict[int, list[int]] = defaultdict(list) pairs = session.execute( diff --git a/src/api/routes/bot/manual_task/router.py b/src/api/routes/bot/manual_task/router.py index 5a871f9..9b30f54 100644 --- a/src/api/routes/bot/manual_task/router.py +++ b/src/api/routes/bot/manual_task/router.py @@ -5,7 +5,8 @@ from sqlalchemy.sql.functions import count from src.api.exceptions import ( - TooManyTasksException, ManualTaskIsInactiveException, + TooManyTasksException, + ManualTaskIsInactiveException, ) from src.api.utils import ( ROOM_DEPENDENCY,