class Team(db.Model): id = db.Column(db.Integer, primary_key=True) title = db.Column(db.String(64)) desc = db.Column(db.String(256)) owner_id = db.Column(db.Integer, db.ForeignKey('user.id')) users = db.relationship("TeamUserRelationship", backref="team", lazy='dynamic')
class Article(db.Model): # 设计成可以分段加载的,一次性把所有的text_node加载进来按时间排序 # 题目限制 60 个汉字,120 个字符 # 一段文章的限制为 10000 个汉字 id = db.Column(db.Integer, primary_key=True) owner_id = db.Column(db.Integer, db.ForeignKey('user.id')) title = db.Column(db.String(128)) text_nodes = db.relationship("TextNode", backref="article", lazy='dynamic') delete = db.Column(db.Boolean, default=False) visitor_count = db.Column(db.Integer, default=0) created_at = db.Column(db.Integer, default=time.time) modified_at = db.Column(db.Integer, default=time.time, onupdate=time.time)
class Message(db.Model): id = db.Column(db.Integer, primary_key=True) type = db.Column( db.SmallInteger, default=MessageType.NORMAL) # normal, yes_or_no, must_reply reply_message_id = db.Column(db.Integer, default=0) # None if no one to reply from_user_id = db.Column(db.Integer, nullable=False) message_batch_id = db.Column(db.Integer, db.ForeignKey('message_batch.id')) context = db.Column(db.String(2048), default='') readed = db.Column(db.Boolean, default=False) created_at = db.Column(db.Integer, default=time.time)
class Image(db.Model): id = db.Column(db.Integer, primary_key=True) title = db.Column(db.String(128)) uri = db.Column(db.String(128)) state = db.Column(db.SmallInteger, default=ImageState.WAIT_LABEL) freeze = db.Column(db.Boolean, default=False) delete = db.Column(db.Boolean, default=False) users = db.relationship("ImageUserRelationship", backref="image", lazy='dynamic') alg_id = db.Column(db.Integer, db.ForeignKey('alg.id')) @property def store_uri(self): return self.uri + '.raw'
class AlgUserRelationship(db.Model): # 因为设计上有些东西没有想明白,比如如果某一个管理员删除了一个算法后 id = db.Column(db.Integer, primary_key=True) user_id = db.Column(db.Integer, db.ForeignKey('user.id')) alg_id = db.Column(db.Integer, db.ForeignKey('alg.id'))
class ImageUserRelationship(db.Model): id = db.Column(db.Integer, primary_key=True) image_id = db.Column(db.Integer, db.ForeignKey('image.id')) user_id = db.Column(db.Integer, db.ForeignKey('user.id')) isOwner = db.Column(db.Boolean, nullable=False, default=False)
class TeamUserRelationship(db.Model): id = db.Column(db.Integer, primary_key=True) team_id = db.Column(db.Integer, db.ForeignKey('team.id')) user_id = db.Column(db.Integer, db.ForeignKey('user.id')) isLeader = db.Column(db.Boolean, nullable=False, default=False)
class TextNode(db.Model): # 一段文章的限制为 10000 个汉字 id = db.Column(db.Integer, primary_key=True) context = db.Column(db.String(2048)) created_at = db.Column(db.Integer, default=time.time) article_id = db.Column(db.Integer, db.ForeignKey('article.id'))