Add additional ORM relations and thumbs in API responses
This commit is contained in:
parent
791a79249c
commit
4272f2878e
9 changed files with 37 additions and 6 deletions
|
@ -25,3 +25,4 @@ class ChargePoint(Base):
|
|||
connectors = relationship("Connector", cascade="delete, delete-orphan")
|
||||
transactions = relationship("Transaction", cascade="delete, delete-orphan")
|
||||
variables = relationship("ChargepointVariable", cascade="delete, delete-orphan")
|
||||
firmware_updates = relationship("FirmwareUpdate", cascade="delete, delete-orphan")
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
import uuid
|
||||
from sqlalchemy import Column, DateTime, Enum, ForeignKey, Integer, String, Text, Uuid
|
||||
from sqlalchemy.orm import relationship
|
||||
|
||||
from app.database import Base
|
||||
from app.schemas.firmware_update import FirmwareUpdateStatus
|
||||
|
@ -20,3 +21,4 @@ class FirmwareUpdate(Base):
|
|||
signature = Column(String, nullable=True)
|
||||
|
||||
chargepoint_id = Column(Uuid, ForeignKey("chargepoints.id"), index=True)
|
||||
chargepoint = relationship("ChargePoint", back_populates="firmware_updates")
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
import uuid
|
||||
from sqlalchemy import Uuid, Column, DateTime, Enum, Float, ForeignKey, String
|
||||
from sqlalchemy.orm import relationship
|
||||
|
||||
from app.database import Base
|
||||
from app.schemas.meter_value import Measurand, PhaseType
|
||||
|
@ -14,4 +15,5 @@ class MeterValue(Base):
|
|||
unit = Column(String, nullable=True)
|
||||
value = Column(Float)
|
||||
|
||||
transaction_id = Column(String, ForeignKey("transactions.id"), index=True)
|
||||
transaction_id = Column(String, ForeignKey("transactions.id"), index=True)
|
||||
transaction = relationship("Transaction", back_populates="meter_values")
|
|
@ -1,5 +1,6 @@
|
|||
import uuid
|
||||
from sqlalchemy import Column, DateTime, ForeignKey, String, Uuid
|
||||
from sqlalchemy.orm import relationship
|
||||
|
||||
from app.database import Base
|
||||
|
||||
|
@ -11,4 +12,5 @@ class Session(Base):
|
|||
refresh_token = Column(String, nullable=False, unique=True, index=True)
|
||||
last_used = Column(DateTime(timezone=True))
|
||||
|
||||
user_id = Column(Uuid, ForeignKey("users.id"), nullable=False, index=True)
|
||||
user_id = Column(Uuid, ForeignKey("users.id"), nullable=False, index=True)
|
||||
user = relationship("User", back_populates="sessions")
|
|
@ -1,4 +1,5 @@
|
|||
from sqlalchemy import String, Uuid, Column, DateTime, Enum, Numeric, ForeignKey
|
||||
from sqlalchemy.orm import relationship
|
||||
|
||||
from app.schemas.transaction import TransactionEventTriggerReason, TransactionStatus
|
||||
from app.database import Base
|
||||
|
@ -16,4 +17,9 @@ class Transaction(Base):
|
|||
price = Column(Numeric(10,2))
|
||||
|
||||
user_id = Column(Uuid, ForeignKey("users.id"), nullable=True, index=True)
|
||||
user = relationship("User", back_populates="transactions")
|
||||
|
||||
chargepoint_id = Column(Uuid, ForeignKey("chargepoints.id"), index=True)
|
||||
chargepoint = relationship("ChargePoint", back_populates="transactions")
|
||||
|
||||
meter_values = relationship("MeterValue", cascade="delete, delete-orphan")
|
||||
|
|
|
@ -17,3 +17,4 @@ class User(Base):
|
|||
|
||||
id_tokens = relationship("IdToken", back_populates="owner", cascade="delete, delete-orphan")
|
||||
transactions = relationship("Transaction", cascade="delete, delete-orphan")
|
||||
sessions = relationship("Session", cascade="delete, delete-orphan")
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue