config.py 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. from sqlalchemy import Column, Integer, String, Text, DateTime, ForeignKey, UniqueConstraint, Index
  2. from sqlalchemy.sql import func
  3. from app.database import Base
  4. class SystemConfig(Base):
  5. __tablename__ = "system_config"
  6. __table_args__ = (
  7. UniqueConstraint("tenant_id", "config_key", name="uq_system_config_tenant_key"),
  8. Index("idx_system_config_tenant_id", "tenant_id"),
  9. {"schema": "aigcspace"},
  10. )
  11. id = Column(Integer, primary_key=True, index=True)
  12. tenant_id = Column(Integer, ForeignKey("aigcspace.tenants.id"), nullable=True, index=True)
  13. config_key = Column(String(100), nullable=False, index=True)
  14. config_value = Column(Text, nullable=False)
  15. config_type = Column(String(20), nullable=False)
  16. category = Column(String(50), nullable=False, index=True)
  17. description = Column(String(500))
  18. updated_by = Column(Integer, ForeignKey("aigcspace.enterprise_admins.id"), nullable=True)
  19. updated_at = Column(DateTime, default=func.now(), onupdate=func.now())
  20. created_at = Column(DateTime, default=func.now())
  21. class ConfigHistory(Base):
  22. __tablename__ = "config_history"
  23. __table_args__ = (
  24. Index("idx_config_history_tenant_id", "tenant_id"),
  25. {"schema": "aigcspace"},
  26. )
  27. id = Column(Integer, primary_key=True, index=True)
  28. tenant_id = Column(Integer, ForeignKey("aigcspace.tenants.id"), nullable=True, index=True)
  29. config_key = Column(String(100), nullable=False, index=True)
  30. old_value = Column(Text)
  31. new_value = Column(Text, nullable=False)
  32. updated_by = Column(Integer, ForeignKey("aigcspace.enterprise_admins.id"), nullable=True)
  33. updated_at = Column(DateTime, default=func.now(), index=True)