Skip to content

Commit

Permalink
chore: update migration to use composite pk on cmc
Browse files Browse the repository at this point in the history
  • Loading branch information
robcxyz committed Oct 30, 2023
1 parent c2a19a1 commit f93a413
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 4 deletions.
9 changes: 6 additions & 3 deletions icon_stats/crons/cmc_cryptocurrency_quotes_latest.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from icon_stats.log import logger
from sqlalchemy.orm import Session
from sqlalchemy.exc import IntegrityError

from icon_stats.utils.times import convert_str_date
from icon_stats.metrics import prom_metrics
Expand All @@ -26,8 +27,10 @@ async def run_cmc_cryptocurrency_quotes_latest():
quote['last_updated'] = convert_str_date(quote['last_updated'])
exchanges_legacy = CmcListingsLatestQuote(base='ICX', quote='USD', **quote)


await upsert_model(db_name='stats', model=exchanges_legacy)
try:
await upsert_model(db_name='stats', model=exchanges_legacy)
except IntegrityError:
logger.info("Duplicate PK - skipping upsert")

prom_metrics.cron_ran.inc()
logger.info("Ending top tokens cron")
logger.info("Ending cmc crypto quotes latest cron")
9 changes: 8 additions & 1 deletion icon_stats/models/cmc_cryptocurrency_quotes_latest.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,14 @@ class CmcListingsLatestQuote(SQLModel, table=True):
market_cap_dominance: float
fully_diluted_market_cap: float
tvl: float | None
last_updated: datetime.datetime = Column(DateTime(timezone=True), primary_key=True)
# last_updated: datetime.datetime = Column(DateTime(timezone=True), primary_key=True)
# last_updated: datetime.datetime = Field(
# sa_column=Column(DateTime(timezone=True), primary_key=True)
# )
last_updated: datetime.datetime = Field(
sa_column=Column(DateTime(timezone=True)),
primary_key=True,
)

__table_args__ = {'schema': 'stats'}

Expand Down
1 change: 1 addition & 0 deletions tests/integration/api/test_api_markets.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
def test_api_get_markets(client: TestClient):
response = client.get(f"{config.API_REST_PREFIX}/stats/exchanges/legacy")
assert response.status_code == 200
assert response.json()['data']['marketCap'] > 10000000


def test_api_get_prep_error(client: TestClient):
Expand Down

0 comments on commit f93a413

Please sign in to comment.