Added create_entity
Some checks failed
checks-impure / test (pull_request) Successful in 30s
checks / test (pull_request) Failing after 3h13m7s

This commit is contained in:
2023-11-26 20:54:57 +01:00
parent 80ccaa83d3
commit d1a3a5381a
8 changed files with 200 additions and 128 deletions

View File

@@ -1,23 +1,90 @@
from sqlalchemy import JSON, Column, ForeignKey, Integer
from sqlalchemy import JSON, Boolean, Column, DateTime, ForeignKey, Integer, String
from sqlalchemy.orm import relationship
from .sql_db import Base
# Relationsship example
# https://dev.to/freddiemazzilli/flask-sqlalchemy-relationships-exploring-relationship-associations-igo
class Producer(Base):
class Entity(Base):
__tablename__ = "entities"
## Queryable body ##
did = Column(String, primary_key=True, index=True)
name = Column(String, index=True)
ip = Column(String, index=True)
attached = Column(Boolean, index=True)
## Non queryable body ##
# In here we deposit: Network, Roles, Visible, etc.
other = Column(JSON)
## Relations ##
producers = relationship("Producer", back_populates="entity")
consumers = relationship("Consumer", back_populates="entity")
# repository = relationship("Repository", uselist=False, back_populates="entity")
class ProducerAbstract(Base):
__abstract__ = True
# Queryable body
id = Column(Integer, primary_key=True, index=True)
service_name = Column(String, unique=True, index=True)
service_type = Column(String, index=True)
endpoint_url = Column(String, index=True)
status = Column(String, index=True)
## Non queryable body ##
# In here we deposit: Action
other = Column(JSON)
class Producer(ProducerAbstract):
__tablename__ = "producers"
# Usage is the consumers column
## Relations ##
# One entity can have many producers
entity = relationship("Entity", back_populates="producers")
entity_did = Column(Integer, ForeignKey("entities.did"))
# One producer has many consumers
consumers = relationship("Consumer", back_populates="producer")
class Consumer(Base):
__tablename__ = "consumers"
## Queryable body ##
id = Column(Integer, primary_key=True, index=True)
jsonblob = Column(JSON)
repos = relationship("Repository", back_populates="producer")
## Relations ##
# one entity can have many consumers
entity = relationship("Entity", back_populates="consumers")
entity_did = Column(Integer, ForeignKey("entities.did"))
# one consumer has one producer
producer = relationship("Producer", back_populates="consumers")
producer_id = Column(Integer, ForeignKey("producers.id"))
class Repository(Base):
__tablename__ = "repositories"
# class Repository(ProducerAbstract):
# __tablename__ = "repositories"
id = Column(Integer, primary_key=True, index=True)
jsonblob = Column(JSON)
prod_id = Column(Integer, ForeignKey("producers.id"))
# # one repository has one entity
# entity = relationship("Entity", back_populates="repository")
# entity_did = Column(Integer, ForeignKey("entities.did"))
producer = relationship("Producer", back_populates="repos")
# TODO: Ask how this works exactly
class Resolution(Base):
__tablename__ = "resolutions"
id = Column(Integer, primary_key=True)
requester_name = Column(String, index=True)
requester_did = Column(String, index=True)
resolved_did = Column(String, index=True)
timestamp = Column(DateTime, index=True)