46 lines
1.6 KiB
Python
46 lines
1.6 KiB
Python
"""SQLAlchemy model for the 'states' table in the Home Assistant PostgreSQL database."""
|
|
|
|
from sqlalchemy import (
|
|
Column,
|
|
BigInteger,
|
|
CHAR,
|
|
String,
|
|
SmallInteger,
|
|
TIMESTAMP,
|
|
Float,
|
|
LargeBinary,
|
|
ForeignKey,
|
|
)
|
|
|
|
from .base import Base
|
|
|
|
|
|
class States(Base):
|
|
"""SQLAlchemy model for the 'states' table."""
|
|
|
|
__tablename__ = "states"
|
|
__table_args__ = {"schema": "public"}
|
|
|
|
state_id = Column(BigInteger, primary_key=True, autoincrement=True)
|
|
entity_id = Column(CHAR(1), nullable=True)
|
|
state = Column(String(255), nullable=True)
|
|
attributes = Column(CHAR(1), nullable=True)
|
|
event_id = Column(SmallInteger, nullable=True)
|
|
last_changed = Column(TIMESTAMP(timezone=True), nullable=True)
|
|
last_changed_ts = Column(Float, nullable=True)
|
|
last_reported_ts = Column(Float, nullable=True)
|
|
last_updated = Column(TIMESTAMP(timezone=True), nullable=True)
|
|
last_updated_ts = Column(Float, nullable=True)
|
|
old_state_id = Column(BigInteger, ForeignKey("public.states.state_id"), nullable=True)
|
|
attributes_id = Column(
|
|
BigInteger, ForeignKey("public.state_attributes.attributes_id"), nullable=True
|
|
)
|
|
context_id = Column(CHAR(1), nullable=True)
|
|
context_user_id = Column(CHAR(1), nullable=True)
|
|
context_parent_id = Column(CHAR(1), nullable=True)
|
|
origin_idx = Column(SmallInteger, nullable=True)
|
|
context_id_bin = Column(LargeBinary, nullable=True)
|
|
context_user_id_bin = Column(LargeBinary, nullable=True)
|
|
context_parent_id_bin = Column(LargeBinary, nullable=True)
|
|
metadata_id = Column(BigInteger, ForeignKey("public.states_meta.metadata_id"), nullable=True)
|