From e04c1bc54dfdc9e0e8eb622c103b2bb8f41c69a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20=C5=BBelazko?= Date: Tue, 26 Mar 2024 13:02:26 +0100 Subject: [PATCH] feature: use default value for created_at field in db entities --- backend/app/infrastructure/database/allocations.py | 6 ------ backend/app/infrastructure/database/models.py | 4 ++-- 2 files changed, 2 insertions(+), 8 deletions(-) diff --git a/backend/app/infrastructure/database/allocations.py b/backend/app/infrastructure/database/allocations.py index d95273e35e..d3e3afc089 100644 --- a/backend/app/infrastructure/database/allocations.py +++ b/backend/app/infrastructure/database/allocations.py @@ -155,8 +155,6 @@ def get_user_alloc_sum_by_epoch(epoch: int, user_address: str) -> int: def store_allocation_request( user_address: str, epoch_num: int, request: UserAllocationRequestPayload, **kwargs ): - now = datetime.utcnow() - user: User = get_by_address(user_address) options = {"is_manually_edited": None, **kwargs} @@ -168,7 +166,6 @@ def store_allocation_request( nonce=request.payload.nonce, proposal_address=to_checksum_address(a.proposal_address), amount=str(a.amount), - created_at=now, ) for a in request.payload.allocations ] @@ -187,8 +184,6 @@ def store_allocation_request( @deprecated("Alloc rework") def add_all(epoch: int, user_id: int, nonce: int, allocations): - now = datetime.utcnow() - new_allocations = [ Allocation( epoch=epoch, @@ -196,7 +191,6 @@ def add_all(epoch: int, user_id: int, nonce: int, allocations): nonce=nonce, proposal_address=to_checksum_address(a.proposal_address), amount=str(a.amount), - created_at=now, ) for a in allocations ] diff --git a/backend/app/infrastructure/database/models.py b/backend/app/infrastructure/database/models.py index 85f770987d..742e8e9669 100644 --- a/backend/app/infrastructure/database/models.py +++ b/backend/app/infrastructure/database/models.py @@ -1,7 +1,7 @@ -from datetime import datetime as dt from typing import Optional from app.extensions import db +from app.modules.common import time # Alias common SQLAlchemy names Column = db.Column @@ -12,7 +12,7 @@ class BaseModel(Model): __abstract__ = True - created_at = Column(db.TIMESTAMP, default=dt.utcnow) + created_at = Column(db.TIMESTAMP, default=lambda: time.now().datetime()) class User(BaseModel):