mirror of
https://github.com/jxxghp/MoviePilot.git
synced 2026-03-20 12:08:09 +08:00
fix db
This commit is contained in:
@@ -9,13 +9,16 @@ from sqlalchemy.orm import Session, as_declarative, declared_attr, scoped_sessio
|
||||
from app.core.config import settings
|
||||
|
||||
|
||||
def get_id_column():
|
||||
def get_id_column(table_name: str = None):
|
||||
"""
|
||||
根据数据库类型返回合适的ID列定义
|
||||
"""
|
||||
if settings.DB_TYPE.lower() == "postgresql":
|
||||
# PostgreSQL使用SERIAL类型
|
||||
return Column(Integer, primary_key=True, index=True)
|
||||
# PostgreSQL使用显式序列,确保序列正确创建
|
||||
if table_name:
|
||||
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:
|
||||
# SQLite使用Sequence
|
||||
return Column(Integer, Sequence('id'), primary_key=True, index=True)
|
||||
|
||||
@@ -12,7 +12,7 @@ class DownloadHistory(Base):
|
||||
"""
|
||||
下载历史记录
|
||||
"""
|
||||
id = get_id_column()
|
||||
id = get_id_column('downloadhistory')
|
||||
# 保存路径
|
||||
path = Column(String, nullable=False, index=True)
|
||||
# 类型 电影/电视剧
|
||||
@@ -188,7 +188,7 @@ class DownloadFiles(Base):
|
||||
"""
|
||||
下载文件记录
|
||||
"""
|
||||
id = get_id_column()
|
||||
id = get_id_column('downloadfiles')
|
||||
# 下载器
|
||||
downloader = Column(String)
|
||||
# 下载任务Hash
|
||||
|
||||
@@ -13,7 +13,7 @@ class MediaServerItem(Base):
|
||||
"""
|
||||
媒体服务器媒体条目表
|
||||
"""
|
||||
id = get_id_column()
|
||||
id = get_id_column('mediaserveritem')
|
||||
# 服务器类型
|
||||
server = Column(String)
|
||||
# 媒体库ID
|
||||
|
||||
@@ -11,7 +11,7 @@ class Message(Base):
|
||||
"""
|
||||
消息表
|
||||
"""
|
||||
id = get_id_column()
|
||||
id = get_id_column('message')
|
||||
# 消息渠道
|
||||
channel = Column(String)
|
||||
# 消息来源
|
||||
|
||||
@@ -8,7 +8,7 @@ class PluginData(Base):
|
||||
"""
|
||||
插件数据表
|
||||
"""
|
||||
id = get_id_column()
|
||||
id = get_id_column('plugindata')
|
||||
plugin_id = Column(String, nullable=False, index=True)
|
||||
key = Column(String, index=True, nullable=False)
|
||||
value = Column(JSON)
|
||||
|
||||
@@ -11,7 +11,7 @@ class Site(Base):
|
||||
"""
|
||||
站点表
|
||||
"""
|
||||
id = get_id_column()
|
||||
id = get_id_column('site')
|
||||
# 站点名
|
||||
name = Column(String, nullable=False)
|
||||
# 域名Key
|
||||
|
||||
@@ -9,7 +9,7 @@ class SiteIcon(Base):
|
||||
"""
|
||||
站点图标表
|
||||
"""
|
||||
id = get_id_column()
|
||||
id = get_id_column('siteicon')
|
||||
# 站点名称
|
||||
name = Column(String, nullable=False)
|
||||
# 域名Key
|
||||
|
||||
@@ -11,7 +11,7 @@ class SiteStatistic(Base):
|
||||
"""
|
||||
站点统计表
|
||||
"""
|
||||
id = get_id_column()
|
||||
id = get_id_column('sitestatistic')
|
||||
# 域名Key
|
||||
domain = Column(String, index=True)
|
||||
# 成功次数
|
||||
|
||||
@@ -12,7 +12,7 @@ class SiteUserData(Base):
|
||||
"""
|
||||
站点数据表
|
||||
"""
|
||||
id = get_id_column()
|
||||
id = get_id_column('siteuserdata')
|
||||
# 站点域名
|
||||
domain = Column(String, index=True)
|
||||
# 站点名称
|
||||
|
||||
@@ -12,7 +12,7 @@ class Subscribe(Base):
|
||||
"""
|
||||
订阅表
|
||||
"""
|
||||
id = get_id_column()
|
||||
id = get_id_column('subscribe')
|
||||
# 标题
|
||||
name = Column(String, nullable=False, index=True)
|
||||
# 年份
|
||||
|
||||
@@ -11,7 +11,7 @@ class SubscribeHistory(Base):
|
||||
"""
|
||||
订阅历史表
|
||||
"""
|
||||
id = get_id_column()
|
||||
id = get_id_column('subscribehistory')
|
||||
# 标题
|
||||
name = Column(String, nullable=False, index=True)
|
||||
# 年份
|
||||
|
||||
@@ -9,7 +9,7 @@ class SystemConfig(Base):
|
||||
"""
|
||||
配置表
|
||||
"""
|
||||
id = get_id_column()
|
||||
id = get_id_column('systemconfig')
|
||||
# 主键
|
||||
key = Column(String, index=True)
|
||||
# 值
|
||||
|
||||
@@ -12,7 +12,7 @@ class TransferHistory(Base):
|
||||
"""
|
||||
整理记录
|
||||
"""
|
||||
id = get_id_column()
|
||||
id = get_id_column('transferhistory')
|
||||
# 源路径
|
||||
src = Column(String, index=True)
|
||||
# 源存储
|
||||
|
||||
@@ -10,7 +10,7 @@ class User(Base):
|
||||
用户表
|
||||
"""
|
||||
# ID
|
||||
id = get_id_column()
|
||||
id = get_id_column('user')
|
||||
# 用户名,唯一值
|
||||
name = Column(String, index=True, nullable=False)
|
||||
# 邮箱
|
||||
|
||||
@@ -8,7 +8,7 @@ class UserConfig(Base):
|
||||
"""
|
||||
用户配置表
|
||||
"""
|
||||
id = get_id_column()
|
||||
id = get_id_column('userconfig')
|
||||
# 用户名
|
||||
username = Column(String, index=True)
|
||||
# 配置键
|
||||
|
||||
@@ -12,7 +12,7 @@ class Workflow(Base):
|
||||
工作流表
|
||||
"""
|
||||
# ID
|
||||
id = get_id_column()
|
||||
id = get_id_column('workflow')
|
||||
# 名称
|
||||
name = Column(String, index=True, nullable=False)
|
||||
# 描述
|
||||
|
||||
Reference in New Issue
Block a user