Implement BaseModel class, TimestampMixin, TzDateTime type; cleanup Task model
This commit is contained in:
parent
7ce43a2bfe
commit
252c15acbd
15 changed files with 223 additions and 42 deletions
23
tofu_api/common/database/mixins.py
Normal file
23
tofu_api/common/database/mixins.py
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
from datetime import datetime
|
||||
|
||||
from sqlalchemy import Column, func
|
||||
from sqlalchemy.orm import declarative_mixin
|
||||
|
||||
from tofu_api.common.database import Col
|
||||
from tofu_api.common.database.types import TzDateTime
|
||||
|
||||
__all__ = [
|
||||
'TimestampMixin'
|
||||
]
|
||||
|
||||
|
||||
@declarative_mixin
|
||||
class TimestampMixin:
|
||||
"""
|
||||
Mixin for database models that provides the "created_at" and "modified_at" columns.
|
||||
"""
|
||||
# Created timestamp (automatically set to NOW() once on object creation)
|
||||
created_at: Col[datetime] = Column(TzDateTime, nullable=False, server_default=func.now())
|
||||
|
||||
# Modified timestamp (automatically set to NOW() on each update)
|
||||
modified_at: Col[datetime] = Column(TzDateTime, nullable=False, server_default=func.now(), onupdate=func.now())
|
||||
Loading…
Add table
Add a link
Reference in a new issue