From 8d7948a067f12d225488441e8519b0bca69ef99f Mon Sep 17 00:00:00 2001 From: devJoe Date: Mon, 25 Nov 2024 14:27:24 +0000 Subject: [PATCH 1/2] feat: Create db models for nostra events --- apps/data_handler/db/models/nostra_events.py | 56 ++++++++++++++++++++ 1 file changed, 56 insertions(+) diff --git a/apps/data_handler/db/models/nostra_events.py b/apps/data_handler/db/models/nostra_events.py index 5e92f0c6..d59eacdc 100644 --- a/apps/data_handler/db/models/nostra_events.py +++ b/apps/data_handler/db/models/nostra_events.py @@ -12,7 +12,63 @@ class DebtMintEventModel(EventBaseModel): """ __tablename__ = "debt_mint_event" +from decimal import Decimal +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) From 726afd01ac5e241abde5af44704840dbea38d512 Mon Sep 17 00:00:00 2001 From: devJoe Date: Mon, 25 Nov 2024 14:56:39 +0000 Subject: [PATCH 2/2] chore: implement migrations --- .../versions/163f616930fb_migration_for_.py | 85 +++++++++++++++++++ 1 file changed, 85 insertions(+) create mode 100644 apps/data_handler/migrations/versions/163f616930fb_migration_for_.py diff --git a/apps/data_handler/migrations/versions/163f616930fb_migration_for_.py b/apps/data_handler/migrations/versions/163f616930fb_migration_for_.py new file mode 100644 index 00000000..77bc0da4 --- /dev/null +++ b/apps/data_handler/migrations/versions/163f616930fb_migration_for_.py @@ -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 ###