comments migration wip

This commit is contained in:
2021-10-12 22:38:12 +03:00
parent 816a90f656
commit 80f4fa1d08
6 changed files with 147 additions and 103 deletions

View File

@@ -7,9 +7,9 @@ from orm.notification import Notification
from orm.shout import Shout, ShoutAuthor, ShoutTopic, ShoutRating, ShoutViewByDay,\
ShoutRatingStorage, ShoutViewStorage
from orm.base import Base, engine, local_session
from orm.comment import Comment
from orm.comment import Comment, CommentRating
__all__ = ["User", "Role", "Operation", "Permission", "Message", "Shout", "Topic", "Notification"]
__all__ = ["User", "Role", "Operation", "Permission", "Message", "Shout", "Topic", "Notification", "ShoutRating", "Comment", "CommentRating"]
Base.metadata.create_all(engine)
Operation.init_table()

View File

@@ -1,7 +1,7 @@
from typing import List
from datetime import datetime
from sqlalchemy import Column, Integer, String, ForeignKey, DateTime
from sqlalchemy import Column, Integer, String, ForeignKey, DateTime, Boolean
from sqlalchemy.orm import relationship
from orm.base import Base
@@ -19,14 +19,16 @@ class Comment(Base):
__tablename__ = 'comment'
author: int = Column(ForeignKey("user.id"), nullable=False, comment="Sender")
body: str = Column(String, nullable=False, comment="Body")
body: str = Column(String, nullable=False, comment="Comment Body")
createdAt = Column(DateTime, nullable=False, default = datetime.now, comment="Created at")
updatedAt = Column(DateTime, nullable=True, comment="Updated at")
deletedAt = Column(DateTime, nullable=True, comment="Deleted at")
deletedBy = Column(ForeignKey("user.id"), nullable=True, comment="Deleted by")
shout: int = Column(ForeignKey("shout.id"), nullable=True, comment="Shout ID")
rating: int = Column(Integer, nullable=True, comment="Comment Rating")
ratings = relationship(CommentRating, foreign_keys=CommentRating.comment_id)
old_id: str = Column(String, nullable = True)
deleted: bool = Column(Boolean, nullable = True)
# TODO: work in progress, udpate this code

View File

@@ -58,6 +58,7 @@ class User(Base):
ratings = relationship(UserRatings, foreign_keys=UserRatings.user_id)
roles = relationship(lambda: Role, secondary=UserRoles)
topics = relationship(lambda: Topic, secondary=UserTopics)
old_id: str = Column(String, nullable = True)
@classmethod
def get_permission(cls, user_id):