Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: add origin_network to Error model #205

Merged
merged 1 commit into from
Mar 27, 2024
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
14 changes: 12 additions & 2 deletions mm-bot/src/models/error.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,26 @@
from datetime import datetime

from sqlalchemy import Column, Integer, ForeignKey, String, DateTime
from sqlalchemy import Column, Integer, ForeignKeyConstraint, String, DateTime, Enum
from sqlalchemy.orm import relationship, Mapped

from config.database_config import Base
from models.network import Network
from models.order import Order


class Error(Base):
__tablename__ = "error"
id: int = Column(Integer, primary_key=True, nullable=False)
order_id: int = Column(Integer, ForeignKey("orders.order_id"), nullable=False)
order_id: int = Column(Integer, nullable=False)
origin_network: Network = Column(Enum(Network), nullable=False)
order: Mapped[Order] = relationship("Order")
message: str = Column(String, nullable=False)
created_at: datetime = Column(DateTime, nullable=False, server_default="clock_timestamp()")

# Set order_id and origin_network as composite foreign key
__table_args__ = (
ForeignKeyConstraint(
["order_id", "origin_network"],
["orders.order_id", "orders.origin_network"]
),
)
2 changes: 1 addition & 1 deletion mm-bot/src/services/order_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ def set_order_failed(self, order: Order, error_message: str) -> Order:
:param error_message: the error message to store in the database
"""
order = self.set_failed(order, True)
error = Error(order_id=order.order_id, message=error_message)
error = Error(order_id=order.order_id, origin_network=order.origin_network, message=error_message)
self.error_dao.create_error(error)
return order

Expand Down
Loading