This commit is contained in:
jxxghp
2025-08-19 11:53:59 +08:00
parent 15833f94cf
commit 4bc24f3b00
16 changed files with 20 additions and 23 deletions
+4 -7
View File
@@ -2,23 +2,20 @@ import asyncio
from typing import Any, Generator, List, Optional, Self, Tuple, AsyncGenerator, Union from typing import Any, Generator, List, Optional, Self, Tuple, AsyncGenerator, Union
from sqlalchemy import NullPool, QueuePool, and_, create_engine, inspect, text, select, delete, Column, Integer, \ from sqlalchemy import NullPool, QueuePool, and_, create_engine, inspect, text, select, delete, Column, Integer, \
Sequence Sequence, Identity
from sqlalchemy.ext.asyncio import create_async_engine, AsyncSession, async_sessionmaker from sqlalchemy.ext.asyncio import create_async_engine, AsyncSession, async_sessionmaker
from sqlalchemy.orm import Session, as_declarative, declared_attr, scoped_session, sessionmaker from sqlalchemy.orm import Session, as_declarative, declared_attr, scoped_session, sessionmaker
from app.core.config import settings from app.core.config import settings
def get_id_column(table_name: str = None): def get_id_column():
""" """
根据数据库类型返回合适的ID列定义 根据数据库类型返回合适的ID列定义
""" """
if settings.DB_TYPE.lower() == "postgresql": if settings.DB_TYPE.lower() == "postgresql":
# PostgreSQL使用显式序列,确保序列正确创建 # PostgreSQL使用SERIAL类型,让数据库自动处理序列
if table_name: return Column(Integer, Identity(start=1, cycle=True), primary_key=True, index=True)
return Column(Integer, Sequence(f'{table_name}_id_seq'), primary_key=True, index=True)
else:
return Column(Integer, Sequence('id_seq'), primary_key=True, index=True)
else: else:
# SQLite使用Sequence # SQLite使用Sequence
return Column(Integer, Sequence('id'), primary_key=True, index=True) return Column(Integer, Sequence('id'), primary_key=True, index=True)
+2 -2
View File
@@ -12,7 +12,7 @@ class DownloadHistory(Base):
""" """
下载历史记录 下载历史记录
""" """
id = get_id_column('downloadhistory') id = get_id_column()
# 保存路径 # 保存路径
path = Column(String, nullable=False, index=True) path = Column(String, nullable=False, index=True)
# 类型 电影/电视剧 # 类型 电影/电视剧
@@ -188,7 +188,7 @@ class DownloadFiles(Base):
""" """
下载文件记录 下载文件记录
""" """
id = get_id_column('downloadfiles') id = get_id_column()
# 下载器 # 下载器
downloader = Column(String) downloader = Column(String)
# 下载任务Hash # 下载任务Hash
+1 -1
View File
@@ -13,7 +13,7 @@ class MediaServerItem(Base):
""" """
媒体服务器媒体条目表 媒体服务器媒体条目表
""" """
id = get_id_column('mediaserveritem') id = get_id_column()
# 服务器类型 # 服务器类型
server = Column(String) server = Column(String)
# 媒体库ID # 媒体库ID
+1 -1
View File
@@ -11,7 +11,7 @@ class Message(Base):
""" """
消息表 消息表
""" """
id = get_id_column('message') id = get_id_column()
# 消息渠道 # 消息渠道
channel = Column(String) channel = Column(String)
# 消息来源 # 消息来源
+1 -1
View File
@@ -8,7 +8,7 @@ class PluginData(Base):
""" """
插件数据表 插件数据表
""" """
id = get_id_column('plugindata') id = get_id_column()
plugin_id = Column(String, nullable=False, index=True) plugin_id = Column(String, nullable=False, index=True)
key = Column(String, index=True, nullable=False) key = Column(String, index=True, nullable=False)
value = Column(JSON) value = Column(JSON)
+1 -1
View File
@@ -11,7 +11,7 @@ class Site(Base):
""" """
站点表 站点表
""" """
id = get_id_column('site') id = get_id_column()
# 站点名 # 站点名
name = Column(String, nullable=False) name = Column(String, nullable=False)
# 域名Key # 域名Key
+1 -1
View File
@@ -9,7 +9,7 @@ class SiteIcon(Base):
""" """
站点图标表 站点图标表
""" """
id = get_id_column('siteicon') id = get_id_column()
# 站点名称 # 站点名称
name = Column(String, nullable=False) name = Column(String, nullable=False)
# 域名Key # 域名Key
+1 -1
View File
@@ -11,7 +11,7 @@ class SiteStatistic(Base):
""" """
站点统计表 站点统计表
""" """
id = get_id_column('sitestatistic') id = get_id_column()
# 域名Key # 域名Key
domain = Column(String, index=True) domain = Column(String, index=True)
# 成功次数 # 成功次数
+1 -1
View File
@@ -12,7 +12,7 @@ class SiteUserData(Base):
""" """
站点数据表 站点数据表
""" """
id = get_id_column('siteuserdata') id = get_id_column()
# 站点域名 # 站点域名
domain = Column(String, index=True) domain = Column(String, index=True)
# 站点名称 # 站点名称
+1 -1
View File
@@ -12,7 +12,7 @@ class Subscribe(Base):
""" """
订阅表 订阅表
""" """
id = get_id_column('subscribe') id = get_id_column()
# 标题 # 标题
name = Column(String, nullable=False, index=True) name = Column(String, nullable=False, index=True)
# 年份 # 年份
+1 -1
View File
@@ -11,7 +11,7 @@ class SubscribeHistory(Base):
""" """
订阅历史表 订阅历史表
""" """
id = get_id_column('subscribehistory') id = get_id_column()
# 标题 # 标题
name = Column(String, nullable=False, index=True) name = Column(String, nullable=False, index=True)
# 年份 # 年份
+1 -1
View File
@@ -9,7 +9,7 @@ class SystemConfig(Base):
""" """
配置表 配置表
""" """
id = get_id_column('systemconfig') id = get_id_column()
# 主键 # 主键
key = Column(String, index=True) key = Column(String, index=True)
# 值 # 值
+1 -1
View File
@@ -12,7 +12,7 @@ class TransferHistory(Base):
""" """
整理记录 整理记录
""" """
id = get_id_column('transferhistory') id = get_id_column()
# 源路径 # 源路径
src = Column(String, index=True) src = Column(String, index=True)
# 源存储 # 源存储
+1 -1
View File
@@ -10,7 +10,7 @@ class User(Base):
用户表 用户表
""" """
# ID # ID
id = get_id_column('user') id = get_id_column()
# 用户名,唯一值 # 用户名,唯一值
name = Column(String, index=True, nullable=False) name = Column(String, index=True, nullable=False)
# 邮箱 # 邮箱
+1 -1
View File
@@ -8,7 +8,7 @@ class UserConfig(Base):
""" """
用户配置表 用户配置表
""" """
id = get_id_column('userconfig') id = get_id_column()
# 用户名 # 用户名
username = Column(String, index=True) username = Column(String, index=True)
# 配置键 # 配置键
+1 -1
View File
@@ -12,7 +12,7 @@ class Workflow(Base):
工作流表 工作流表
""" """
# ID # ID
id = get_id_column('workflow') id = get_id_column()
# 名称 # 名称
name = Column(String, index=True, nullable=False) name = Column(String, index=True, nullable=False)
# 描述 # 描述