33 lines
1.2 KiB
Python
33 lines
1.2 KiB
Python
"""Project Knowledge Graph entity model."""
|
|
|
|
from __future__ import annotations
|
|
|
|
from typing import Any, Optional
|
|
|
|
from sqlalchemy import Integer, TIMESTAMP, VARCHAR, UniqueConstraint, func
|
|
from sqlalchemy.orm import Mapped, mapped_column
|
|
|
|
from .base import Base
|
|
from .types import JSONB
|
|
|
|
|
|
class KGEntity(Base):
|
|
__tablename__ = "kg_entities"
|
|
__table_args__ = (
|
|
UniqueConstraint("tenant_id", "entity_type", "entity_key", name="uq_kg_entities_tenant_type_key"),
|
|
)
|
|
|
|
id: Mapped[int] = mapped_column(Integer, primary_key=True, autoincrement=True)
|
|
entity_type: Mapped[str] = mapped_column(VARCHAR(40), nullable=False, index=True)
|
|
entity_key: Mapped[str] = mapped_column(VARCHAR(255), nullable=False, index=True)
|
|
display_name: Mapped[str] = mapped_column(VARCHAR(255), nullable=False)
|
|
payload: Mapped[Optional[Any]] = mapped_column(JSONB, nullable=True)
|
|
source_type: Mapped[str] = mapped_column(VARCHAR(32), nullable=False, default="system", index=True)
|
|
source_ref: Mapped[Optional[str]] = mapped_column(VARCHAR(255), nullable=True)
|
|
last_seen_at: Mapped[Optional[TIMESTAMP]] = mapped_column(
|
|
TIMESTAMP,
|
|
nullable=False,
|
|
server_default=func.now(),
|
|
index=True,
|
|
)
|