Skip to content

Commit

Permalink
feature: use default value for created_at field in db entities
Browse files Browse the repository at this point in the history
  • Loading branch information
pik694 committed Mar 27, 2024
1 parent b2fbf24 commit e04c1bc
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 8 deletions.
6 changes: 0 additions & 6 deletions backend/app/infrastructure/database/allocations.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand All @@ -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
]
Expand All @@ -187,16 +184,13 @@ 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,
user_id=user_id,
nonce=nonce,
proposal_address=to_checksum_address(a.proposal_address),
amount=str(a.amount),
created_at=now,
)
for a in allocations
]
Expand Down
4 changes: 2 additions & 2 deletions backend/app/infrastructure/database/models.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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):
Expand Down

0 comments on commit e04c1bc

Please sign in to comment.