2021-04-21 16:47:18 +00:00
|
|
|
"""
|
2021-04-29 02:02:08 +00:00
|
|
|
This module defines the :class:`.Repository` database class.
|
2021-04-21 16:47:18 +00:00
|
|
|
"""
|
|
|
|
|
|
|
|
from ..base import Base
|
|
|
|
|
|
|
|
|
|
|
|
class Repository(Base.Model):
|
|
|
|
__tablename__ = "repository"
|
2021-04-29 02:02:08 +00:00
|
|
|
|
|
|
|
# Columns
|
2021-04-21 16:47:18 +00:00
|
|
|
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-29 02:02:08 +00:00
|
|
|
|
2021-04-21 16:47:18 +00:00
|
|
|
# Foreign Keys
|
|
|
|
owner_id = Base.Column(Base.String, Base.ForeignKey("user.email"), nullable=False)
|
2021-04-29 02:02:08 +00:00
|
|
|
|
2021-04-21 16:47:18 +00:00
|
|
|
# Relationships
|
|
|
|
owner = Base.relationship("User", back_populates="owner_of")
|
2021-05-01 12:25:50 +00:00
|
|
|
authorizations = Base.relationship("Authorization", back_populates="repository", cascade="all, delete")
|
|
|
|
tweets = Base.relationship("Composed", back_populates="repository", cascade="all, delete")
|
|
|
|
alerts = Base.relationship("Alert", back_populates="repository", cascade="all, delete")
|
|
|
|
uses = Base.relationship("Uses", back_populates="repository", cascade="all, delete")
|
2021-04-25 13:41:27 +00:00
|
|
|
|
|
|
|
def to_json(self):
|
2021-04-29 02:02:08 +00:00
|
|
|
return {
|
|
|
|
"id": self.id,
|
|
|
|
"name": self.name,
|
|
|
|
"start": self.start.isoformat() if self.start else None,
|
|
|
|
"isActive": self.isActive,
|
|
|
|
"end": self.end.isoformat() if self.end else None,
|
|
|
|
"owner": self.owner.to_json()
|
|
|
|
}
|