class User(Model, ModelMixin): __tablename__ = "users" email = Column(Text, index=True, nullable=False, unique=True) _password = Column(Text, nullable=True) name = Column(Text) activation_code = Column(Text, nullable=True) is_superadmin = Column(Boolean, default=False) is_active = Column(Boolean, default=False) group_id = Column(PortableUUID(), ForeignKey("groups.id"), index=True) dashboards = relationship("Dashboard") owned_projects = relationship("Project", backref="owner") tokens = relationship("Token", backref="user") projects = relationship("Project", secondary=users_projects, backref=backref("users", lazy="subquery")) @hybrid_property def password(self): return self._password @password.setter def password(self, value): self._password = bcrypt.generate_password_hash(value).decode("utf8") def check_password(self, plaintext): return bcrypt.check_password_hash(self.password, plaintext) def to_dict(self, with_projects=False): """An overridden method to include projects""" user_dict = super().to_dict() if with_projects: user_dict["projects"] = [ project.to_dict() for project in self.projects ] return user_dict
class Run(Model, ModelMixin): __tablename__ = "runs" artifacts = relationship("Artifact") component = Column(Text, index=True) created = Column(DateTime, default=datetime.utcnow, index=True) # this is metadata but it is a reserved attr data = Column(mutable_json_type(dbtype=PortableJSON(), nested=True)) duration = Column(Float, index=True) env = Column(Text, index=True) project_id = Column(PortableUUID(), ForeignKey("projects.id"), index=True) results = relationship("Result") source = Column(Text, index=True) start_time = Column(DateTime, default=datetime.utcnow, index=True) summary = Column(mutable_json_type(dbtype=PortableJSON())) artifacts = relationship("Artifact", backref="run")
class Import(Model, ModelMixin): __tablename__ = "imports" file = relationship("ImportFile") filename = Column(Text, index=True) format = Column(Text, index=True) data = Column(mutable_json_type(dbtype=PortableJSON(), nested=True)) status = Column(Text, index=True)
class Dashboard(Model, ModelMixin): __tablename__ = "dashboards" title = Column(Text, index=True) description = Column(Text, default="") filters = Column(Text, default="") project_id = Column(PortableUUID(), ForeignKey("projects.id"), index=True) user_id = Column(PortableUUID(), ForeignKey("users.id"), index=True) widgets = relationship("WidgetConfig")
class Project(Model, ModelMixin): __tablename__ = "projects" name = Column(Text, index=True) title = Column(Text, index=True) owner_id = Column(PortableUUID(), ForeignKey("users.id"), index=True) group_id = Column(PortableUUID(), ForeignKey("groups.id"), index=True) reports = relationship("Report") results = relationship("Result", backref="project") runs = relationship("Run", backref="project") dashboards = relationship("Dashboard", backref="project") widget_configs = relationship("WidgetConfig", backref="project") def to_dict(self, with_owner=False): """An overridden method to include the owner""" project_dict = super().to_dict() if with_owner and self.owner: project_dict["owner"] = self.owner.to_dict() return project_dict
class Report(Model, ModelMixin): __tablename__ = "reports" created = Column(DateTime, default=datetime.utcnow, index=True) download_url = Column(Text, index=True) filename = Column(Text, index=True) mimetype = Column(Text, index=True) name = Column(Text, index=True) params = Column(mutable_json_type(dbtype=PortableJSON())) project_id = Column(PortableUUID(), ForeignKey("projects.id"), index=True) file = relationship("ReportFile") status = Column(Text, index=True) url = Column(Text, index=True) view_url = Column(Text, index=True)
class Group(Model, ModelMixin): __tablename__ = "groups" name = Column(Text, index=True) projects = relationship("Project") data = Column(mutable_json_type(dbtype=PortableJSON(), nested=True))