Skip to content

Commit

Permalink
Merge branch 'master' into add-pylint
Browse files Browse the repository at this point in the history
  • Loading branch information
sigmadawg authored Nov 1, 2024
2 parents 0fc7686 + fd94afd commit d12357d
Show file tree
Hide file tree
Showing 4 changed files with 99 additions and 4,032 deletions.
80 changes: 78 additions & 2 deletions apps/data_handler/db/models/zklend_events.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
""" This module contains the SQLAlchemy models for the zkLend events. """
from decimal import Decimal

from data_handler.db.models.event import EventBaseModel
from sqlalchemy import Numeric, String
from sqlalchemy.orm import Mapped, mapped_column

from data_handler.db.models.event import EventBaseModel


class AccumulatorsSyncEventData(EventBaseModel):
"""
Expand Down Expand Up @@ -38,3 +37,80 @@ class LiquidationEventData(EventBaseModel):
debt_face_amount: Mapped[Decimal] = mapped_column(Numeric(38, 18), nullable=False)
collateral_token: Mapped[str] = mapped_column(String, nullable=False)
collateral_amount: Mapped[Decimal] = mapped_column(Numeric(38, 18), nullable=False)


class RepaymentEventData(EventBaseModel):
"""
Database model for Repayment event, inheriting from EventBaseModel.
This model stores details of a repayment event, including the addresses involved
and the amounts in raw and face formats.
"""

__tablename__ = "repayment_event"

repayer: Mapped[str] = mapped_column(String, nullable=False)
beneficiary: Mapped[str] = mapped_column(String, nullable=False)
token: Mapped[str] = mapped_column(String, nullable=False)
raw_amount: Mapped[Decimal] = mapped_column(Numeric(38, 18), nullable=False)
face_amount: Mapped[Decimal] = mapped_column(Numeric(38, 18), nullable=False)


class DepositEventData(EventBaseModel):
"""
Database model for Deposit event, inheriting from EventBaseModel.
This model stores details of a deposit event, including the user address,
token, and the face amount of the deposit.
"""

__tablename__ = "deposit_event"

user: Mapped[str] = mapped_column(String, nullable=False)
token: Mapped[str] = mapped_column(String, nullable=False)
face_amount: Mapped[Decimal] = mapped_column(Numeric(38, 18), nullable=False)


class BorrowingEventData(EventBaseModel):
"""
Database model for Borrowing event, inheriting from EventBaseModel.
This model stores details of a borrowing event, including the user address,
token, and amounts in raw and face formats.
"""

__tablename__ = "borrowing_event"

user: Mapped[str] = mapped_column(String, nullable=False)
token: Mapped[str] = mapped_column(String, nullable=False)
raw_amount: Mapped[Decimal] = mapped_column(Numeric(38, 18), nullable=False)
face_amount: Mapped[Decimal] = mapped_column(Numeric(38, 18), nullable=False)


class WithdrawalEventData(EventBaseModel):
"""
Database model for Withdrawal event, inheriting from EventBaseModel.
This model stores details of a withdrawal event, including the user address,
token, and the amount withdrawn.
"""

__tablename__ = "withdrawal_event"

user: Mapped[str] = mapped_column(String, nullable=False)
amount: Mapped[Decimal] = mapped_column(Numeric(38, 18), nullable=False)
token: Mapped[str] = mapped_column(String, nullable=False)


class CollateralEnabledDisabledEventData(EventBaseModel):
"""
Database model for CollateralEnabled/Disabled event, inheriting from EventBaseModel.
This model stores details of a collateral enabled/disabled event, including
the user address and the token involved.
"""

__tablename__ = "collateral_enabled_disabled_event"

user: Mapped[str] = mapped_column(String, nullable=False)
token: Mapped[str] = mapped_column(String, nullable=False)
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@

from typing import Sequence, Union

from alembic import op
import sqlalchemy as sa
import sqlalchemy_utils
from alembic import op
from sqlalchemy import inspect, text

from shared.constants import ProtocolIDs

# revision identifiers, used by Alembic.
Expand Down Expand Up @@ -84,7 +86,22 @@ def upgrade() -> None:
["event_name"],
unique=False,
)
op.drop_index("ix_notification_email", table_name="notification")

conn = op.get_bind()
result = conn.execute(
text(
"SELECT EXISTS (SELECT FROM information_schema.tables WHERE table_name = 'notification');"
)
)
table_exists = result.scalar()

if table_exists:
inspector = inspect(conn)
existing_indexes = [
index["name"] for index in inspector.get_indexes("notification")
]
if "ix_notification_email" in existing_indexes:
op.drop_index("ix_notification_email", table_name="notification")
# ### end Alembic commands ###


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@ def upgrade() -> None:

def downgrade() -> None:
""" Downgrade the database """

conn = op.get_bind()

if conn.engine.dialect.has_table(conn, "withdrawal_event"):
Expand Down Expand Up @@ -219,4 +220,4 @@ def downgrade() -> None:
op.drop_index(
op.f("ix_borrowing_event_block_number"), table_name="borrowing_event"
)
op.drop_table("borrowing_event")
op.drop_table("borrowing_event")
Loading

0 comments on commit d12357d

Please sign in to comment.