modify scripts

This commit is contained in:
2025-11-10 15:22:45 +08:00
parent 28124c1bff
commit bd6e1b6ed8
4 changed files with 192 additions and 2 deletions

View File

@ -1,5 +1,7 @@
from sqlalchemy import Column, Integer, Text, String, Float, DateTime, func
from sqlalchemy import Column, Integer, Text, String, Float, DateTime, ForeignKey, func
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import relationship, Mapped
from typing import List, Optional
# 基础模型基类(如果已有全局 Base 可直接复用)
ResourceBase = declarative_base()
@ -26,4 +28,95 @@ class U3C3(ResourceBase):
def __repr__(self):
"""打印实例时显示的信息"""
return f"<U3c3(id={self.id}, title='{self.title[:20]}...')>"
return f"<U3c3(id={self.id}, title='{self.title[:20]}...')>"
class Sis(ResourceBase):
"""对应 MySQL 中的 sis 表"""
__tablename__ = "sis" # 表名与原表保持一致
# 字段定义(严格映射原表结构)
id = Column(Integer, primary_key=True, autoincrement=True, comment="主键ID")
plate_name = Column(Text, comment="板块名称")
title = Column(Text, comment="标题")
url = Column(String(512), unique=True, comment="资源链接(唯一)")
size_text = Column(Text, comment="大小文本描述")
size_gb = Column(Float, comment="大小GB")
update_date = Column(Text, comment="更新日期")
# 补充MySQL 中建议用 func.now() 替代 func.datetime(...),兼容性更好
created_at = Column(DateTime, default=func.now(), comment="创建时间(本地时间)")
updated_at = Column(DateTime, default=func.now(), onupdate=func.now(), comment="更新时间(本地时间)")
def __repr__(self):
return f"<Sis(id={self.id}, title='{self.title[:20]}...')>"
class ClmIndex(ResourceBase):
"""对应 MySQL 中的 clm_index 表"""
__tablename__ = "clm_index" # 表名与原表保持一致
# 字段定义(严格映射原表结构)
id = Column(Integer, primary_key=True, autoincrement=True, comment="主键ID")
category = Column(Text, comment="分类")
title = Column(Text, comment="标题")
href = Column(String(512), unique=True, comment="资源链接(唯一)")
magnet_href = Column(Text, comment="磁力链接")
size_text = Column(Text, comment="大小文本描述")
size_gb = Column(Float, comment="大小GB")
heat = Column(Integer, default=0, comment="热度")
add_date = Column(Text, comment="添加日期")
last_down_date = Column(Text, comment="最后下载日期")
created_at = Column(DateTime, default=func.now(), comment="创建时间(本地时间)")
updated_at = Column(DateTime, default=func.now(), onupdate=func.now(), comment="更新时间(本地时间)")
# 关系定义:用 Mapped[List["ClmKeywordsIndex"]] 替代 List["ClmKeywordsIndex"]
clm_keywords_index: Mapped[List["ClmKeywordsIndex"]] = relationship(
"ClmKeywordsIndex", back_populates="index"
)
def __repr__(self):
return f"<ClmIndex(id={self.id}, title='{self.title[:20]}...')>"
class ClmKeywords(ResourceBase):
"""对应 MySQL 中的 clm_keywords 表"""
__tablename__ = "clm_keywords" # 表名与原表保持一致
# 字段定义(严格映射原表结构)
id = Column(Integer, primary_key=True, autoincrement=True, comment="主键ID")
words = Column(String(512), unique=True, comment="关键词(唯一)")
groups = Column(Text, comment="关键词分组")
tags = Column(Text, comment="标签")
index_count = Column(Integer, default=0, comment="关联索引数量")
created_at = Column(DateTime, default=func.now(), comment="创建时间(本地时间)")
updated_at = Column(DateTime, default=func.now(), onupdate=func.now(), comment="更新时间(本地时间)")
# 关系定义:用 Mapped[List["ClmKeywordsIndex"]] 替代 List["ClmKeywordsIndex"]
clm_keywords_index: Mapped[List["ClmKeywordsIndex"]] = relationship(
"ClmKeywordsIndex", back_populates="words"
)
def __repr__(self):
return f"<ClmKeywords(id={self.id}, words='{self.words[:20]}...')>"
class ClmKeywordsIndex(ResourceBase):
"""对应 MySQL 中的 clm_keywords_index 表(关联表)"""
__tablename__ = "clm_keywords_index" # 表名与原表保持一致
# 字段定义(严格映射原表结构)
id = Column(Integer, primary_key=True, autoincrement=True, comment="主键ID")
words_id = Column(Integer, ForeignKey("clm_keywords.id"), comment="关键词ID外键")
index_id = Column(Integer, ForeignKey("clm_index.id"), comment="索引ID外键")
wid_iid = Column(String(255), unique=True, comment="关键词与索引的关联标识")
tags = Column(Text, comment="关联标签")
created_at = Column(DateTime, default=func.now(), comment="创建时间(本地时间)")
updated_at = Column(DateTime, default=func.now(), onupdate=func.now(), comment="更新时间(本地时间)")
# 关系定义:用 Mapped 包装单个对象类型
index: Mapped["ClmIndex"] = relationship("ClmIndex", back_populates="clm_keywords_index")
words: Mapped["ClmKeywords"] = relationship("ClmKeywords", back_populates="clm_keywords_index")
def __repr__(self):
return f"<ClmKeywordsIndex(id={self.id}, words_id={self.words_id}, index_id={self.index_id})>"