plugin.py 1.5 KB

12345678910111213141516171819202122232425262728293031323334
  1. from datetime import datetime
  2. from sqlalchemy import Column, Integer, String, Text, SmallInteger, DateTime, UniqueConstraint, Index
  3. from app.core.database import Base
  4. class Plugin(Base):
  5. __tablename__ = "plugins"
  6. id = Column(Integer, primary_key=True, autoincrement=True)
  7. name = Column(String(64), unique=True, nullable=False, index=True)
  8. display_name = Column(String(128), nullable=False, default="")
  9. filename = Column(String(128), nullable=False, default="")
  10. latest_version = Column(String(32), nullable=False, default="1.0.0")
  11. description = Column(String(512), nullable=False, default="")
  12. status = Column(SmallInteger, nullable=False, default=1, index=True)
  13. created_at = Column(DateTime, default=datetime.utcnow, nullable=False)
  14. updated_at = Column(DateTime, default=datetime.utcnow, onupdate=datetime.utcnow, nullable=False)
  15. class PluginVersion(Base):
  16. __tablename__ = "plugin_versions"
  17. id = Column(Integer, primary_key=True, autoincrement=True)
  18. plugin_id = Column(Integer, nullable=False, default=0, index=True)
  19. plugin_name = Column(String(64), nullable=False, index=True)
  20. version = Column(String(32), nullable=False)
  21. download_url = Column(String(512), nullable=False)
  22. sha256 = Column(String(64), nullable=False, default="")
  23. changelog = Column(Text, nullable=True)
  24. created_at = Column(DateTime, default=datetime.utcnow, nullable=False)
  25. __table_args__ = (
  26. UniqueConstraint("plugin_id", "version", name="uk_plugin_version"),
  27. )