Skip to content

Commit 3873acb

Browse files
authored
Merge pull request #600 from zimaexe/feat/fix_migrations
fixed migrations
2 parents 5833d52 + 41a80a6 commit 3873acb

File tree

5 files changed

+63
-52
lines changed

5 files changed

+63
-52
lines changed

apps/data_handler/Dockerfile

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
FROM python:3.11
22

3-
WORKDIR /code
3+
WORKDIR /app
44

5-
COPY data_handler/poetry.lock data_handler/pyproject.toml /code/
6-
COPY data_handler/entrypoint.sh /code/entrypoint.sh
5+
COPY data_handler/poetry.lock data_handler/pyproject.toml /app/
6+
COPY data_handler/entrypoint.sh /app/entrypoint.sh
77

88
RUN curl -sSL https://install.python-poetry.org | POETRY_HOME=/usr/local/ POETRY_VERSION=1.8.3 python3 -\
99
&& poetry config virtualenvs.create false \
1010
&& poetry install --no-dev
1111

1212
# Adjust build context for folders out of Docker context
1313
# Assuming data_handler and shared are located in the root directory, set the context to root
14-
COPY shared /code/shared
15-
COPY data_handler /code/data_handler
14+
COPY shared /app/shared
15+
COPY data_handler /app/data_handler
1616

17-
ENTRYPOINT ["bash", "/code/entrypoint.sh"]
17+
ENTRYPOINT ["bash", "/app/data_handler/entrypoint.sh"]

apps/data_handler/db/models/vesu.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
from sqlalchemy import BigInteger, Column, String
22
from sqlalchemy.ext.declarative import declarative_base
3-
4-
Base = declarative_base()
3+
from data_handler.db.models.base import Base
54

65

76
class VesuPosition(Base):

apps/data_handler/handlers/loan_states/vesu/events.py

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
calculate collateral and debt values, and determine health factors for users.
55
"""
66

7+
from datetime import datetime
78
from decimal import Decimal
89

910
from sqlalchemy import select
@@ -29,7 +30,7 @@ def __init__(self):
2930
"""Initialize Starknet client and storage."""
3031
self.client = StarknetClient()
3132
self.db_connector = DBConnector()
32-
self.session = self.db_connector.Session()
33+
self.session = self.db_connector.Session
3334
self._cache = {}
3435
self.last_processed_block = 654244 # First VESU event block
3536

@@ -47,9 +48,9 @@ async def _get_token_decimals(self, token_address: int) -> Decimal:
4748
decimals = result[0]
4849
return Decimal(10) ** Decimal(decimals)
4950
return Decimal("Inf")
50-
51+
5152
async def save_health_ratio_level(
52-
self, session, timestamp, user_id, value, protocol_id
53+
self, timestamp, user_id, value, protocol_id
5354
):
5455
"""Save a HealthRatioLevel record to the DB."""
5556
record = HealthRatioLevel(
@@ -58,19 +59,19 @@ async def save_health_ratio_level(
5859
value=value,
5960
protocol_id=protocol_id,
6061
)
61-
session.add(record)
62-
await session.commit()
63-
await session.refresh(record)
62+
self.session.add(record)
63+
self.session.commit()
64+
self.session.refresh(record)
6465
return record
6566

66-
async def calculate_health_factor(self, user_address: int, session=None) -> dict[str, Decimal]:
67+
async def calculate_health_factor(self, user_address: int) -> dict[str, Decimal]:
6768
"""
6869
Calculate health factors for all positions of a user.
6970
7071
:param user_address: User address in int format
7172
:return: Dictionary with pool IDs (in hex) as keys and health factors as values
7273
"""
73-
result = await self.session.execute(
74+
result = self.session.execute(
7475
select(VesuPosition).where(VesuPosition.user == str(user_address))
7576
)
7677
positions = result.scalars().all()
@@ -144,13 +145,12 @@ async def calculate_health_factor(self, user_address: int, session=None) -> dict
144145

145146
results[hex(pool_id)] = health_factor
146147

147-
if session is not None:
148-
await self.save_health_ratio_level(
149-
session=session,
150-
timestamp=pos.get("block_number", 0),
148+
await self.save_health_ratio_level(
149+
# session=self.session,
150+
timestamp=datetime.now().timestamp(),
151151
user_id=str(user_address),
152152
value=health_factor,
153-
protocol_id=pool_id,
153+
protocol_id="Vesu",
154154
)
155155

156156
return results
@@ -395,4 +395,4 @@ async def update_positions_data(self) -> None:
395395

396396
self.last_processed_block = max(self.last_processed_block, block_number)
397397

398-
await self.session.commit()
398+
self.session.commit()
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
"""new tables, vesu support
2+
3+
Revision ID: 227cd0abde09
4+
Revises: 0003f938152d
5+
Create Date: 2025-06-09 20:49:57.071381
6+
7+
"""
8+
from typing import Sequence, Union
9+
10+
from alembic import op
11+
import sqlalchemy as sa
12+
13+
14+
# revision identifiers, used by Alembic.
15+
revision: str = '227cd0abde09'
16+
down_revision: Union[str, None] = '0003f938152d'
17+
branch_labels: Union[str, Sequence[str], None] = None
18+
depends_on: Union[str, Sequence[str], None] = None
19+
20+
21+
def upgrade() -> None:
22+
# ### commands auto generated by Alembic - please adjust! ###
23+
op.create_table('vesu_positions',
24+
sa.Column('id', sa.BigInteger(), autoincrement=True, nullable=False),
25+
sa.Column('user', sa.String(), nullable=True),
26+
sa.Column('pool_id', sa.String(), nullable=True),
27+
sa.Column('collateral_asset', sa.String(), nullable=True),
28+
sa.Column('debt_asset', sa.String(), nullable=True),
29+
sa.Column('block_number', sa.BigInteger(), nullable=True),
30+
sa.PrimaryKeyConstraint('id')
31+
)
32+
op.create_index(op.f('ix_vesu_positions_pool_id'), 'vesu_positions', ['pool_id'], unique=False)
33+
op.create_index(op.f('ix_vesu_positions_user'), 'vesu_positions', ['user'], unique=False)
34+
# ### end Alembic commands ###
35+
36+
37+
def downgrade() -> None:
38+
# ### commands auto generated by Alembic - please adjust! ###
39+
op.drop_index(op.f('ix_vesu_positions_user'), table_name='vesu_positions')
40+
op.drop_index(op.f('ix_vesu_positions_pool_id'), table_name='vesu_positions')
41+
op.drop_table('vesu_positions')
42+
# ### end Alembic commands ###

apps/data_handler/migrations/versions/eca9b6bc75e9_add_vesu_protocol_support_to_enum_.py

Lines changed: 0 additions & 30 deletions
This file was deleted.

0 commit comments

Comments
 (0)