You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
106 lines
3.9 KiB
106 lines
3.9 KiB
"""
|
|
AmazingData 数据服务平台 - 数据库表模型
|
|
"""
|
|
|
|
from sqlalchemy import Column, Integer, String, Text, DateTime, BigInteger, JSON, Boolean, ForeignKey, Index
|
|
from sqlalchemy.sql import func
|
|
from backend.models.database import Base
|
|
|
|
|
|
class SystemConfig(Base):
|
|
"""系统配置表"""
|
|
__tablename__ = "system_config"
|
|
|
|
id = Column(Integer, primary_key=True, autoincrement=True)
|
|
config_key = Column(String(100), unique=True, nullable=False, index=True)
|
|
config_value = Column(Text)
|
|
config_type = Column(String(20), default="string")
|
|
description = Column(String(255))
|
|
created_at = Column(DateTime, server_default=func.now())
|
|
updated_at = Column(DateTime, server_default=func.now(), onupdate=func.now())
|
|
|
|
|
|
class User(Base):
|
|
"""用户表"""
|
|
__tablename__ = "users"
|
|
|
|
id = Column(Integer, primary_key=True, autoincrement=True)
|
|
username = Column(String(50), unique=True, nullable=False, index=True)
|
|
password_hash = Column(String(255), nullable=False)
|
|
role = Column(String(20), default="user")
|
|
is_active = Column(Boolean, default=True)
|
|
last_login = Column(DateTime)
|
|
created_at = Column(DateTime, server_default=func.now())
|
|
updated_at = Column(DateTime, server_default=func.now(), onupdate=func.now())
|
|
|
|
|
|
class SubscriptionTask(Base):
|
|
"""订阅任务表"""
|
|
__tablename__ = "subscription_tasks"
|
|
|
|
id = Column(Integer, primary_key=True, autoincrement=True)
|
|
task_name = Column(String(100), nullable=False)
|
|
codes = Column(JSON, nullable=False)
|
|
periods = Column(JSON, nullable=False)
|
|
save_path = Column(String(255))
|
|
duration = Column(Integer, default=0)
|
|
save_interval = Column(Integer, default=60)
|
|
status = Column(String(20), default="pending", index=True)
|
|
subscription_id = Column(String(100))
|
|
started_at = Column(DateTime)
|
|
stopped_at = Column(DateTime)
|
|
created_by = Column(String(50))
|
|
created_at = Column(DateTime, server_default=func.now(), index=True)
|
|
updated_at = Column(DateTime, server_default=func.now(), onupdate=func.now())
|
|
|
|
|
|
class BatchTask(Base):
|
|
"""批量任务表"""
|
|
__tablename__ = "batch_tasks"
|
|
|
|
id = Column(Integer, primary_key=True, autoincrement=True)
|
|
task_type = Column(String(20), nullable=False, index=True)
|
|
task_params = Column(JSON)
|
|
total_count = Column(Integer, default=0)
|
|
processed_count = Column(Integer, default=0)
|
|
success_count = Column(Integer, default=0)
|
|
failed_count = Column(Integer, default=0)
|
|
status = Column(String(20), default="pending", index=True)
|
|
output_path = Column(String(255))
|
|
error_message = Column(Text)
|
|
started_at = Column(DateTime)
|
|
completed_at = Column(DateTime)
|
|
created_by = Column(String(50))
|
|
created_at = Column(DateTime, server_default=func.now())
|
|
updated_at = Column(DateTime, server_default=func.now(), onupdate=func.now())
|
|
|
|
|
|
class CacheRecord(Base):
|
|
"""数据缓存记录表"""
|
|
__tablename__ = "cache_records"
|
|
|
|
id = Column(Integer, primary_key=True, autoincrement=True)
|
|
filename = Column(String(255), nullable=False, index=True)
|
|
file_type = Column(String(20), nullable=False, index=True)
|
|
trading_day = Column(String(8), index=True)
|
|
code = Column(String(20))
|
|
period = Column(String(10))
|
|
record_count = Column(Integer, default=0)
|
|
file_size = Column(BigInteger, default=0)
|
|
file_path = Column(String(255))
|
|
created_at = Column(DateTime, server_default=func.now())
|
|
|
|
|
|
class OperationLog(Base):
|
|
"""操作日志表"""
|
|
__tablename__ = "operation_logs"
|
|
|
|
id = Column(Integer, primary_key=True, autoincrement=True)
|
|
user_id = Column(Integer, index=True)
|
|
operation = Column(String(50), nullable=False, index=True)
|
|
resource = Column(String(100))
|
|
detail = Column(Text)
|
|
ip_address = Column(String(45))
|
|
status = Column(String(20), default="success")
|
|
error_message = Column(Text)
|
|
created_at = Column(DateTime, server_default=func.now(), index=True) |