user model upgrade, rating, notificaiton
This commit is contained in:
17
orm/notification.py
Normal file
17
orm/notification.py
Normal file
@@ -0,0 +1,17 @@
|
||||
from sqlalchemy import Column, Integer, String, ForeignKey, JSON as JSONType
|
||||
from orm.base import Base
|
||||
|
||||
class Notification(Base):
|
||||
__tablename__ = 'notification'
|
||||
|
||||
kind: str = Column(String, primary_key = True)
|
||||
template: str = Column(String, nullable = False)
|
||||
variables: JSONType = Column(JSONType, nullable = True) # [ <var1>, .. ]
|
||||
|
||||
class UserNotification(Base):
|
||||
__tablename__ = 'user_notification'
|
||||
|
||||
id: int = Column(Integer, primary_key = True)
|
||||
user: int = Column(ForeignKey("user.id"))
|
||||
kind: int = Column(ForeignKey("notification.kind"), nullable = False)
|
||||
values: JSONType = Column(JSONType, nullable = True) # [ <var1>, .. ]
|
10
orm/rating.py
Normal file
10
orm/rating.py
Normal file
@@ -0,0 +1,10 @@
|
||||
|
||||
from sqlalchemy import Column, Integer, String, ForeignKey
|
||||
from orm.base import Base
|
||||
|
||||
class Rating(Base):
|
||||
__tablename__ = 'rating'
|
||||
|
||||
id: int = Column(Integer, primary_key = True)
|
||||
createdBy: int = Column(ForeignKey("user.id"), primary_key = True)
|
||||
value: int = Column(Integer, nullable=False)
|
@@ -21,5 +21,6 @@ class Shout(Base):
|
||||
versionOf: str = Column(ForeignKey("shout.slug"), nullable=True)
|
||||
tags: str = Column(String, nullable=True)
|
||||
topics: str = Column(String, nullable=True)
|
||||
views: int = Column(Integer, default=0)
|
||||
|
||||
# TODO: add all the fields
|
||||
|
29
orm/user.py
29
orm/user.py
@@ -1,28 +1,39 @@
|
||||
from typing import List
|
||||
|
||||
from sqlalchemy import Column, Integer, String, ForeignKey
|
||||
from sqlalchemy import Column, Integer, String, ForeignKey, Boolean, DateTime
|
||||
from sqlalchemy.orm import relationship
|
||||
|
||||
from orm import Permission
|
||||
from orm.base import Base, local_session
|
||||
|
||||
from orm.rating import Rating
|
||||
from orm.notification import UserNotification
|
||||
|
||||
class UserRole(Base):
|
||||
__tablename__ = 'user_role'
|
||||
|
||||
id = None
|
||||
id: int = Column(Integer, primary_key = True)
|
||||
user_id: int = Column(ForeignKey("user.id"), primary_key = True)
|
||||
role_id: int = Column(ForeignKey("role.id"), primary_key = True)
|
||||
role: str = Column(ForeignKey("role.name"), primary_key = True)
|
||||
|
||||
class User(Base):
|
||||
__tablename__ = 'user'
|
||||
|
||||
email: str = Column(String, unique=True, nullable=False)
|
||||
username: str = Column(String, nullable=False, comment="Name")
|
||||
email: str = Column(String, unique=True, nullable=False, comment="Email")
|
||||
username: str = Column(String, nullable=False, comment="Login")
|
||||
password: str = Column(String, nullable=True, comment="Password")
|
||||
|
||||
oauth_id: str = Column(String, nullable=True)
|
||||
|
||||
bio: str = Column(String, nullable=True, comment="Bio")
|
||||
userpic: str = Column(String, nullable=True, comment="Userpic")
|
||||
viewname: str = Column(String, nullable=True, comment="Display name")
|
||||
rating: int = Column(Integer, nullable=True, comment="Rating")
|
||||
slug: str = Column(String, unique=True, nullable=True, comment="Slug")
|
||||
muted: bool = Column(Boolean, default=False)
|
||||
emailConfirmed: bool = Column(Boolean, default=False)
|
||||
createdAt: DateTime = Column(DateTime, nullable=False, comment="Created at")
|
||||
wasOnlineAt: DateTime = Column(DateTime, nullable=False, comment="Was online at")
|
||||
links: JSON = Column(JSON, nullable=True, comment="Links")
|
||||
oauth: str = Column(String, nullable=True)
|
||||
notifications = relationship("Notification", secondary=UserNotification.__table__)
|
||||
ratings = relationship("Rating", secondary=Rating.__table__)
|
||||
roles = relationship("Role", secondary=UserRole.__table__)
|
||||
|
||||
@classmethod
|
||||
|
Reference in New Issue
Block a user