provider.py 1.1 KB

1234567891011121314151617181920212223242526272829303132333435
  1. from datetime import datetime
  2. from sqlalchemy import (
  3. Column,
  4. Integer,
  5. BigInteger,
  6. SmallInteger,
  7. String,
  8. DateTime,
  9. JSON,
  10. UniqueConstraint,
  11. Index,
  12. )
  13. from app.core.database import Base
  14. class Provider(Base):
  15. __tablename__ = "providers"
  16. id = Column(BigInteger, primary_key=True, autoincrement=True)
  17. name = Column(String(128), nullable=False, unique=True, index=True)
  18. enabled = Column(SmallInteger, nullable=False, default=1)
  19. plugin_config = Column(JSON, nullable=False, default=dict)
  20. role_templates = Column(JSON, nullable=False, default=dict)
  21. version = Column(Integer, nullable=False, default=0)
  22. updated_by = Column(String(64), nullable=True, default="system")
  23. created_at = Column(DateTime, default=datetime.utcnow, nullable=False)
  24. updated_at = Column(
  25. DateTime, default=datetime.utcnow, onupdate=datetime.utcnow, nullable=False
  26. )
  27. __table_args__ = (
  28. UniqueConstraint("name", name="uk_providers_name"),
  29. Index("idx_providers_enabled", "enabled"),
  30. Index("idx_providers_updated_at", "updated_at"),
  31. )