modify db schema
This commit is contained in:
parent
892c929c35
commit
33a0b1d8be
|
@ -2,12 +2,11 @@ from orm.rbac import Organization, Operation, Resource, Permission, Role
|
|||
from orm.user import User
|
||||
from orm.message import Message
|
||||
from orm.topic import Topic
|
||||
from orm.rating import Rating
|
||||
from orm.notification import Notification
|
||||
from orm.shout import Shout
|
||||
from orm.base import Base, engine
|
||||
|
||||
__all__ = ["User", "Role", "Operation", "Permission", "Message", "Shout", "Topic", "Rating", "Notification"]
|
||||
__all__ = ["User", "Role", "Operation", "Permission", "Message", "Shout", "Topic", "Notification"]
|
||||
|
||||
Base.metadata.create_all(engine)
|
||||
Operation.init_table()
|
||||
|
|
12
orm/like.py
12
orm/like.py
|
@ -7,11 +7,11 @@ from orm.base import Base
|
|||
|
||||
|
||||
class Like(Base):
|
||||
__tablename__ = 'like'
|
||||
__tablename__ = 'like'
|
||||
|
||||
author_id: str = Column(ForeignKey("user.id"), nullable=False, comment="Author")
|
||||
value: str = Column(String, nullable=False, comment="Value")
|
||||
shout: str = Column(String, ForeignKey("shout.slug"), nullable=True, comment="Liked shout slug")
|
||||
user: str = Column(ForeignKey("user.id"), nullable=True, comment="Liked user")
|
||||
id: int = None
|
||||
user_id: str = Column(ForeignKey("user.id"), comment="Author", primary_key = True)
|
||||
shout: str = Column(String, ForeignKey("shout.slug"), comment="Liked shout slug", primary_key = True)
|
||||
value: int = Column(Integer, nullable=False, comment="Value")
|
||||
|
||||
# TODO: add resolvers, debug, etc.
|
||||
# TODO: add resolvers, debug, etc.
|
||||
|
|
|
@ -1,9 +1,3 @@
|
|||
from sqlalchemy import Column, Integer, String, ForeignKey
|
||||
# from orm import Permission
|
||||
from orm.base import Base
|
||||
|
||||
class Rating(Base):
|
||||
__tablename__ = "rating"
|
||||
|
||||
createdBy: int = Column(Integer, ForeignKey("user.id"), primary_key = True)
|
||||
value: int = Column(Integer, nullable=False)
|
||||
|
|
|
@ -17,6 +17,7 @@ Connection = Table('topic_connections',
|
|||
class Topic(Base):
|
||||
__tablename__ = 'topic'
|
||||
|
||||
id: int = None
|
||||
slug: str = Column(String, unique = True, nullable = False, primary_key=True)
|
||||
org_id: str = Column(ForeignKey("organization.id"), nullable=False)
|
||||
createdAt: str = Column(DateTime, nullable=False, default = datetime.now, comment="Created at")
|
||||
|
|
15
orm/user.py
15
orm/user.py
|
@ -5,7 +5,6 @@ from sqlalchemy.orm import relationship
|
|||
|
||||
from orm import Permission
|
||||
from orm.base import Base, local_session
|
||||
from orm.rating import Rating
|
||||
from orm.rbac import Role
|
||||
|
||||
class UserNotifications(Base):
|
||||
|
@ -16,11 +15,13 @@ class UserNotifications(Base):
|
|||
kind: str = Column(String, ForeignKey("notification.kind"))
|
||||
values: JSONType = Column(JSONType, nullable = True) # [ <var1>, .. ]
|
||||
|
||||
UserRatings = Table("user_ratings",
|
||||
Base.metadata,
|
||||
Column('user_id', Integer, ForeignKey('user.id')),
|
||||
Column('rater_id', Integer, ForeignKey('rating.createdBy'))
|
||||
)
|
||||
class UserRatings(Base):
|
||||
__tablename__ = "user_ratings"
|
||||
|
||||
id = None
|
||||
rater_id = Column(ForeignKey('user.id'), primary_key = True)
|
||||
user_id = Column(ForeignKey('user.id'), primary_key = True)
|
||||
value = Column(Integer)
|
||||
|
||||
UserRoles = Table("user_roles",
|
||||
Base.metadata,
|
||||
|
@ -46,7 +47,7 @@ class User(Base):
|
|||
links: JSONType = Column(JSONType, nullable=True, comment="Links")
|
||||
oauth: str = Column(String, nullable=True)
|
||||
notifications = relationship(lambda: UserNotifications)
|
||||
ratings = relationship(lambda: Rating, secondary=UserRatings)
|
||||
ratings = relationship(UserRatings, foreign_keys=UserRatings.user_id)
|
||||
roles = relationship(lambda: Role, secondary=UserRoles)
|
||||
|
||||
@classmethod
|
||||
|
|
Loading…
Reference in New Issue
Block a user