knowledge_base.py 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. from sqlalchemy import create_engine, Column, Integer, String, ForeignKey, DateTime, Table, MetaData,Text
  2. from sqlalchemy.ext.declarative import declarative_base
  3. from sqlalchemy.orm import relationship, sessionmaker
  4. Base = declarative_base()
  5. metadata = MetaData()
  6. from sqlalchemy import Column, Integer, String, Text, DateTime, ForeignKey
  7. from sqlalchemy.orm import relationship
  8. class KnowledgeFile(Base):
  9. __tablename__ = 'knowledge_file'
  10. id = Column(Integer, primary_key=True)
  11. file_identifier = Column(String(50), unique=True, nullable=False, comment='文件唯一标识符')
  12. file_path = Column(Text, nullable=False, comment='文件存储路径')
  13. file_name = Column(String(255), nullable=False, comment='文件名字')
  14. is_deleted = Column(Integer, default=0, comment='是否删除')
  15. createTime = Column(DateTime, comment='创建时间')
  16. updateTime = Column(DateTime, comment='更新时间')
  17. knowledge_base_code = Column(String(50), ForeignKey('knowledge_base.base_code'), nullable=False)
  18. knowledge_base = relationship("KnowledgeBase", back_populates="files")
  19. class KnowledgeBase(Base):
  20. __tablename__ = 'knowledge_base'
  21. reportId = Column(String(255), primary_key=True)
  22. reportName = Column(String(400), comment='报告名称')
  23. subject = Column(String(100), comment='主题词')
  24. eventType = Column(String(10), comment='事件类型')
  25. publishDate = Column(DateTime, comment='发布日期')
  26. publishingUnit = Column(String(255), comment='来源单位')
  27. summary = Column(String(100), comment='摘要')
  28. notificationType = Column(String(100), comment='知识类型')
  29. updateTime = Column(DateTime, comment='更新时间')
  30. base_code = Column(String(50), unique=True, comment='知识库的基础编码')
  31. del_flag = Column(String(10), comment='是否删除')
  32. files = relationship("KnowledgeFile", order_by=KnowledgeFile.id, back_populates="knowledge_base")