35 lines
2.0 KiB
Python
35 lines
2.0 KiB
Python
from datetime import datetime, timezone
|
|
from typing import Optional
|
|
|
|
from sqlalchemy import DateTime, ForeignKey, Index, Integer, String, Text, UniqueConstraint
|
|
from sqlalchemy.orm import Mapped, mapped_column
|
|
|
|
from app.database import Base
|
|
|
|
|
|
class UpstreamGeneratedKey(Base):
|
|
__tablename__ = "upstream_generated_keys"
|
|
|
|
id: Mapped[int] = mapped_column(Integer, primary_key=True, index=True)
|
|
upstream_id: Mapped[int] = mapped_column(Integer, ForeignKey("upstreams.id", ondelete="CASCADE"), index=True)
|
|
group_id: Mapped[str] = mapped_column(String(255), nullable=False, index=True)
|
|
group_name: Mapped[str] = mapped_column(String(255), default="")
|
|
key_id: Mapped[Optional[str]] = mapped_column(String(255), nullable=True)
|
|
key_name: Mapped[str] = mapped_column(String(255), nullable=False)
|
|
key_value: Mapped[str] = mapped_column(Text, nullable=False)
|
|
masked_key: Mapped[str] = mapped_column(String(255), default="")
|
|
raw_json: Mapped[str] = mapped_column(Text, default="{}")
|
|
managed_prefix: Mapped[Optional[str]] = mapped_column(String(64), nullable=True, index=True)
|
|
status: Mapped[str] = mapped_column(String(32), default="created")
|
|
error: Mapped[Optional[str]] = mapped_column(Text, nullable=True)
|
|
imported_website_id: Mapped[Optional[int]] = mapped_column(Integer, ForeignKey("websites.id", ondelete="SET NULL"), nullable=True, index=True)
|
|
imported_account_id: Mapped[Optional[str]] = mapped_column(String(255), nullable=True)
|
|
imported_at: Mapped[Optional[datetime]] = mapped_column(DateTime, nullable=True)
|
|
created_at: Mapped[datetime] = mapped_column(DateTime, default=lambda: datetime.now(timezone.utc))
|
|
updated_at: Mapped[datetime] = mapped_column(DateTime, default=lambda: datetime.now(timezone.utc), onupdate=lambda: datetime.now(timezone.utc))
|
|
|
|
__table_args__ = (
|
|
UniqueConstraint("upstream_id", "group_id", "key_name", name="uq_upstream_group_key"),
|
|
Index("ix_key_upstream_name", "upstream_id", "key_name"),
|
|
)
|