393 lines
23 KiB
Python
393 lines
23 KiB
Python
"""Seed content: the IT system inventory plus the initial data-flow topology.
|
||
|
||
Everything here is editable through the API afterwards; seeding only runs when the
|
||
database is still empty so local edits are never overwritten.
|
||
"""
|
||
|
||
from __future__ import annotations
|
||
|
||
import sqlite3
|
||
|
||
from .db import json_dump, set_setting, transaction, utcnow
|
||
|
||
LAYERS = [
|
||
{
|
||
"id": "common",
|
||
"name": "通用系统(全公司使用)",
|
||
"short_name": "通用系统",
|
||
"color": "#0d9488",
|
||
"description": "面向全公司提供的通用办公与协同系统。",
|
||
"sort_order": 1,
|
||
},
|
||
{
|
||
"id": "dept",
|
||
"name": "各部门业务系统",
|
||
"short_name": "部门业务",
|
||
"color": "#2563eb",
|
||
"description": "由各业务部门主导建设、服务本部门主流程的系统。",
|
||
"sort_order": 2,
|
||
},
|
||
{
|
||
"id": "base",
|
||
"name": "底座(基础平台)",
|
||
"short_name": "底座",
|
||
"color": "#7c3aed",
|
||
"description": "为上层系统提供认证、算力、存储与组件复用能力的底座平台。",
|
||
"sort_order": 3,
|
||
},
|
||
]
|
||
|
||
# tier drives the column of a node inside the data-flow graph:
|
||
# 0 = 统一入口层, 1 = 审批中枢, 2 = 业务系统, 3 = 底座能力
|
||
SYSTEMS = [
|
||
# ---- 通用系统 ----
|
||
{
|
||
"key": "oa", "name": "OA(华智OA)", "layer_id": "common", "dept": "",
|
||
"status": "running", "tech": "Java / Spring Boot / MySQL",
|
||
"tier": 1,
|
||
"description": "统一办公自动化系统(华智OA),覆盖审批、流程、协同办公,全公司正常使用中,也是当前审批数据的主要产生源。",
|
||
},
|
||
{
|
||
"key": "finance-bot", "name": "财务数字助理", "layer_id": "common", "dept": "",
|
||
"status": "running", "tech": "Python / OCR / MySQL",
|
||
"tier": 2,
|
||
"description": "智能化财务辅助系统,承接 OA 报销单据做票据识别与入账处理,正常使用中。",
|
||
},
|
||
{
|
||
"key": "nas", "name": "NAS文件服务", "layer_id": "common", "dept": "",
|
||
"status": "running", "tech": "NAS / SMB",
|
||
"tier": 3,
|
||
"description": "网络文件存储与共享服务,承载盖章合同原件等归档文件,正常使用中。",
|
||
},
|
||
{
|
||
"key": "wecom", "name": "企业微信", "layer_id": "common", "dept": "",
|
||
"status": "running", "tech": "企业微信开放平台",
|
||
"tier": 0,
|
||
"description": "统一沟通与移动办公平台,移动端统一接入入口,负责备案发起与消息提醒回传;使用独立账号体系,不接入 UniHub SSO。",
|
||
},
|
||
{
|
||
"key": "ekb", "name": "ekb知识库", "layer_id": "common", "dept": "",
|
||
"status": "dev", "tech": "Java / Elasticsearch",
|
||
"tier": 3,
|
||
"description": "企业级知识库系统,目前开发完善中,上线后服务全公司知识管理与智能检索。",
|
||
},
|
||
{
|
||
"key": "unibot", "name": "unibot(智能体平台)", "layer_id": "common", "dept": "",
|
||
"status": "running", "tech": "Python / Agent / MCP",
|
||
"tier": 0,
|
||
"description": "公司级 AI 智能体平台,经 MCP 总线向业务系统取数做经营分析,算力经 UniTensor 中转。",
|
||
},
|
||
# ---- 各部门业务系统 ----
|
||
{
|
||
"key": "kingdee", "name": "金蝶", "layer_id": "dept", "dept": "经营管理中心",
|
||
"status": "running", "tech": "金蝶 ERP",
|
||
"tier": 2,
|
||
"description": "财务管理/ERP 系统,用于经营管理中心的财务与业务一体化管理,付款/报销/开票在此完成记账。",
|
||
},
|
||
{
|
||
"key": "edrs", "name": "EDRS日报系统", "layer_id": "dept", "dept": "经营管理中心",
|
||
"status": "improving", "tech": "Vue / Java / MySQL",
|
||
"tier": 2,
|
||
"description": "员工日报填报与汇总系统,支撑经营数据报送与追踪,经 MCP 接入 unibot 做交叉分析。",
|
||
},
|
||
{
|
||
"key": "pms", "name": "PMS四算", "layer_id": "dept", "dept": "方案系统事业部、协同营销事业部",
|
||
"status": "running", "tech": "Java / MySQL",
|
||
"tier": 2,
|
||
"description": "项目四算管理系统(估算/概算/预算/决算),在合同与付款前提供预算闸门校验。",
|
||
},
|
||
{
|
||
"key": "oms", "name": "OMS", "layer_id": "dept", "dept": "云智产品事业部",
|
||
"status": "improving", "tech": "Java / Spring Boot / MySQL",
|
||
"tier": 2,
|
||
"description": "订单/运营管理系统,云智产品事业部核心业务系统,驱动采购、付款、开票的履约链路。",
|
||
},
|
||
{
|
||
"key": "dms", "name": "DMS新光线", "layer_id": "dept", "dept": "软件开发事业部",
|
||
"status": "running", "tech": "Java / MySQL",
|
||
"tier": 2,
|
||
"description": "研发/项目管理系统,定制项目信息与华智 OA 双向同步;调用 UniTensor 算力,经 MCP 接入 unibot。",
|
||
},
|
||
{
|
||
"key": "docs", "name": "docs文档系统", "layer_id": "dept", "dept": "软件开发事业部",
|
||
"status": "running", "tech": "Node.js / MongoDB",
|
||
"tier": 2,
|
||
"description": "在线文档协作系统,用于研发知识沉淀与文档共享;调用 UniTensor 中转的大模型算力并统计 token 消耗。",
|
||
},
|
||
{
|
||
"key": "gitea", "name": "Gitea代码仓", "layer_id": "dept", "dept": "软件开发事业部",
|
||
"status": "running", "tech": "Gitea / Docker",
|
||
"tier": 2,
|
||
"description": "自建 Git 代码托管平台,承载全公司研发代码协作,正常使用中。",
|
||
},
|
||
{
|
||
"key": "scc", "name": "SCC", "layer_id": "dept", "dept": "云智销售部",
|
||
"status": "improving", "tech": "Vue / Java / MySQL",
|
||
"tier": 2,
|
||
"description": "云智销售部业务系统(商机/客户/销售过程),商机备案与费用出差备案由此发起,签单后转 OMS 订单。",
|
||
},
|
||
# ---- 底座 ----
|
||
{
|
||
"key": "unitensor", "name": "UniTensor", "layer_id": "base", "dept": "",
|
||
"status": "improving", "tech": "Python / GPU / 推理服务",
|
||
"tier": 3,
|
||
"description": "底层基础组件/大模型算力中转平台,作为 Agent 与各系统推理请求的统一中转站。",
|
||
},
|
||
{
|
||
"key": "unihub", "name": "UniHub统一认证平台", "layer_id": "base", "dept": "",
|
||
"status": "improving", "tech": "OAuth2 / OIDC",
|
||
"tier": 3,
|
||
"description": "全公司统一身份认证中心(SSO)与智能体统一接入监管平台,为各系统提供登录认证与权限基础。",
|
||
},
|
||
{
|
||
"key": "k3s", "name": "k3s基础服务", "layer_id": "base", "dept": "",
|
||
"status": "running", "tech": "k3s / minIO / Docker Registry",
|
||
"tier": 3,
|
||
"description": "容器化微服务运行底座,统一纳管 fileview 文件预览、OCR 文字提取、minIO 对象存储、Docker 镜像仓库。",
|
||
},
|
||
{
|
||
"key": "dsh", "name": "DSH组件市场", "layer_id": "base", "dept": "",
|
||
"status": "improving", "tech": "前端组件 / npm 私服",
|
||
"tier": 3,
|
||
"description": "公司级组件市场,统一沉淀、共享与复用公共组件与通用能力,支撑业务系统快速集成。",
|
||
},
|
||
]
|
||
|
||
FLOW_TYPES = [
|
||
{
|
||
"id": "core", "name": "核心业务链路", "color": "#1d4ed8", "line_style": "solid",
|
||
"default_interval": 1800, "sort_order": 1,
|
||
"description": "预算→合同→订单→签单→归档的主业务闭环数据。",
|
||
},
|
||
{
|
||
"id": "entry", "name": "移动端入口 / 消息", "color": "#16a34a", "line_style": "dashed",
|
||
"default_interval": 300, "sort_order": 2,
|
||
"description": "企业微信作为移动端统一入口发起备案,并回传消息与通知。",
|
||
},
|
||
{
|
||
"id": "mcp", "name": "MCP 取数(Agent)", "color": "#a855f7", "line_style": "dash-dot",
|
||
"default_interval": 3600, "sort_order": 3,
|
||
"description": "unibot 经 MCP 总线向业务系统读取结构化数据做智能分析。",
|
||
},
|
||
{
|
||
"id": "cap", "name": "底座能力调用", "color": "#0ea5e9", "line_style": "solid",
|
||
"default_interval": 900, "sort_order": 4,
|
||
"description": "业务系统调用底座能力:算力推理、对象存储、OCR、文件预览。",
|
||
},
|
||
{
|
||
"id": "auth", "name": "统一认证(SSO)", "color": "#7c3aed", "line_style": "solid",
|
||
"default_interval": 300, "sort_order": 5,
|
||
"description": "各系统跳转 UniHub 完成票据校验与登录态同步。",
|
||
},
|
||
{
|
||
"id": "archive", "name": "归档 / 知识沉淀", "color": "#64748b", "line_style": "dash-dot",
|
||
"default_interval": 3600, "sort_order": 6,
|
||
"description": "合同原件归档、文档知识沉淀等低频大批量数据传输。",
|
||
},
|
||
]
|
||
|
||
# interval_sec / records / kb / latency describe the steady state of each link.
|
||
# peak_hours are the local hours (0-23) when the link is busiest.
|
||
FLOWS = [
|
||
# ---------- 核心业务闭环 ----------
|
||
dict(source="pms", target="oa", type="core", label="预算闸门", payload="预算/概算可用额度校验结果",
|
||
direction="bidirectional", interval_sec=1800, records_per_batch=42, avg_payload_kb=64,
|
||
latency_ms=180, reliability="sync", peak_hours=[9, 10, 11, 14, 15, 16, 17],
|
||
note="合同/付款审批前调用 PMS 预算闸门,审批结果回写占用与执行数。"),
|
||
dict(source="oa", target="oms", type="core", label="合同→订单", payload="合同编号、金额、客户、履约条款",
|
||
interval_sec=1800, records_per_batch=26, avg_payload_kb=96, latency_ms=220,
|
||
reliability="sync", peak_hours=[10, 11, 14, 15, 16, 17, 18],
|
||
note="合同审批通过后由 OA 推送结构化数据到 OMS 转订单。"),
|
||
dict(source="oms", target="scc", type="core", label="订单/签单回填", payload="订单状态、交付节点",
|
||
interval_sec=3600, records_per_batch=18, avg_payload_kb=48, latency_ms=260,
|
||
reliability="async", peak_hours=[9, 10, 15, 16, 17], note=None),
|
||
dict(source="scc", target="oms", type="core", label="归档转订单", payload="签单归档信息、开票抬头",
|
||
interval_sec=3600, records_per_batch=12, avg_payload_kb=40, latency_ms=240,
|
||
reliability="async", peak_hours=[16, 17, 18], note=None),
|
||
dict(source="oa", target="finance-bot", type="core", label="报销单据", payload="报销单、发票影像、成本中心",
|
||
interval_sec=900, records_per_batch=58, avg_payload_kb=220, latency_ms=320,
|
||
reliability="sync", peak_hours=[11, 12, 16, 17, 18], note="费用报销审批完成后推送财务数字助理做票据识别。"),
|
||
dict(source="finance-bot", target="kingdee", type="core", label="记账凭证", payload="凭证分录、票据号、金额",
|
||
interval_sec=3600, records_per_batch=35, avg_payload_kb=52, latency_ms=420,
|
||
reliability="async", peak_hours=[9, 10, 15, 16, 17, 18], note="识别通过的单据由财务在金蝶完成记账。"),
|
||
dict(source="dms", target="oa", type="core", label="项目信息同步", payload="定制项目主数据、里程碑",
|
||
direction="bidirectional", interval_sec=3600, records_per_batch=30, avg_payload_kb=88,
|
||
latency_ms=280, reliability="sync", peak_hours=[10, 11, 14, 15, 16],
|
||
note="定制项目信息接口保留不变,双向同步。"),
|
||
# ---------- 企业微信入口 ----------
|
||
dict(source="oa", target="wecom", type="entry", label="待办/收款群通知", payload="审批待办卡片、收款群消息",
|
||
interval_sec=300, records_per_batch=120, avg_payload_kb=12, latency_ms=160,
|
||
reliability="async", peak_hours=[9, 10, 11, 14, 15, 16, 17, 18]),
|
||
dict(source="wecom", target="finance-bot", type="entry", label="导出PDF报销", payload="移动端报销 PDF、票据照片",
|
||
interval_sec=1800, records_per_batch=20, avg_payload_kb=480, latency_ms=620,
|
||
reliability="async", peak_hours=[12, 17, 18, 19], note="员工在企微端上传 PDF,由财务助理识别。"),
|
||
dict(source="scc", target="wecom", type="entry", label="商机备案", payload="商机备案表单、客户名称",
|
||
interval_sec=1800, records_per_batch=15, avg_payload_kb=24, latency_ms=200,
|
||
reliability="sync", peak_hours=[10, 11, 15, 16, 17]),
|
||
dict(source="pms", target="wecom", type="entry", label="概算备案", payload="概算编号、项目归属",
|
||
interval_sec=3600, records_per_batch=10, avg_payload_kb=18, latency_ms=190,
|
||
reliability="sync", peak_hours=[10, 11, 14, 15]),
|
||
dict(source="wecom", target="edrs", type="entry", label="填报提醒", payload="日报催办与填报回执",
|
||
interval_sec=3600, records_per_batch=90, avg_payload_kb=8, latency_ms=150,
|
||
reliability="async", peak_hours=[9, 18, 19, 20], note="早间提醒与日终催办。"),
|
||
# ---------- MCP 取数 ----------
|
||
dict(source="unibot", target="pms", type="mcp", label="MCP 取数", payload="四算执行进度、预算占用",
|
||
direction="bidirectional", interval_sec=3600, records_per_batch=200, avg_payload_kb=180,
|
||
latency_ms=520, reliability="sync", peak_hours=[9, 10, 14, 15, 16]),
|
||
dict(source="unibot", target="oms", type="mcp", label="MCP 取数", payload="订单履约与回款进度",
|
||
direction="bidirectional", interval_sec=3600, records_per_batch=220, avg_payload_kb=196,
|
||
latency_ms=540, reliability="sync", peak_hours=[9, 10, 14, 15, 16]),
|
||
dict(source="unibot", target="scc", type="mcp", label="MCP 取数", payload="商机漏斗与签单数据",
|
||
direction="bidirectional", interval_sec=3600, records_per_batch=160, avg_payload_kb=140,
|
||
latency_ms=500, reliability="sync", peak_hours=[9, 10, 15, 16, 17]),
|
||
dict(source="unibot", target="edrs", type="mcp", label="MCP 取数", payload="日报投入工时与经营口径数据",
|
||
direction="bidirectional", interval_sec=3600, records_per_batch=180, avg_payload_kb=120,
|
||
latency_ms=480, reliability="sync", peak_hours=[9, 18, 19]),
|
||
dict(source="unibot", target="unitensor", type="mcp", label="Agent 算力中转", payload="推理请求与返回 token",
|
||
direction="bidirectional", interval_sec=60, records_per_batch=480, avg_payload_kb=320,
|
||
latency_ms=900, reliability="sync", peak_hours=list(range(8, 21)),
|
||
note="Agent 推理全部经 UniTensor 中转站。"),
|
||
# ---------- 底座能力调用 ----------
|
||
dict(source="docs", target="unitensor", type="cap", label="调用算力·统计token", payload="文档摘要/问答推理请求",
|
||
interval_sec=300, records_per_batch=320, avg_payload_kb=260, latency_ms=760,
|
||
reliability="async", peak_hours=list(range(9, 19))),
|
||
dict(source="dms", target="unitensor", type="cap", label="调用算力", payload="代码辅助推理请求",
|
||
interval_sec=600, records_per_batch=200, avg_payload_kb=210, latency_ms=700,
|
||
reliability="async", peak_hours=[10, 11, 14, 15, 16, 17]),
|
||
dict(source="finance-bot", target="k3s", type="cap", label="文件预览/OCR/对象存储", payload="发票影像、识别中间件",
|
||
interval_sec=900, records_per_batch=90, avg_payload_kb=1500, latency_ms=520,
|
||
reliability="sync", peak_hours=[11, 12, 16, 17, 18]),
|
||
dict(source="scc", target="k3s", type="cap", label="对象存储", payload="商机附件、资质材料",
|
||
interval_sec=1800, records_per_batch=45, avg_payload_kb=2200, latency_ms=580,
|
||
reliability="async", peak_hours=[10, 11, 14, 15, 16]),
|
||
dict(source="docs", target="k3s", type="cap", label="文件预览", payload="文档预览渲染对象",
|
||
interval_sec=900, records_per_batch=150, avg_payload_kb=880, latency_ms=340,
|
||
reliability="async", peak_hours=list(range(9, 19))),
|
||
dict(source="dms", target="k3s", type="cap", label="镜像仓库", payload="构建镜像层",
|
||
interval_sec=3600, records_per_batch=12, avg_payload_kb=64000, latency_ms=1200,
|
||
reliability="async", peak_hours=[11, 17, 18], note="CI 构建推送镜像,单次体量大、频次低。"),
|
||
dict(source="dms", target="gitea", type="cap", label="CI 触发", payload="流水线触发与构建回调",
|
||
direction="bidirectional", interval_sec=600, records_per_batch=35, avg_payload_kb=36,
|
||
latency_ms=280, reliability="async", peak_hours=[10, 11, 14, 15, 16, 17]),
|
||
dict(source="dms", target="dsh", type="cap", label="组件发布/拉取", payload="公共组件包版本",
|
||
interval_sec=86400, records_per_batch=6, avg_payload_kb=12000, latency_ms=1500,
|
||
reliability="async", peak_hours=[15, 16, 17], note="组件市场发布节奏按工作日估算。"),
|
||
# ---------- 统一认证 ----------
|
||
dict(source="oa", target="unihub", type="auth", label="SSO 票据校验", payload="OIDC token 交换",
|
||
interval_sec=300, records_per_batch=400, avg_payload_kb=4, latency_ms=90,
|
||
reliability="sync", peak_hours=[9, 10, 13, 14, 15, 16, 17]),
|
||
dict(source="pms", target="unihub", type="auth", label="SSO 票据校验", payload="OIDC token 交换",
|
||
interval_sec=600, records_per_batch=120, avg_payload_kb=4, latency_ms=90,
|
||
reliability="sync", peak_hours=[9, 10, 14, 15, 16]),
|
||
dict(source="oms", target="unihub", type="auth", label="SSO 票据校验", payload="OIDC token 交换",
|
||
interval_sec=600, records_per_batch=150, avg_payload_kb=4, latency_ms=95,
|
||
reliability="sync", peak_hours=[9, 10, 14, 15, 16, 17]),
|
||
dict(source="scc", target="unihub", type="auth", label="SSO 票据校验", payload="OIDC token 交换",
|
||
interval_sec=600, records_per_batch=110, avg_payload_kb=4, latency_ms=92,
|
||
reliability="sync", peak_hours=[9, 10, 14, 15, 16, 17]),
|
||
dict(source="dms", target="unihub", type="auth", label="SSO 票据校验", payload="OIDC token 交换",
|
||
interval_sec=600, records_per_batch=70, avg_payload_kb=4, latency_ms=88,
|
||
reliability="sync", peak_hours=[10, 11, 14, 15, 16]),
|
||
dict(source="docs", target="unihub", type="auth", label="SSO 票据校验", payload="OIDC token 交换",
|
||
interval_sec=600, records_per_batch=95, avg_payload_kb=4, latency_ms=86,
|
||
reliability="sync", peak_hours=list(range(9, 19))),
|
||
dict(source="gitea", target="unihub", type="auth", label="SSO 票据校验", payload="OIDC token 交换",
|
||
interval_sec=900, records_per_batch=60, avg_payload_kb=4, latency_ms=85,
|
||
reliability="sync", peak_hours=[10, 11, 14, 15, 16, 17]),
|
||
dict(source="ekb", target="unihub", type="auth", label="SSO 票据校验", payload="OIDC token 交换",
|
||
interval_sec=1800, records_per_batch=25, avg_payload_kb=4, latency_ms=90,
|
||
reliability="sync", peak_hours=[10, 11, 15, 16]),
|
||
# ---------- 归档 / 知识沉淀 ----------
|
||
dict(source="oa", target="nas", type="archive", label="盖章合同原件归档", payload="盖章合同 PDF 原件",
|
||
interval_sec=3600, records_per_batch=8, avg_payload_kb=24000, latency_ms=1800,
|
||
reliability="async", peak_hours=[16, 17, 18], note="流程走完后归档,单文件体量大。"),
|
||
dict(source="docs", target="ekb", type="archive", label="知识沉淀同步", payload="结项文档、方案模板",
|
||
interval_sec=3600, records_per_batch=22, avg_payload_kb=3600, latency_ms=900,
|
||
reliability="async", peak_hours=[17, 18, 19]),
|
||
dict(source="unibot", target="ekb", type="archive", label="企业知识检索", payload="RAG 检索与向量召回",
|
||
direction="bidirectional", interval_sec=600, records_per_batch=260, avg_payload_kb=640,
|
||
latency_ms=1100, reliability="sync", peak_hours=list(range(9, 19))),
|
||
]
|
||
|
||
DEFAULT_SETTINGS = {
|
||
"site_title": "公司 IT 系统全景与数据流向平台",
|
||
"site_subtitle": "① 系统全景总览 | ② 数据流向图(实时流动)",
|
||
"editing_enabled": True,
|
||
"animation_enabled": True,
|
||
"animation_speed": 1.0,
|
||
"live_mode": True,
|
||
"live_interval_sec": 15,
|
||
"default_range_days": 7,
|
||
"metric_seed": "it-panorama-seed-v1",
|
||
# 折线 (正交走线) reads best in a report, so it is the shipped default; 曲线 / 直线 stay one click away.
|
||
"flow_route_style": "elbow",
|
||
}
|
||
|
||
|
||
def already_seeded(conn: sqlite3.Connection) -> bool:
|
||
row = conn.execute("SELECT COUNT(*) AS c FROM systems").fetchone()
|
||
return bool(row and row["c"])
|
||
|
||
|
||
def seed(conn: sqlite3.Connection) -> bool:
|
||
"""Populate a fresh database. Returns True when seeding actually ran."""
|
||
if already_seeded(conn):
|
||
return False
|
||
|
||
now = utcnow()
|
||
with transaction(conn):
|
||
for layer in LAYERS:
|
||
conn.execute(
|
||
"INSERT INTO layers (id, name, short_name, color, description, sort_order) VALUES (?,?,?,?,?,?)",
|
||
(layer["id"], layer["name"], layer["short_name"], layer["color"], layer["description"], layer["sort_order"]),
|
||
)
|
||
|
||
for index, system in enumerate(SYSTEMS):
|
||
conn.execute(
|
||
"""INSERT INTO systems (key, name, layer_id, dept, status, tech, url, domain, owner,
|
||
description, tier, sort_order, created_at, updated_at)
|
||
VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?)""",
|
||
(
|
||
system["key"], system["name"], system["layer_id"], system.get("dept", ""),
|
||
system["status"], system.get("tech", ""), system.get("url", ""), system.get("domain", ""),
|
||
system.get("owner", ""), system["description"], system["tier"], index, now, now,
|
||
),
|
||
)
|
||
|
||
for flow_type in FLOW_TYPES:
|
||
conn.execute(
|
||
"""INSERT INTO flow_types (id, name, color, line_style, default_interval, description, sort_order)
|
||
VALUES (?,?,?,?,?,?,?)""",
|
||
(
|
||
flow_type["id"], flow_type["name"], flow_type["color"], flow_type["line_style"],
|
||
flow_type["default_interval"], flow_type["description"], flow_type["sort_order"],
|
||
),
|
||
)
|
||
|
||
for index, flow in enumerate(FLOWS):
|
||
conn.execute(
|
||
"""INSERT INTO data_flows (source_key, target_key, flow_type_id, label, payload, direction,
|
||
interval_sec, records_per_batch, avg_payload_kb, latency_ms,
|
||
reliability, peak_hours, enabled, note, sort_order, created_at, updated_at)
|
||
VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)""",
|
||
(
|
||
flow["source"], flow["target"], flow["type"], flow["label"], flow.get("payload") or "",
|
||
flow.get("direction") or "forward", flow["interval_sec"], flow["records_per_batch"],
|
||
flow["avg_payload_kb"], flow["latency_ms"], flow.get("reliability", "async"),
|
||
json_dump(flow["peak_hours"]), 1, flow.get("note") or "", index, now, now,
|
||
),
|
||
)
|
||
|
||
for key, value in DEFAULT_SETTINGS.items():
|
||
set_setting(conn, key, value)
|
||
|
||
return True
|
||
|
||
|
||
def ensure_graph_shape(conn: sqlite3.Connection) -> None:
|
||
"""Fill tier ranks derived from the flow graph when they look unset."""
|
||
rows = conn.execute("SELECT DISTINCT tier FROM systems").fetchall()
|
||
if len(rows) >= 2:
|
||
return
|
||
conn.executescript("UPDATE systems SET tier = 2;")
|