Files
opsxsql/backend/app/models/instance.py
T
logan 128de64592 feat: 数据源编辑加排除数据库+脱敏字段+审批流关联; 权限组Transfer改为选择实例
- EditInstanceDialog: 新增排除数据库(逗号分隔)、脱敏字段(动态表单+表/字段/规则)、审批流程关联
- Instance: workflow JSON字段改为workflow_id FK关联workflow_definitions表
- InstanceGroupPage: Transfer穿梭框从选数据库改为选实例(数据源)
- 后端instance API返回workflow_name, _get_workflow_names批量查询
- DB迁移: instances表添加workflow_id列
- 37个测试全部通过
2026-05-24 19:36:39 +08:00

38 lines
1.7 KiB
Python

from sqlalchemy import Column, Integer, String, Text, DateTime, ForeignKey, func
from sqlalchemy.orm import relationship
from app.core.database import Base
class Instance(Base):
__tablename__ = "instances"
id = Column(Integer, primary_key=True, autoincrement=True)
name = Column(String(100), nullable=False)
db_type = Column(String(20), nullable=False) # mysql / postgres / redis / mongo
host = Column(String(200), nullable=False)
port = Column(Integer, nullable=False)
username = Column(String(100), nullable=False)
password = Column(String(500), nullable=False) # encrypted
database = Column(String(100), nullable=True)
env = Column(String(20), default="development") # production / staging / development
description = Column(Text, nullable=True)
status = Column(String(20), default="disconnected") # connected / disconnected / error
version = Column(String(50), nullable=True)
# 新增字段
access_mode = Column(String(20), default="readwrite") # readwrite / read / write
workflow_id = Column(Integer, ForeignKey("workflow_definitions.id", ondelete="SET NULL"), nullable=True)
excluded_databases = Column(Text, nullable=True) # JSON: ["sys", "information_schema", ...]
mask_fields = Column(Text, nullable=True) # JSON: [{table, field, rule}]
# 权限组关联
group_id = Column(Integer, ForeignKey("instance_groups.id", ondelete="SET NULL"), nullable=True)
created_at = Column(DateTime, server_default=func.now())
updated_at = Column(DateTime, server_default=func.now(), onupdate=func.now())
# 关系
group = relationship("InstanceGroup", back_populates="instances")
workflow_def = relationship("WorkflowDefinition")