1
Fork 0
mirror of https://github.com/pds-nest/nest.git synced 2024-11-23 05:24:18 +00:00
pds-2021-g2-nest/code/backend/nest_backend/database/tables/Repository.py
Lorenzo Balugani 6e4bb34a1b Add API repository functions
Now an user can create, edit, list, add conditions, start and stop a repository.
2021-04-25 16:33:12 +02:00

25 lines
1 KiB
Python

"""
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)
start = Base.Column(Base.DateTime, nullable=True)
end = Base.Column(Base.DateTime, nullable=True)
isActive = Base.Column(Base.Boolean, nullable=False, default=False)
# 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")
alerts = Base.relationship("Alert", back_populates="repository")
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()}