2021-04-21 16:47:18 +00:00
|
|
|
"""
|
|
|
|
This module defines the Repository database class.
|
|
|
|
"""
|
|
|
|
|
|
|
|
from ..base import Base
|
|
|
|
|
|
|
|
|
|
|
|
class Repository(Base.Model):
|
|
|
|
__tablename__ = "repository"
|
|
|
|
id = Base.Column(Base.Integer, primary_key=True)
|
|
|
|
name = Base.Column(Base.String, nullable=False)
|
2021-04-25 14:33:12 +00:00
|
|
|
start = Base.Column(Base.DateTime, nullable=True)
|
2021-04-25 13:41:27 +00:00
|
|
|
end = Base.Column(Base.DateTime, nullable=True)
|
2021-04-25 14:33:12 +00:00
|
|
|
isActive = Base.Column(Base.Boolean, nullable=False, default=False)
|
2021-04-21 16:47:18 +00:00
|
|
|
# Foreign Keys
|
|
|
|
owner_id = Base.Column(Base.String, Base.ForeignKey("user.email"), nullable=False)
|
|
|
|
# Relationships
|
|
|
|
owner = Base.relationship("User", back_populates="owner_of")
|
|
|
|
authorizations = Base.relationship("Authorization", back_populates="repository")
|
|
|
|
tweets = Base.relationship("Composed", back_populates="repository")
|
2021-04-22 14:54:27 +00:00
|
|
|
alerts = Base.relationship("Alert", back_populates="repository")
|
2021-04-25 13:41:27 +00:00
|
|
|
uses = Base.relationship("Uses", back_populates="repository")
|
|
|
|
|
|
|
|
def to_json(self):
|
|
|
|
return {"id": self.id, "name": self.name, "start": self.start.isoformat(), "owner": self.owner.to_json()}
|