generated from Luis/nextjs-python-web-template
Fully working schemas and database, with api endpoints. two missing.
This commit is contained in:
@@ -1,5 +1,16 @@
|
||||
from sqlalchemy import JSON, Boolean, Column, DateTime, ForeignKey, Integer, String
|
||||
from sqlalchemy import (
|
||||
JSON,
|
||||
Boolean,
|
||||
Column,
|
||||
DateTime,
|
||||
ForeignKey,
|
||||
Integer,
|
||||
String,
|
||||
Text,
|
||||
UniqueConstraint,
|
||||
)
|
||||
from sqlalchemy.orm import relationship
|
||||
from sqlalchemy.sql import func
|
||||
|
||||
from .sql_db import Base
|
||||
|
||||
@@ -23,15 +34,15 @@ class Entity(Base):
|
||||
## Relations ##
|
||||
producers = relationship("Producer", back_populates="entity")
|
||||
consumers = relationship("Consumer", back_populates="entity")
|
||||
# repository = relationship("Repository", uselist=False, 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)
|
||||
uuid = Column(Text(length=36), primary_key=True, index=True)
|
||||
service_name = Column(String, index=True)
|
||||
service_type = Column(String, index=True)
|
||||
endpoint_url = Column(String, index=True)
|
||||
status = Column(String, index=True)
|
||||
@@ -49,7 +60,7 @@ class Producer(ProducerAbstract):
|
||||
## Relations ##
|
||||
# One entity can have many producers
|
||||
entity = relationship("Entity", back_populates="producers")
|
||||
entity_did = Column(Integer, ForeignKey("entities.did"))
|
||||
entity_did = Column(String, ForeignKey("entities.did"))
|
||||
|
||||
# One producer has many consumers
|
||||
consumers = relationship("Consumer", back_populates="producer")
|
||||
@@ -61,22 +72,29 @@ class Consumer(Base):
|
||||
## Queryable body ##
|
||||
id = Column(Integer, primary_key=True, index=True)
|
||||
|
||||
## Non queryable body ##
|
||||
other = Column(JSON)
|
||||
|
||||
## Relations ##
|
||||
# one entity can have many consumers
|
||||
entity = relationship("Entity", back_populates="consumers")
|
||||
entity_did = Column(Integer, ForeignKey("entities.did"))
|
||||
entity_did = Column(String, ForeignKey("entities.did"))
|
||||
|
||||
# one consumer has one producer
|
||||
producer = relationship("Producer", back_populates="consumers")
|
||||
producer_id = Column(Integer, ForeignKey("producers.id"))
|
||||
producer_uuid = Column(String, ForeignKey("producers.uuid"))
|
||||
|
||||
__table_args__ = (UniqueConstraint("producer_uuid", "entity_did"),)
|
||||
|
||||
|
||||
# class Repository(ProducerAbstract):
|
||||
# __tablename__ = "repositories"
|
||||
class Repository(ProducerAbstract):
|
||||
__tablename__ = "repositories"
|
||||
|
||||
# # one repository has one entity
|
||||
# entity = relationship("Entity", back_populates="repository")
|
||||
# entity_did = Column(Integer, ForeignKey("entities.did"))
|
||||
time_created = Column(DateTime(timezone=True), server_default=func.now())
|
||||
|
||||
# one repository has one entity
|
||||
entity = relationship("Entity", back_populates="repository")
|
||||
entity_did = Column(Integer, ForeignKey("entities.did"))
|
||||
|
||||
|
||||
# TODO: Ask how this works exactly
|
||||
|
||||
Reference in New Issue
Block a user