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

feat: Create db models for nostra events #320

Closed
wants to merge 2 commits into from
Closed
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
56 changes: 56 additions & 0 deletions apps/data_handler/db/models/nostra_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,63 @@ class DebtMintEventModel(EventBaseModel):
"""

__tablename__ = "debt_mint_event"
from decimal import Decimal
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pleasa, sync with master

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


class DebtMintEventModel(EventBaseModel):
"""
Database model for DebtMint event, inheriting from EventBaseModel.

This model stores the user address and the amount minted.
"""

__tablename__ = "debt_mint_event"

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


class DebtBurnEventModel(EventBaseModel):
"""
Database model for DebtBurn event, inheriting from EventBaseModel.

This model stores the user address and the amount burned.
"""

__tablename__ = "debt_burn_event"

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


class BearingCollateralBurnEventModel(EventBaseModel):
"""
Database model for BearingCollateralBurn event, inheriting from EventBaseModel.

This model stores the user address and the amount burned.
"""

__tablename__ = "bearing_collateral_burn_event"

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


class DebtTransferEventModel(EventBaseModel):
"""
Database model for DebtTransfer event, inheriting from EventBaseModel.

This model stores the sender address, recipient address, and the transfer amount.
"""

__tablename__ = "debt_transfer_event"

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

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
"""migration for BearingCollateralBurnEventModel and DebtTransferEventModel

Revision ID: 163f616930fb
Revises: d3691f6e8c5a
Create Date: 2024-11-25 15:42:21.851978

"""
from typing import Sequence, Union

from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision: str = '163f616930fb'
down_revision: Union[str, None] = 'd3691f6e8c5a'
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None


def upgrade() -> None:
# ### commands auto generated by Alembic - please adjust! ###
op.create_table('bearing_collateral_burn_event',
sa.Column('user', sa.String(), nullable=False),
sa.Column('amount', sa.Numeric(precision=38, scale=18), nullable=False),
sa.Column('event_name', sa.String(), nullable=False),
sa.Column('block_number', sa.Integer(), nullable=False),
sa.Column('protocol_id', sqlalchemy_utils.types.choice.ChoiceType(), nullable=False),
sa.Column('id', sa.UUID(), nullable=False),
sa.PrimaryKeyConstraint('id')
)
op.create_index(op.f('ix_bearing_collateral_burn_event_block_number'), 'bearing_collateral_burn_event', ['block_number'], unique=False)
op.create_index(op.f('ix_bearing_collateral_burn_event_event_name'), 'bearing_collateral_burn_event', ['event_name'], unique=False)
op.create_table('debt_burn_event',
sa.Column('user', sa.String(), nullable=False),
sa.Column('amount', sa.Numeric(precision=38, scale=18), nullable=False),
sa.Column('event_name', sa.String(), nullable=False),
sa.Column('block_number', sa.Integer(), nullable=False),
sa.Column('protocol_id', sqlalchemy_utils.types.choice.ChoiceType(), nullable=False),
sa.Column('id', sa.UUID(), nullable=False),
sa.PrimaryKeyConstraint('id')
)
op.create_index(op.f('ix_debt_burn_event_block_number'), 'debt_burn_event', ['block_number'], unique=False)
op.create_index(op.f('ix_debt_burn_event_event_name'), 'debt_burn_event', ['event_name'], unique=False)
op.create_table('debt_mint_event',
sa.Column('user', sa.String(), nullable=False),
sa.Column('amount', sa.Numeric(precision=38, scale=18), nullable=False),
sa.Column('event_name', sa.String(), nullable=False),
sa.Column('block_number', sa.Integer(), nullable=False),
sa.Column('protocol_id', sqlalchemy_utils.types.choice.ChoiceType(), nullable=False),
sa.Column('id', sa.UUID(), nullable=False),
sa.PrimaryKeyConstraint('id')
)
op.create_index(op.f('ix_debt_mint_event_block_number'), 'debt_mint_event', ['block_number'], unique=False)
op.create_index(op.f('ix_debt_mint_event_event_name'), 'debt_mint_event', ['event_name'], unique=False)
op.create_table('debt_transfer_event',
sa.Column('sender', sa.String(), nullable=False),
sa.Column('recipient', sa.String(), nullable=False),
sa.Column('amount', sa.Numeric(precision=38, scale=18), nullable=False),
sa.Column('event_name', sa.String(), nullable=False),
sa.Column('block_number', sa.Integer(), nullable=False),
sa.Column('protocol_id', sqlalchemy_utils.types.choice.ChoiceType(), nullable=False),
sa.Column('id', sa.UUID(), nullable=False),
sa.PrimaryKeyConstraint('id')
)
op.create_index(op.f('ix_debt_transfer_event_block_number'), 'debt_transfer_event', ['block_number'], unique=False)
op.create_index(op.f('ix_debt_transfer_event_event_name'), 'debt_transfer_event', ['event_name'], unique=False)
# ### end Alembic commands ###


def downgrade() -> None:
# ### commands auto generated by Alembic - please adjust! ###
op.drop_index(op.f('ix_debt_transfer_event_event_name'), table_name='debt_transfer_event')
op.drop_index(op.f('ix_debt_transfer_event_block_number'), table_name='debt_transfer_event')
op.drop_table('debt_transfer_event')
op.drop_index(op.f('ix_debt_mint_event_event_name'), table_name='debt_mint_event')
op.drop_index(op.f('ix_debt_mint_event_block_number'), table_name='debt_mint_event')
op.drop_table('debt_mint_event')
op.drop_index(op.f('ix_debt_burn_event_event_name'), table_name='debt_burn_event')
op.drop_index(op.f('ix_debt_burn_event_block_number'), table_name='debt_burn_event')
op.drop_table('debt_burn_event')
op.drop_index(op.f('ix_bearing_collateral_burn_event_event_name'), table_name='bearing_collateral_burn_event')
op.drop_index(op.f('ix_bearing_collateral_burn_event_block_number'), table_name='bearing_collateral_burn_event')
op.drop_table('bearing_collateral_burn_event')
# ### end Alembic commands ###