Skip to content

Commit

Permalink
Move create at column to base model
Browse files Browse the repository at this point in the history
  • Loading branch information
koldakov committed Jan 4, 2024
1 parent 8d86183 commit 81fc523
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 22 deletions.
11 changes: 10 additions & 1 deletion app/repositories/base.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
from enum import Enum
from typing import List

from sqlalchemy import select
from sqlalchemy import Column, DateTime, select
from sqlalchemy.engine.result import Result
from sqlalchemy.exc import NoResultFound
from sqlalchemy.ext.asyncio.session import AsyncSession
from sqlalchemy.orm import declarative_base
from sqlalchemy.orm.attributes import InstrumentedAttribute
from sqlalchemy.sql import func
from sqlalchemy.sql.elements import UnaryExpression

_Base = declarative_base()
Expand All @@ -30,6 +31,14 @@ class Base[T, U](_Base):
__abstract__ = True
order_by: U = OrderBy

created_at = Column(
DateTime(
timezone=True,
),
server_default=func.now(),
nullable=False,
)

def to_dict(
self,
*,
Expand Down
22 changes: 1 addition & 21 deletions app/repositories/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,13 +127,6 @@ class Season(Base):
primary_key=True,
)

created_at = Column(
DateTime(
timezone=True,
),
server_default=func.now(),
nullable=False,
)
uuid = Column(
COLUMN_UUID(
as_uuid=True,
Expand Down Expand Up @@ -175,6 +168,7 @@ class SeasonDoesNotExist(ModelDoesNotExist):
class EpisodeCharacterAssociation(Base):
__tablename__ = "episode_character_association"

created_at = None
episode_id: Mapped[int] = mapped_column(
ForeignKey("episodes.id"),
primary_key=True,
Expand All @@ -196,13 +190,6 @@ class Episode(Base):
),
nullable=True,
)
created_at = Column(
DateTime(
timezone=True,
),
server_default=func.now(),
nullable=False,
)
uuid = Column(
COLUMN_UUID(
as_uuid=True,
Expand Down Expand Up @@ -291,13 +278,6 @@ class Character(Base):
),
nullable=False,
)
created_at = Column(
DateTime(
timezone=True,
),
server_default=func.now(),
nullable=False,
)
gender = Column(
ENUM(
CharacterGender,
Expand Down

0 comments on commit 81fc523

Please sign in to comment.