Author SHA1 Message Date
王野 6bb97211af feat(config): 添加MQTT配置支持并更新镜像配置格式
- 在agent-common-values.yaml中添加mqttCredentials配置项
- 在edge-common-values.yaml中添加mqtt服务配置
- 将镜像配置从简单字符串格式更新为包含repository和tag的对象格式
- 为开发环境和演示环境统一应用MQTT相关配置
2026-08-03 00:29:52 +08:00
57 changed files with 43 additions and 3528 deletions

No files matched your search

-110
View File
@@ -1,110 +0,0 @@
# ============================================================================
# .drone.yml — MixingX 交付晋级流水线(release-promote)— 本仓库第一条流水线
#
# 触发方式: 手动 (Drone Web 界面 → 打开 mixingx.deploy → NEW BUILD)
# 参数(可选,均有默认;Drone custom build 参数以同名环境变量注入各 step):
# RELEASE_VERSION — 交付版本号 v1.0.1;不传则自动递增 patch(查 chart 仓库上一个 tag);
# 可显式指定已存在版本(幂等复用,同版本发多客户)
# CUSTOMER — 客户目录名,默认 mxlexus(唯一客户时可省略)
# PLAN — 按服务交付计划(JSON 数组,每服务一条),示例:
# [{"service":"sso","action":"deliver","harborTag":"develop-v.1.0.1-202608250629-41"},
# {"service":"agent","action":"reuse","version":"v1.0.1"},
# {"service":"ultra","action":"keep"}]
# service: gateway/sso/ultra/audit/agent/edge;
# action: keep(缺省)/reuse(复用已交付版本)/deliver(交付 Harbor tag,
# 缺省取 demo 当前)/ci-now(行为同 deliver,release-notes 记为 ci-now)
# SERVICES — 兼容参数,逗号分隔服务名 = 这些服务 deliver(其余 keep)
# IMAGES — 兼容参数,逗号分隔 svc=harborTag = 该服务 deliver 且显式指定 tag
# (PLAN 存在时优先于 SERVICES/IMAGES;全空 = 6 服务全量交付,与改造前一致)
# CHART_ONLY — true 时只发 chart:跳过镜像基线与 retag,pin 只动 chart
# targetRevision 与 release-notes,默认 false
# RELEASE_NOTES — 发布说明,写入客户 release-notes.yaml,默认空
# DB_CHANGE — 逗号分隔服务名,本次含 DB 变更(须为本次非 keep 服务的子集),默认空
# OPERATOR — 发布操作人,默认 drone
# PROMOTE_PROTOCOLS — true 时连 protocol mock 镜像一起晋级,默认 false(现场不部署)
#
# 职责(四步,详见 ci/promote.sh;按服务部分交付设计见 hub docs/adr/0074):
# prepare: 解析 PLAN/版本号 + 生成交付基线 + 核对交付镜像清单
# retag : 基线镜像 develop-* → v1.0.x,bit 级复制推 ACR(ADR-0067,部分交付见
# hub docs/adr/0074),逐镜像记录 digest
# chart : chart 仓库 bump Chart.yaml + 打 tag chart-v1.0.x(已存在则复用跳过;
# 纯复用发布整步跳过)
# pin : release 分支客户目录按服务钉版(镜像 tag + chart tag) + release-notes.yaml
#
# 边界:
# - 不构建任何镜像(构建属于 9 个源码仓库的流水线)
# - 不触碰 deploy master(demo 写回由构建流水线负责)
# - git push 凭证走 Drone netrc 自动注入;推 ACR 走 secrets(acr_push_*)
# - 凭证禁止走构建参数(会明文进构建历史,ADR-0066)
#
# Secrets (Drone → mixingx.deploy → Settings → Secrets):
# acr_push_username / acr_push_password — ACR 推送凭证(✅ 已配置)
# harbor_username / harbor_password — Harbor 凭证(prepare 校验显式 harborTag 存在性;
# 未配置则跳过校验并警告)
# ============================================================================
kind: pipeline
type: docker
name: release-promote
trigger:
event:
- custom # 仅手动触发;push 事件(demo 写回)不触发任何东西
steps:
# ═══════════════════════════════════════════
# Step 1: 准备 — 解析 PLAN + 版本号 + 交付基线 + 镜像清单核对
# ═══════════════════════════════════════════
- name: prepare
image: 192.168.1.119:8888/mixingx/gitops-tools:latest
pull: if-not-exists
environment:
HARBOR_USER:
from_secret: harbor_username
HARBOR_PASS:
from_secret: harbor_password
commands:
- sh ci/promote.sh prepare
# ═══════════════════════════════════════════
# Step 2: 镜像晋级 — pull 119 → tag ACR → push + 记录 digest
# ═══════════════════════════════════════════
- name: retag-images
image: docker:24-dind
pull: if-not-exists
privileged: true
volumes:
- name: dockersock
path: /var/run/docker.sock
environment:
ACR_USER:
from_secret: acr_push_username
ACR_PASS:
from_secret: acr_push_password
ACR_REGISTRY: mx-imserver-registry.cn-shanghai.cr.aliyuncs.com
HARBOR_REGISTRY: 192.168.1.119:8888/mixingx
commands:
- sh ci/promote.sh retag
# ═══════════════════════════════════════════
# Step 3: chart 版本化 — bump Chart.yaml + tag chart-v1.0.x(已存在则复用)
# ═══════════════════════════════════════════
- name: chart-tag
image: 192.168.1.119:8888/mixingx/gitops-tools:latest
pull: if-not-exists
commands:
- sh ci/promote.sh chart
# ═══════════════════════════════════════════
# Step 4: 交付分支钉版 — release 分支客户目录按服务钉版 + release-notes
# ═══════════════════════════════════════════
- name: pin-release
image: 192.168.1.119:8888/mixingx/gitops-tools:latest
pull: if-not-exists
commands:
- sh ci/promote.sh pin
volumes:
- name: dockersock
host:
path: /var/run/docker.sock
-6
View File
@@ -17,12 +17,6 @@ Demo environment:
2. Apply or create `bootstrap/mixingx-demo-root.yaml`. 2. Apply or create `bootstrap/mixingx-demo-root.yaml`.
3. Argo CD will create/sync the applications under `applications/`. 3. Argo CD will create/sync the applications under `applications/`.
Dev environment (retired):
- The dev environment (namespace `mixingx-dev`, `dev.mixingx.local`) is retired; local development is covered by Aspire in `mixingx.hub`.
- Its manifests are kept inert under `applications/dev/disabled/` and `bootstrap/disabled/`; values under `environments/dev/` are kept for reference.
- See `applications/dev/README.md` for the rationale and re-enable steps.
Agent and edge fleets: Agent and edge fleets:
- `applications/agents.yaml` is an Argo CD ApplicationSet. - `applications/agents.yaml` is an Argo CD ApplicationSet.
-51
View File
@@ -1,51 +0,0 @@
apiVersion: argoproj.io/v1alpha1
kind: ApplicationSet
metadata:
name: mixingx-agents
namespace: argocd
spec:
goTemplate: true
goTemplateOptions:
- missingkey=error
generators:
- matrix:
generators:
- git:
repoURL: https://gitee.com/mixing-tech/mixingx.deploy.git
revision: develop/basic-test
files:
- path: environments/basic-test/agents.yaml
- list:
elementsYaml: '{{ .agents | toJson }}'
template:
metadata:
name: 'mixingx-agent-{{ .id }}'
spec:
project: default
sources:
- repoURL: https://gitee.com/mixing-tech/mixingx.hub.chart.git
targetRevision: master
path: release-charts/mixingx-agent-unit
helm:
releaseName: 'mixingx-agent-{{ .id }}'
valueFiles:
- $values/environments/basic-test/image-version.yaml
- $values/environments/basic-test/agent-common-values.yaml
- $values/environments/basic-test/single-node-values.yaml
values: |
site: "{{ .id }}"
description: "{{ .description }}"
phaseType: "{{ .phaseType }}"
{{- if hasKey . "nodeLabel" }}
nodeSelector:
mixingx.io/edge-node: "{{ .nodeLabel }}"
{{- end }}
- repoURL: https://gitee.com/mixing-tech/mixingx.deploy.git
targetRevision: develop/basic-test
ref: values
destination:
server: https://kubernetes.default.svc
namespace: mixingx
syncPolicy:
syncOptions:
- CreateNamespace=true
-26
View File
@@ -1,26 +0,0 @@
apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
name: mixingx-audit
namespace: argocd
spec:
project: default
sources:
- repoURL: https://gitee.com/mixing-tech/mixingx.hub.chart.git
targetRevision: master
path: release-charts/mixingx-audit
helm:
releaseName: mixingx-audit
valueFiles:
- $values/environments/basic-test/image-version.yaml
- $values/environments/basic-test/audit-values.yaml
- $values/environments/basic-test/single-node-values.yaml
- repoURL: https://gitee.com/mixing-tech/mixingx.deploy.git
targetRevision: develop/basic-test
ref: values
destination:
server: https://kubernetes.default.svc
namespace: mixingx
syncPolicy:
syncOptions:
- CreateNamespace=true
-51
View File
@@ -1,51 +0,0 @@
apiVersion: argoproj.io/v1alpha1
kind: ApplicationSet
metadata:
name: mixingx-edges
namespace: argocd
spec:
goTemplate: true
goTemplateOptions:
- missingkey=error
generators:
- matrix:
generators:
- git:
repoURL: https://gitee.com/mixing-tech/mixingx.deploy.git
revision: develop/basic-test
files:
- path: environments/basic-test/edges.yaml
- list:
elementsYaml: '{{ .edges | toJson }}'
template:
metadata:
name: 'mixingx-edge-{{ .id }}'
spec:
project: default
sources:
- repoURL: https://gitee.com/mixing-tech/mixingx.hub.chart.git
targetRevision: master
path: release-charts/mixingx-edge-unit
helm:
releaseName: 'mixingx-edge-{{ .id }}'
valueFiles:
- $values/environments/basic-test/image-version.yaml
- $values/environments/basic-test/edge-common-values.yaml
- $values/environments/basic-test/single-node-values.yaml
values: |
site: "{{ .id }}"
idWorkerId: {{ .idWorkerId }}
description: "{{ .description }}"
{{- if hasKey . "nodeLabel" }}
nodeSelector:
mixingx.io/edge-node: "{{ .nodeLabel }}"
{{- end }}
- repoURL: https://gitee.com/mixing-tech/mixingx.deploy.git
targetRevision: develop/basic-test
ref: values
destination:
server: https://kubernetes.default.svc
namespace: mixingx
syncPolicy:
syncOptions:
- CreateNamespace=true
@@ -1,19 +0,0 @@
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: gateway-ip-ingress
namespace: mixingx
annotations:
traefik.ingress.kubernetes.io/router.entrypoints: web
spec:
ingressClassName: traefik
rules:
- http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: gateway-service
port:
number: 8080
-26
View File
@@ -1,26 +0,0 @@
apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
name: mixingx-gateway
namespace: argocd
spec:
project: default
sources:
- repoURL: https://gitee.com/mixing-tech/mixingx.hub.chart.git
targetRevision: master
path: release-charts/mixingx-gateway
helm:
releaseName: mixingx-gateway
valueFiles:
- $values/environments/basic-test/image-version.yaml
- $values/environments/basic-test/gateway-values.yaml
- $values/environments/basic-test/single-node-values.yaml
- repoURL: https://gitee.com/mixing-tech/mixingx.deploy.git
targetRevision: develop/basic-test
ref: values
destination:
server: https://kubernetes.default.svc
namespace: mixingx
syncPolicy:
syncOptions:
- CreateNamespace=true
-26
View File
@@ -1,26 +0,0 @@
apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
name: mixingx-infra
namespace: argocd
spec:
project: default
sources:
- repoURL: https://gitee.com/mixing-tech/mixingx.hub.chart.git
targetRevision: master
path: release-charts/mixingx-infra
helm:
releaseName: mixingx-infra
valueFiles:
- $values/environments/basic-test/image-version.yaml
- $values/environments/basic-test/infra-values.yaml
- $values/environments/basic-test/single-node-values.yaml
- repoURL: https://gitee.com/mixing-tech/mixingx.deploy.git
targetRevision: develop/basic-test
ref: values
destination:
server: https://kubernetes.default.svc
namespace: mixingx
syncPolicy:
syncOptions:
- CreateNamespace=true
-52
View File
@@ -1,52 +0,0 @@
apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
name: longhorn
namespace: argocd
spec:
project: default
source:
repoURL: https://charts.longhorn.io
chart: longhorn
targetRevision: 1.12.0
helm:
releaseName: longhorn
values: |
global:
imageRegistry: 192.168.1.119:8888/docker-proxy
service:
ui:
type: NodePort
nodePort: 30880
preUpgradeChecker:
jobEnabled: false
upgradeVersionCheck: false
csi:
kubeletRootDir: /var/lib/kubelet
attacherReplicaCount: 1
provisionerReplicaCount: 1
resizerReplicaCount: 1
snapshotterReplicaCount: 1
persistence:
createStorageClass: true
defaultClass: false
defaultClassReplicaCount: 1
defaultDataLocality: disabled
dataEngine: v1
reclaimPolicy: Delete
volumeBindingMode: Immediate
defaultSettings:
defaultDataPath: /var/lib/longhorn/
defaultReplicaCount: '{"v1":"1","v2":"1"}'
v1DataEngine: true
v2DataEngine: false
storageReservedPercentageForDefaultDisk: 10
upgradeChecker: false
longhornUI:
replicas: 1
destination:
server: https://kubernetes.default.svc
namespace: longhorn-system
syncPolicy:
syncOptions:
- CreateNamespace=true
@@ -1,25 +0,0 @@
apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
name: mixingx-network-agent
namespace: argocd
spec:
project: default
sources:
- repoURL: https://gitee.com/mixing-tech/mixingx.hub.chart.git
targetRevision: master
path: release-charts/mixingx-network-agent
helm:
releaseName: mixingx-network-agent
valueFiles:
- $values/environments/basic-test/image-version.yaml
- $values/environments/basic-test/network-agent-values.yaml
- repoURL: https://gitee.com/mixing-tech/mixingx.deploy.git
targetRevision: develop/basic-test
ref: values
destination:
server: https://kubernetes.default.svc
namespace: mixingx
syncPolicy:
syncOptions:
- CreateNamespace=true
-26
View File
@@ -1,26 +0,0 @@
apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
name: mixingx-sso
namespace: argocd
spec:
project: default
sources:
- repoURL: https://gitee.com/mixing-tech/mixingx.hub.chart.git
targetRevision: master
path: release-charts/mixingx-sso
helm:
releaseName: mixingx-sso
valueFiles:
- $values/environments/basic-test/image-version.yaml
- $values/environments/basic-test/sso-values.yaml
- $values/environments/basic-test/single-node-values.yaml
- repoURL: https://gitee.com/mixing-tech/mixingx.deploy.git
targetRevision: develop/basic-test
ref: values
destination:
server: https://kubernetes.default.svc
namespace: mixingx
syncPolicy:
syncOptions:
- CreateNamespace=true
-26
View File
@@ -1,26 +0,0 @@
apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
name: mixingx-ultra
namespace: argocd
spec:
project: default
sources:
- repoURL: https://gitee.com/mixing-tech/mixingx.hub.chart.git
targetRevision: master
path: release-charts/mixingx-ultra
helm:
releaseName: mixingx-ultra
valueFiles:
- $values/environments/basic-test/image-version.yaml
- $values/environments/basic-test/ultra-values.yaml
- $values/environments/basic-test/single-node-values.yaml
- repoURL: https://gitee.com/mixing-tech/mixingx.deploy.git
targetRevision: develop/basic-test
ref: values
destination:
server: https://kubernetes.default.svc
namespace: mixingx
syncPolicy:
syncOptions:
- CreateNamespace=true
File renamed without changes.
-1
View File
@@ -33,7 +33,6 @@ spec:
- $values/environments/demo/edge-common-values.yaml - $values/environments/demo/edge-common-values.yaml
values: | values: |
site: "{{ .id }}" site: "{{ .id }}"
idWorkerId: {{ .idWorkerId }}
description: "{{ .description }}" description: "{{ .description }}"
{{- if hasKey . "nodeLabel" }} {{- if hasKey . "nodeLabel" }}
nodeSelector: nodeSelector:
-25
View File
@@ -1,25 +0,0 @@
apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
name: mixingx-mqttx
namespace: argocd
spec:
project: default
sources:
- repoURL: https://gitee.com/mixing-tech/mixingx.hub.chart.git
targetRevision: master
path: release-charts/mixingx-mqttx
helm:
releaseName: mixingx-mqttx
valueFiles:
- $values/environments/demo/image-version.yaml
- $values/environments/demo/mqttx-values.yaml
- repoURL: https://gitee.com/mixing-tech/mixingx.deploy.git
targetRevision: master
ref: values
destination:
server: https://kubernetes.default.svc
namespace: mixingx
syncPolicy:
syncOptions:
- CreateNamespace=true
-62
View File
@@ -1,62 +0,0 @@
# Dev 环境(已退役)
> 状态:自 2026-08-26 起退役。本目录仅保留历史配置与启用说明,Argo CD 不再同步 dev 环境。
## 为什么退役
- dev 环境的历史使命是验证 mixingx.deploy「分支 + 文件夹」GitOps 结构(master 分支 + `environments/`、`applications/` 按环境分目录)是否可行。该结构已被 demo 环境与 mxlexus 客户现场(release 分支)生产性使用,验证目的已达成。
- 本地开发由 Aspire(`aspire run`,见 mixingx.hub 仓库)完整覆盖,反馈更快,不再需要 K8s dev 环境。
- dev 使用的伞形 chart `release-charts/mixingx-platform` 是 demo 已淘汰的旧部署模式(参见 `applications/demo/disabled/platform-legacy.yaml`),与当前「每服务独立 release」的目标形态不一致。
## 保留了什么
- `disabled/` 下三个清单:`platform.yaml`(伞形平台 Application)、`agents.yaml` / `edges.yaml`(ApplicationSet)。根 Application 的目录源不递归子目录,放这里即不会被同步,与 `applications/demo/disabled/` 同一先例。
- `bootstrap/disabled/mixingx-dev-root.yaml`:dev 的 app-of-apps 根 Application。
- `environments/dev/` 下全部 values 原样保留(image-version、platform-values、agents、edges、`*-common-values`)。
注意:`mixingx-platform` chart 是 dev 唯一的消费者,退役后它在 `release-charts/` 中已无活体使用。重新启用 dev 前先确认该 chart 仍存在且受维护;若已被清理,应按 demo 的「每服务独立 release」模式重建,而不是恢复伞形模式。
## 集群侧清理(退役时执行一次)
根 Application 与子 Application 不会自动消失(root 的 syncPolicy 是 `prune: false`),需要在集群里手动删除:
```bash
kubectl -n argocd delete application mixingx-dev-root
kubectl -n argocd delete application mixingx-dev-platform mixingx-dev-agents mixingx-dev-edges
kubectl -n argocd delete application mixingx-dev-agent-demo mixingx-dev-edge-demo # ApplicationSet 生成的实例
kubectl delete namespace mixingx-dev
```
- Postgres / edge 数据盘的 PVC 带 `helm.sh/resource-policy: keep`,namespace 删除后 PV 可能残留,按需手动清理。
- 存储类(`longhorn-platform` / `longhorn-edge-local`)由 demo 的 storageclasses Application 管理,**不要删**。
## 如何重新启用
1. 前置条件:
- 集群已安装 Argo CD 并注册两个仓库(`mixingx.deploy.git`、`mixingx.hub.chart.git`)。
- 存储类存在:`kubectl get sc longhorn-platform longhorn-edge-local`(若集群上没有 demo 环境,先 apply `storageclasses/longhorn-demo.yaml`)。
- 节点标签:agent 默认调度到 `mixingx.io/edge-node=node1`、edge 到 `node2`(见 `environments/dev/agents.yaml`、`edges.yaml` 的 `nodeLabel`);按实际节点重新打标,或删掉 `nodeLabel` 字段。
- hosts/DNS:`dev.mixingx.local` 指向集群 ingress(traefik)。
- 镜像 tag:`environments/dev/image-version.yaml` 里只有一个历史分支构建的全局 tag,启用前确认 Harbor 上仍存在;不存在就先跑对应 Drone 流水线产出新 tag 再改该文件(dev 没有 CI 写回,tag 需手动维护)。
2. 恢复清单并推送:
```bash
mv applications/dev/disabled/*.yaml applications/dev/
mv bootstrap/disabled/mixingx-dev-root.yaml bootstrap/
git add -A && git commit && git push # 推到 master
```
3. 引导(根 Application 不自动创建,需手动 apply):
```bash
kubectl apply -f bootstrap/mixingx-dev-root.yaml
```
root 会建出 `mixingx-dev-platform` / `mixingx-dev-agents` / `mixingx-dev-edges` 三个子应用;子应用默认不自动 sync,需在 Argo CD UI 手动 Sync。
4. 验证:
```bash
kubectl -n mixingx-dev get pods
```
浏览器访问 `http://dev.mixingx.local`。
File renamed without changes.
@@ -33,7 +33,6 @@ spec:
- $values/environments/dev/edge-common-values.yaml - $values/environments/dev/edge-common-values.yaml
values: | values: |
site: "{{ .id }}" site: "{{ .id }}"
idWorkerId: {{ .idWorkerId }}
description: "{{ .description }}" description: "{{ .description }}"
{{- if .nodeLabel }} {{- if .nodeLabel }}
nodeSelector: nodeSelector:
File renamed without changes.
-34
View File
@@ -1,34 +0,0 @@
apiVersion: v1
kind: Namespace
metadata:
name: longhorn-system
annotations:
argocd.argoproj.io/sync-wave: "-1"
---
apiVersion: v1
kind: Namespace
metadata:
name: mixingx
annotations:
argocd.argoproj.io/sync-wave: "-1"
---
apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
name: mixingx-basic-test-root
namespace: argocd
spec:
project: default
source:
repoURL: https://gitee.com/mixing-tech/mixingx.deploy.git
targetRevision: develop/basic-test
path: applications/basic-test
destination:
server: https://kubernetes.default.svc
namespace: argocd
syncPolicy:
automated:
prune: false
selfHeal: true
syncOptions:
- CreateNamespace=true
File renamed without changes.
-25
View File
@@ -1,25 +0,0 @@
#!/bin/sh
# ============================================================================
# ci/auto-bump.sh — 交付版本号自动递增(release-promote 未传 RELEASE_VERSION 时调用)
#
# 规则: 查 chart 仓库已有 chart-vX.Y.Z tag 的最大值,patch +1;
# 无任何 tag 时从 v1.0.1 起步(与现有 appVersion 1.0.1 谱系对齐)。
# 输出: v1.0.2 这样的版本号(stdout,单行)
# ============================================================================
set -eu
CHART_REPO="${CHART_REPO:-https://gitee.com/mixing-tech/mixingx.hub.chart.git}"
latest=$(git ls-remote --tags "$CHART_REPO" 'refs/tags/chart-v*' \
| sed -E 's#.*refs/tags/chart-v##' \
| sort -t. -k1,1n -k2,2n -k3,3n | tail -1 || true)
if [ -z "$latest" ]; then
echo "v1.0.1"
exit 0
fi
major=$(echo "$latest" | cut -d. -f1)
minor=$(echo "$latest" | cut -d. -f2)
patch=$(echo "$latest" | cut -d. -f3)
patch=$((patch + 1))
echo "v${major}.${minor}.${patch}"
-721
View File
@@ -1,721 +0,0 @@
#!/bin/sh
# ============================================================================
# ci/promote.sh — 交付晋级脚本(release-promote 流水线的执行体)— ADR-0067
# 按服务计划(PLAN)部分交付,设计见 hub docs/adr/0074
#
# 子命令(由 .drone.yml 的四个 step 分别调用;状态经 $WS 下的 .release-env /
# .baseline / .digests / .plan.json 文件在 step 间传递,WS=${DRONE_WORKSPACE:-/drone/src}):
#
# prepare 解析 PLAN/RELEASE_VERSION/CUSTOMER,生成交付基线(.baseline)与规范化
# 计划(.plan.json),克隆 chart 仓库核对交付镜像清单
# retag 基线镜像 pull 119 → tag ACR:vX.Y.Z → push(bit 级复制,不重新构建),
# 逐镜像记录 digest(.digests,供 release-notes 反向追踪)
# chart chart 仓库 Chart.yaml bump + commit + tag chart-vX.Y.Z + push
# (tag 已存在则复用跳过;纯复用发布整步跳过)
# pin release 分支:按 PLAN 逐服务钉 image tag 与 chart targetRevision,
# 追加 release-notes.yaml(最新在前),push
#
# 服务计划 PLAN(JSON 数组,每服务一条;未出现的服务 = keep):
# [{"service":"sso","action":"deliver","harborTag":"develop-v.1.0.1-202608250629-41"},
# {"service":"agent","action":"reuse","version":"v1.0.1"},
# {"service":"ultra","action":"keep"}]
# service: gateway / sso / ultra / audit / agent / edge(前后端一对,共用 tag)
# action : keep(缺省,不动)
# reuse(复用已交付版本 version,镜像已在 ACR 不重推)
# deliver(harborTag 为未交付过的 Harbor tag,缺省取 demo 当前,retag 到新版本号)
# ci-now(行为同 deliver,仅 release-notes 如实记录为 ci-now)
# 兼容参数: SERVICES=sso,agent(=这些服务 deliver,其余 keep)
# IMAGES=sso=tagX(=该服务 deliver 且显式 harborTag;逗号分隔多个)
# PLAN 存在时优先;全部缺省 = 6 服务全 deliver demo 当前 tag(与改造前一致)
# protocol mock 不进 PLAN,保留 PROMOTE_PROTOCOLS 独立开关
#
# 版本号分配:
# 有 deliver/ci-now(或 CHART_ONLY=true)→ 需要新版本号(RELEASE_VERSION 缺省 auto-bump);
# chart tag 已存在不再拒绝,记 CHART_TAG_EXISTS=true 复用(幂等,可同参数重跑/同版本发多客户)
# 全部 keep/reuse(纯复用发布)→ 不分配新版本号,chart 步骤跳过,
# reuse 服务 chart targetRevision 各指已有 chart-<version>
#
# 其他参数:
# CHART_ONLY=true 只发 chart:prepare 跳过镜像基线与 Harbor 校验,retag 整步跳过,
# pin 只动 chart targetRevision 与 release-notes
# RELEASE_NOTES 发布说明,写入 release-notes.yaml 条目
# DB_CHANGE 逗号分隔服务名(须为本次非 keep 服务子集),条目 dbChange 标 true
# OPERATOR 发布操作人,默认 drone
# PROMOTE_DRY_RUN=true 本地演练:docker 与 git push 仅打印不执行
#
# 原则:
# - 交付基线 = demo 正在跑且回归过的 develop tag 组合(只读 master,不改 master)
# - 客户目录只允许本流水线写(release 分支受保护,ADR-0068)
# - 全流程幂等:ACR 重推无害、chart tag 存在即复用、pin 幂等重写,失败可同参数重跑
# ============================================================================
set -eu
WS="${DRONE_WORKSPACE:-/drone/src}"
ENV_FILE="$WS/.release-env"
BASELINE_FILE="$WS/.baseline"
DIGESTS_FILE="$WS/.digests"
PLAN_FILE="$WS/.plan.json"
PLAN_TXT_FILE="$WS/.plan.txt"
FACTS_FILE="$WS/.plan-facts"
COMMIT_MSG_FILE="$WS/.commit-msg"
CHART_DIR="$WS/.ci/chart"
DEPLOY_REPO="${DEPLOY_REPO:-https://gitee.com/mixing-tech/mixingx.deploy.git}"
CHART_REPO="${CHART_REPO:-https://gitee.com/mixing-tech/mixingx.hub.chart.git}"
CHARTS_DIR="release-charts"
HARBOR_HOST="${HARBOR_HOST:-192.168.1.119:8888}"
DRY_RUN="${PROMOTE_DRY_RUN:-false}"
log() { echo "[promote] $*"; }
die() { echo "[promote] 错误: $*" >&2; exit 1; }
# 任意字符串 → shell source 安全的单引号字面量(内部 ' 转义为 '\'' )
shq() { printf "'%s'" "$(printf '%s' "$1" | sed "s/'/'\\\\''/g")"; }
# 外部副作用命令(推镜像/推 git)统一走这里:PROMOTE_DRY_RUN=true 时只打印
run() {
if [ "$DRY_RUN" = "true" ]; then
log "[dry-run] $*"
else
"$@"
fi
}
git_setup() {
git config --global url."https://gitee.com/".insteadOf "git@gitee.com:" 2>/dev/null || true
git config user.name "Drone Release"
git config user.email "drone-release@mixingx.local"
}
require_env() {
[ -f "$ENV_FILE" ] || die "缺少 $ENV_FILE,请先运行 prepare 步骤"
. "$ENV_FILE"
[ -n "${CUSTOMER:-}" ] || die "$ENV_FILE 内容不完整(缺 CUSTOMER)"
CHART_ONLY="${CHART_ONLY:-false}"
PURE_REUSE="${PURE_REUSE:-false}"
OPERATOR="${OPERATOR:-drone}"
RELEASE_NOTES="${RELEASE_NOTES:-}"
DB_CHANGE="${DB_CHANGE:-}"
PLAN="${PLAN:-}"
# 纯复用发布没有新版本号,RELEASE_VERSION/CHART_TAG 允许为空
if [ "$PURE_REUSE" != "true" ]; then
[ -n "${RELEASE_VERSION:-}" ] && [ -n "${CHART_TAG:-}" ] \
|| die "$ENV_FILE 内容不完整(缺 RELEASE_VERSION/CHART_TAG)"
fi
}
# ─────────────────────────────────────────────
# prepare
# ─────────────────────────────────────────────
do_prepare() {
# 客户解析:客户目录在 release 分支上(工作区是 master,不含客户目录)
# 唯一客户目录时可省略 CUSTOMER;多客户时不填即拒绝(防发错现场)
git fetch -q origin release || die "release 分支不存在,请先推送初始 release 分支"
CUSTOMERS=$(git ls-tree --name-only "origin/release" environments/ 2>/dev/null \
| sed 's#^environments/##' | sed 's#/$##' | grep -vE '^(_common|demo|dev)$' || true)
C_COUNT=$(printf '%s\n' "$CUSTOMERS" | grep -c . || true)
if [ -z "${CUSTOMER:-}" ]; then
if [ "$C_COUNT" = "1" ]; then
CUSTOMER="$CUSTOMERS"
log "未指定 CUSTOMER,唯一客户目录: $CUSTOMER"
else
die "检测到 ${C_COUNT} 个客户目录,不填 CUSTOMER 无法确定发给谁。现有客户: $(printf '%s ' $CUSTOMERS)"
fi
fi
printf '%s\n' "$CUSTOMERS" | grep -qx "$CUSTOMER" \
|| die "environments/$CUSTOMER 不在 release 分支上。现有客户: $(printf '%s ' $CUSTOMERS)"
CHART_ONLY="${CHART_ONLY:-false}"
case "$CHART_ONLY" in
true|false) : ;;
*) die "CHART_ONLY 只接受 true/false,收到: $CHART_ONLY" ;;
esac
export CHART_ONLY
# ── 解析服务计划(PLAN / 兼容参数 SERVICES、IMAGES / 缺省全量 deliver)──
# 产物:.plan.json(规范化全量计划,pin 步骤消费)、.plan-facts(HAS_DELIVER)、
# .plan.txt(PLAN JSON 原文留痕)、.baseline(仅 deliver/ci-now 服务的 repo)
python3 - "$WS/environments/demo/image-version.yaml" "$BASELINE_FILE" \
"$PLAN_FILE" "$FACTS_FILE" "$PLAN_TXT_FILE" <<'PY'
import base64, json, os, re, sys, urllib.error, urllib.request
import yaml
demo_path, baseline_path, plan_path, facts_path, plantxt_path = sys.argv[1:6]
CHART_ONLY = os.environ.get("CHART_ONLY", "false") == "true"
WITH_PROTOCOLS = os.environ.get("PROMOTE_PROTOCOLS", "false") == "true"
HARBOR_HOST = os.environ.get("HARBOR_HOST", "192.168.1.119:8888")
# ── 服务映射常量表(pin 步骤经 .plan.json 继承同一份定义,勿另起副本)──
ALL = ["gateway", "sso", "ultra", "audit", "agent", "edge"]
ACTIONS = ["keep", "reuse", "deliver", "ci-now"]
# 服务 → 镜像 repo 列表(前后端共用同一 tag)
REPOS = {
"gateway": ["gateway"],
"sso": ["sso", "sso-web"],
"ultra": ["ultra", "ultra-web"],
"audit": ["audit", "audit-web"],
"agent": ["agent", "agent-web"],
"edge": ["edge", "edge-web"],
}
# 服务 → image-version.yaml 中 images 下的 key 列表
KEYS = {
"gateway": ["gateway"],
"sso": ["sso", "ssoWeb"],
"ultra": ["ultra", "ultraWeb"],
"audit": ["audit", "auditWeb"],
"agent": ["agent", "agentWeb"],
"edge": ["edge", "edgeWeb"],
}
# 服务 → applications/<客户>/ 下的 Application 文件
APPFILE = {
"gateway": "gateway.yaml",
"sso": "sso.yaml",
"ultra": "ultra.yaml",
"audit": "audit.yaml",
"agent": "agents.yaml",
"edge": "edges.yaml",
}
def die(msg):
sys.exit("[promote] 错误: " + msg)
data = yaml.safe_load(open(demo_path, encoding="utf-8")) or {}
images = data.get("images") or {}
def demo_tag(svc):
"""deliver/ci-now 缺省 harborTag = demo 当前 tag(前后端应共用同一 tag)"""
tags = []
for k in KEYS[svc]:
node = images.get(k)
if not isinstance(node, dict) or not node.get("tag"):
die(f"demo image-version 缺少 images.{k}.tag,无法取 {svc} 的 demo 当前 tag")
tags.append(str(node["tag"]))
if len(set(tags)) != 1:
die(f"demo image-version 中 {svc} 前后端 tag 不一致({', '.join(tags)}),请显式指定 harborTag")
return tags[0]
# ── 1. 解析 PLAN / 兼容参数 / 缺省 ──
raw_plan = (os.environ.get("PLAN") or "").strip()
entries = []
if raw_plan:
try:
plan = json.loads(raw_plan)
except json.JSONDecodeError as e:
die(f"PLAN JSON 解析失败: {e}")
if not isinstance(plan, list):
die('PLAN 应为 JSON 数组,每服务一条 {"service":..., "action":...}')
for i, e in enumerate(plan):
if not isinstance(e, dict) or "service" not in e:
die(f"PLAN[{i}] 应为对象且含 service 字段")
entries.append(dict(e))
else:
selected = {}
for s in (os.environ.get("SERVICES") or "").split(","):
s = s.strip()
if s:
selected[s] = None # deliver,缺省 demo 当前 tag
for item in (os.environ.get("IMAGES") or "").split(","):
item = item.strip()
if not item:
continue
if "=" not in item:
die(f"IMAGES 条目应为 svc=harborTag,收到: {item}")
s, t = item.split("=", 1)
selected[s.strip()] = t.strip() or None
if selected:
for s, t in selected.items():
e = {"service": s, "action": "deliver"}
if t:
e["harborTag"] = t
entries.append(e)
else:
# 全部缺省 = 6 服务全 deliver demo 当前 tag(行为与改造前一致)
entries = [{"service": s, "action": "deliver"} for s in ALL]
# ── 2. 校验 + 规范化为全量 6 服务计划 ──
norm, seen = {}, set()
for e in entries:
svc = e.get("service")
if svc not in ALL:
die(f"非法服务名: {svc}(合法值: {', '.join(ALL)})")
if svc in seen:
die(f"PLAN 中服务重复: {svc}")
seen.add(svc)
action = e.get("action", "keep")
if action not in ACTIONS:
die(f"非法 action: {action}(合法值: {', '.join(ACTIONS)})")
n = {"service": svc, "action": action,
"repos": REPOS[svc], "keys": KEYS[svc], "appFile": APPFILE[svc]}
if action == "reuse":
ver = str(e.get("version") or "")
if not re.fullmatch(r"v\d+\.\d+\.\d+", ver):
die(f"reuse 服务 {svc} 需提供 version(vX.Y.Z),收到: {ver or '(空)'}")
n["version"] = ver
elif action in ("deliver", "ci-now"):
tag = str(e.get("harborTag") or "").strip()
n["harborTag"] = tag or demo_tag(svc)
n["harborTagExplicit"] = bool(tag)
norm[svc] = n
plan_out = [norm.get(s) or {"service": s, "action": "keep",
"repos": REPOS[s], "keys": KEYS[s], "appFile": APPFILE[s]}
for s in ALL]
has_deliver = any(e["action"] in ("deliver", "ci-now") for e in plan_out)
# ── 3. DB_CHANGE 校验:逗号分隔服务名,须为本次非 keep 服务的子集 ──
db_change = [s.strip() for s in (os.environ.get("DB_CHANGE") or "").split(",") if s.strip()]
nonkeep = {e["service"] for e in plan_out if e["action"] != "keep"}
for s in db_change:
if s not in ALL:
die(f"DB_CHANGE 含非法服务名: {s}(合法值: {', '.join(ALL)})")
if s not in nonkeep:
die(f"DB_CHANGE 服务 {s} 本次为 keep,不在交付范围内(非 keep 服务: {', '.join(sorted(nonkeep)) or '无'})")
# ── 4. deliver/ci-now 显式 harborTag 的 Harbor 存在性校验 ──
explicit = [e for e in plan_out
if e["action"] in ("deliver", "ci-now") and e.get("harborTagExplicit")]
h_user, h_pass = os.environ.get("HARBOR_USER"), os.environ.get("HARBOR_PASS")
if explicit and not (h_user and h_pass):
print("[promote] 警告: 未提供 HARBOR_USER/HARBOR_PASS,跳过显式 harborTag 的 Harbor 存在性校验")
elif explicit:
auth = base64.b64encode(f"{h_user}:{h_pass}".encode()).decode()
for e in explicit:
for repo in e["repos"]:
url = f"http://{HARBOR_HOST}/v2/mixingx/{repo}/manifests/{e['harborTag']}"
req = urllib.request.Request(url, headers={
"Accept": "application/vnd.docker.distribution.manifest.v2+json",
"Authorization": f"Basic {auth}"})
try:
with urllib.request.urlopen(req, timeout=15) as r:
if r.status != 200:
die(f"Harbor 校验 {repo}:{e['harborTag']} 返回 HTTP {r.status}")
except urllib.error.HTTPError as ex:
if ex.code == 404:
die(f"Harbor 上不存在镜像 {repo}:{e['harborTag']}(服务 {e['service']}),请核对 harborTag")
die(f"Harbor 校验 {repo}:{e['harborTag']} 失败: HTTP {ex.code}")
except urllib.error.URLError as ex:
die(f"无法连接 Harbor 校验 {repo}:{e['harborTag']}: {ex.reason}")
print(f"[promote] Harbor 存在性校验通过({len(explicit)} 个显式 harborTag)")
# ── 5. 交付基线(仅 deliver/ci-now 服务;CHART_ONLY 跳过)──
if not CHART_ONLY:
baseline = []
for e in plan_out:
if e["action"] in ("deliver", "ci-now"):
for repo in e["repos"]:
baseline.append(f"{repo} {e['harborTag']}")
# protocol mock 不进 PLAN,沿用 PROMOTE_PROTOCOLS 独立开关;
# 纯复用发布没有新版本号可钉,protocol 一并跳过
if WITH_PROTOCOLS:
if has_deliver:
for name, node in (images.get("protocol") or {}).items():
if isinstance(node, dict) and node.get("repository") and node.get("tag"):
baseline.append(f"{node['repository']} {node['tag']}")
print("[promote] PROMOTE_PROTOCOLS=true:protocol 镜像一并晋级")
else:
print("[promote] 警告: 纯复用发布无新版本号,PROMOTE_PROTOCOLS 本次不生效")
open(baseline_path, "w", encoding="utf-8").write("\n".join(baseline) + ("\n" if baseline else ""))
if baseline:
print(f"[promote] 交付基线 {len(baseline)} 个镜像: " + ", ".join(l.split()[0] for l in baseline))
else:
print("[promote] 交付基线为空(无 deliver/ci-now 服务)")
else:
print("[promote] CHART_ONLY=true:跳过镜像基线生成")
# ── 6. 落盘:.plan.json / .plan-facts / .plan.txt ──
json.dump(plan_out, open(plan_path, "w", encoding="utf-8"), ensure_ascii=False, indent=1)
open(facts_path, "w", encoding="utf-8").write("HAS_DELIVER=%s\n" % ("true" if has_deliver else "false"))
# PLAN JSON 原文(未提供时写规范化后的等价 JSON),仅作审计留痕;pin 实际消费 .plan.json
open(plantxt_path, "w", encoding="utf-8").write(raw_plan or json.dumps(plan_out, ensure_ascii=False))
for e in plan_out:
if e["action"] == "keep":
continue
print(f"[promote] 计划: {e['service']:<8} {e['action']:<8} {e.get('harborTag') or e.get('version') or ''}")
print(f"[promote] DB 变更服务: {', '.join(db_change) or '无'}")
PY
. "$FACTS_FILE" # HAS_DELIVER=true|false
# ── 版本号与 chart tag 分配 ──
GIVEN_VERSION="${RELEASE_VERSION:-}"
if [ "$HAS_DELIVER" = "true" ] || [ "$CHART_ONLY" = "true" ]; then
RELEASE_VERSION="${GIVEN_VERSION:-$(sh ci/auto-bump.sh)}"
case "$RELEASE_VERSION" in
v[0-9]*.[0-9]*.[0-9]*) : ;;
*) die "RELEASE_VERSION 格式应为 vX.Y.Z,收到: $RELEASE_VERSION" ;;
esac
CHART_TAG="chart-$RELEASE_VERSION"
# chart tag 已存在不再拒绝:幂等复用(同参数重跑/同一版本发多个客户)
if git ls-remote --tags "$CHART_REPO" "refs/tags/$CHART_TAG" | grep -q .; then
CHART_TAG_EXISTS=true
log "$CHART_TAG 已存在于 chart 仓库,复用(幂等)"
else
CHART_TAG_EXISTS=false
fi
PURE_REUSE=false
log "交付版本: $RELEASE_VERSION 客户: $CUSTOMER chart tag: $CHART_TAG"
else
# 纯复用发布(全部 keep/reuse):不需要新版本号,chart 步骤整体跳过
RELEASE_VERSION=""; CHART_TAG=""; CHART_TAG_EXISTS=false; PURE_REUSE=true
[ -z "$GIVEN_VERSION" ] || log "警告: 纯复用发布不需要新版本号,已忽略传入的 $GIVEN_VERSION"
log "纯复用发布(无 deliver/ci-now):不分配新版本号,chart 步骤将跳过"
fi
# 克隆 chart 仓库(供 chart 步骤复用)并核对交付镜像清单
rm -rf "$WS/.ci"; mkdir -p "$WS/.ci"
git clone -q "$CHART_REPO" "$CHART_DIR"
python3 - "$CHART_DIR/delivery/image-manifest.yaml" <<'PY'
import sys, yaml
m = yaml.safe_load(open(sys.argv[1], encoding="utf-8")) or {}
missing = [e["acr"] for e in m.get("thirdParty", [])
if not e.get("optional") and not e.get("pushed")]
if missing:
sys.exit("[promote] 错误: 交付镜像清单存在未推送 ACR 的非可选镜像: " + ", ".join(missing) +
"\n 请先按 D2 用 cr_temp_user 临时 token 补推,再执行发布")
print("[promote] 交付镜像清单核对通过(第三方镜像齐备)")
PY
OPERATOR="${OPERATOR:-drone}"
RELEASE_NOTES="${RELEASE_NOTES:-}"
DB_CHANGE="${DB_CHANGE:-}"
# .release-env 是 shell source 的:自由文本值一律经 shq 单引号转义,防注入/断行
{
echo "RELEASE_VERSION=$(shq "$RELEASE_VERSION")"
echo "CUSTOMER=$(shq "$CUSTOMER")"
echo "CHART_TAG=$(shq "$CHART_TAG")"
echo "CHART_TAG_EXISTS=$CHART_TAG_EXISTS"
echo "CHART_ONLY=$CHART_ONLY"
echo "PURE_REUSE=$PURE_REUSE"
echo "OPERATOR=$(shq "$OPERATOR")"
echo "RELEASE_NOTES=$(shq "$RELEASE_NOTES")"
echo "DB_CHANGE=$(shq "$DB_CHANGE")"
echo "PLAN=$(shq "$(cat "$PLAN_TXT_FILE")")"
} > "$ENV_FILE"
log "prepare 完成"
}
# ─────────────────────────────────────────────
# retag
# ─────────────────────────────────────────────
do_retag() {
require_env
if [ "$CHART_ONLY" = "true" ]; then
log "CHART_ONLY=true,镜像晋级整步跳过"
exit 0
fi
if [ ! -s "$BASELINE_FILE" ]; then
log "交付基线为空(纯复用发布或无 deliver/ci-now 服务),无镜像需晋级"
exit 0
fi
if [ "$DRY_RUN" = "true" ]; then
ACR_REGISTRY="${ACR_REGISTRY:-acr.example.com}"
HARBOR_REGISTRY="${HARBOR_REGISTRY:-harbor.example.com/mixingx}"
log "[dry-run] 跳过 ACR 登录,docker 命令仅打印"
else
: "${ACR_REGISTRY:?缺少 ACR_REGISTRY}"
: "${HARBOR_REGISTRY:?缺少 HARBOR_REGISTRY}"
: "${ACR_USER:?缺少 acr_push_username secret}"
: "${ACR_PASS:?缺少 acr_push_password secret}"
# 推 ACR 必须用 docker(ctr 有 blob unknown 问题,见底座 runbook)
printf %s "$ACR_PASS" | docker login "$ACR_REGISTRY" -u "$ACR_USER" --password-stdin \
|| die "ACR 登录失败(检查 secrets 与实例访问授权)"
fi
: > "$DIGESTS_FILE"
while IFS=' ' read -r repo tag; do
[ -n "$repo" ] || continue
log "晋级 $repo:$tag → mixingx/$repo:$RELEASE_VERSION"
if [ "$DRY_RUN" = "true" ]; then
run docker pull "$HARBOR_REGISTRY/$repo:$tag"
run docker tag "$HARBOR_REGISTRY/$repo:$tag" "$ACR_REGISTRY/mixingx/$repo:$RELEASE_VERSION"
run docker push "$ACR_REGISTRY/mixingx/$repo:$RELEASE_VERSION"
run docker rmi "$HARBOR_REGISTRY/$repo:$tag" "$ACR_REGISTRY/mixingx/$repo:$RELEASE_VERSION"
digest="sha256:dryrun-$repo"
else
docker pull "$HARBOR_REGISTRY/$repo:$tag" || die "拉取失败: $repo:$tag(119 上是否存在?)"
docker tag "$HARBOR_REGISTRY/$repo:$tag" "$ACR_REGISTRY/mixingx/$repo:$RELEASE_VERSION"
docker push "$ACR_REGISTRY/mixingx/$repo:$RELEASE_VERSION" || die "推送失败: $repo"
docker rmi "$HARBOR_REGISTRY/$repo:$tag" "$ACR_REGISTRY/mixingx/$repo:$RELEASE_VERSION" >/dev/null 2>&1 || true
# 记录 ACR 镜像 digest(供 release-notes 反向追踪);取不到则写空并警告,不 fail
digest=$(docker buildx imagetools inspect "$ACR_REGISTRY/mixingx/$repo:$RELEASE_VERSION" 2>/dev/null \
| awk '/^Digest:/ {print $2; exit}' || true)
[ -n "$digest" ] || log "警告: 未取到 $repo:$RELEASE_VERSION 的 digest,release-notes 将留空"
fi
printf '%s %s\n' "$repo" "${digest:-}" >> "$DIGESTS_FILE"
done < "$BASELINE_FILE"
log "镜像晋级完成: $(wc -l < "$BASELINE_FILE" | tr -d ' ') 个 → $ACR_REGISTRY/mixingx/*:$RELEASE_VERSION"
}
# ─────────────────────────────────────────────
# chart
# ─────────────────────────────────────────────
do_chart() {
require_env
git_setup
if [ "$PURE_REUSE" = "true" ]; then
log "纯复用发布(无 deliver/ci-now),不需要新 chart tag,chart 步骤跳过"
exit 0
fi
# 幂等:tag 已存在即复用,跳过整个 bump/tag/push(同参数重跑/同版本发多客户)
if git ls-remote --tags "$CHART_REPO" "refs/tags/$CHART_TAG" | grep -q .; then
log "$CHART_TAG 已存在于 chart 仓库,复用(幂等),跳过 bump/tag/push"
exit 0
fi
[ -d "$CHART_DIR/.git" ] || { rm -rf "$CHART_DIR"; git clone -q "$CHART_REPO" "$CHART_DIR"; }
cd "$CHART_DIR"
VER="${RELEASE_VERSION#v}"
for f in $CHARTS_DIR/*/Chart.yaml; do
python3 - "$f" "$VER" <<'PY'
import sys, re
path, ver = sys.argv[1], sys.argv[2]
t = open(path, encoding="utf-8").read()
t = re.sub(r'(?m)^version:\s*\S+', f'version: {ver}', t)
t = re.sub(r'(?m)^appVersion:\s*"?[^"\n]+"?', f'appVersion: "{ver}"', t)
open(path, "w", encoding="utf-8").write(t)
PY
done
git add -A
git diff --cached --quiet && die "Chart.yaml 无变化,异常(版本号相同?)"
git commit -q -m "release: bump chart version to $RELEASE_VERSION"
git tag "$CHART_TAG"
run git push -q origin HEAD:master "refs/tags/$CHART_TAG" || die "chart 仓库 push 失败(netrc 凭证?)"
N=$(ls -d $CHARTS_DIR/*/ | wc -l | tr -d ' ')
log "chart 已发布: $CHART_TAG($N 个 chart version=$VER)"
}
# ─────────────────────────────────────────────
# pin
# ─────────────────────────────────────────────
do_pin() {
require_env
git_setup
cd "$WS"
git fetch -q origin release || die "release 分支不存在,请先推送初始 release 分支(改造清单 B1)"
git checkout -q -B release origin/release
ENVDIR="environments/$CUSTOMER"
APPDIR="applications/$CUSTOMER"
[ -d "$ENVDIR" ] || die "客户目录不存在: $ENVDIR"
[ -d "$APPDIR" ] || die "客户目录不存在: $APPDIR"
[ -f "$PLAN_FILE" ] || die "缺少 $PLAN_FILE,请先运行 prepare 步骤"
export CUSTOMER RELEASE_VERSION CHART_TAG CHART_ONLY PURE_REUSE OPERATOR RELEASE_NOTES DB_CHANGE
python3 - "$ENVDIR" "$APPDIR" "$PLAN_FILE" "$DIGESTS_FILE" "$COMMIT_MSG_FILE" <<'PY'
import json, os, re, sys
from datetime import date as date_type, datetime, timedelta, timezone
import yaml
envdir, appdir, plan_path, digests_path, commit_msg_path = sys.argv[1:6]
CUSTOMER = os.environ.get("CUSTOMER", "")
RELEASE_VERSION = os.environ.get("RELEASE_VERSION", "")
CHART_TAG = os.environ.get("CHART_TAG", "")
CHART_ONLY = os.environ.get("CHART_ONLY", "false") == "true"
PURE_REUSE = os.environ.get("PURE_REUSE", "false") == "true"
OPERATOR = os.environ.get("OPERATOR", "drone")
NOTES = os.environ.get("RELEASE_NOTES", "")
DB_CHANGE = [s for s in os.environ.get("DB_CHANGE", "").split(",") if s]
plan = json.load(open(plan_path, encoding="utf-8"))
actions = [e for e in plan if e["action"] != "keep"]
has_deliver = any(e["action"] in ("deliver", "ci-now") for e in plan)
# 平台 Application(infra/mqttx)不属于 PLAN 服务映射,跟随每次新 chart tag
# (保持旧版全量 sed 行为:全量交付时与改造前逐字节一致;纯复用发布无新 tag 则不动)
PLATFORM_APPFILES = ["infra.yaml", "mqttx.yaml"]
# retag 步骤记录的 ACR 镜像 digest,repo → digest(取不到的行第二列为空)
digests = {}
if os.path.exists(digests_path):
for line in open(digests_path, encoding="utf-8"):
parts = line.split()
if parts:
digests[parts[0]] = parts[1] if len(parts) > 1 else ""
iv_path = os.path.join(envdir, "image-version.yaml")
rn_path = os.path.join(envdir, "release-notes.yaml")
# ── 1) image-version.yaml:只钉非 keep 服务的 key(CHART_ONLY 不动镜像文件)──
from_tags, to_tags = {}, {}
if not CHART_ONLY:
data = yaml.safe_load(open(iv_path, encoding="utf-8")) or {}
images = data.get("images") or {}
for e in actions:
svc = e["service"]
new_tag = RELEASE_VERSION if e["action"] in ("deliver", "ci-now") else e["version"]
to_tags[svc] = new_tag
for i, key in enumerate(e["keys"]):
node = images.get(key)
if not isinstance(node, dict) or "tag" not in node:
sys.exit(f"[promote] 错误: {iv_path} 缺少 images.{key}.tag,无法为 {svc} 钉版")
if i == 0:
from_tags[svc] = str(node["tag"]) # 旧值留作 release-notes 的 from
node["tag"] = new_tag
print(f"[promote] {svc}: image {from_tags[svc]} → {new_tag}")
# images.protocol 幂等清理(客户现场本不该有 protocol mock)
images.pop("protocol", None)
# 顶层 tag 只在有 deliver/ci-now 时跟随新版本号;纯复用保持原值
if has_deliver:
data["tag"] = RELEASE_VERSION
yaml.safe_dump(data, open(iv_path, "w", encoding="utf-8"),
default_flow_style=False, sort_keys=False, allow_unicode=True)
print(f"[promote] {iv_path} 钉版完成(未选中服务原样保留)")
else:
print("[promote] CHART_ONLY=true:image-version.yaml 不动")
# ── 2) applications chart targetRevision:只处理非 keep 服务对应的文件 ──
# (语义等价于按文件 sed,用 python 实现以便与 PLAN 共用服务→文件映射)
chart_from, chart_to = {}, {}
def retarget(path, new_ref, required):
if not os.path.exists(path):
if required:
sys.exit(f"[promote] 错误: 缺少 Application 文件 {path}")
print(f"[promote] 警告: {path} 不存在,跳过")
return None
text = open(path, encoding="utf-8").read()
m = re.search(r"chart-v\d+\.\d+\.\d+", text)
if not m:
if required:
sys.exit(f"[promote] 错误: {path} 中未找到 chart-vX.Y.Z targetRevision")
print(f"[promote] 警告: {path} 中未找到 chart-vX.Y.Z targetRevision,跳过")
return None
old_ref = m.group(0)
new_text = re.sub(r"chart-v\d+\.\d+\.\d+", new_ref, text)
if new_text != text:
open(path, "w", encoding="utf-8").write(new_text)
print(f"[promote] {path}: {old_ref} → {new_ref}")
return old_ref, new_ref
for e in actions:
new_ref = CHART_TAG if e["action"] in ("deliver", "ci-now") else f"chart-{e['version']}"
r = retarget(os.path.join(appdir, e["appFile"]), new_ref, required=True)
if r:
chart_from[e["service"]], chart_to[e["service"]] = r
# 平台文件跟随新 chart tag(纯复用发布无新版本号,不动)
if not PURE_REUSE:
for f in PLATFORM_APPFILES:
retarget(os.path.join(appdir, f), CHART_TAG, required=False)
# ── 3) release-notes.yaml:追加日志,新条目插 releases 列表最前 ──
rn = {}
if os.path.exists(rn_path):
rn = yaml.safe_load(open(rn_path, encoding="utf-8")) or {}
if not isinstance(rn, dict):
rn = {}
releases = rn.get("releases")
if not isinstance(releases, list):
releases = []
# safe_load 会把 ISO8601 date 解析成 datetime,重新落盘前归一化回原字符串,保证幂等
for rel in releases:
d = rel.get("date") if isinstance(rel, dict) else None
if isinstance(d, datetime):
rel["date"] = d.replace(microsecond=0).isoformat()
elif isinstance(d, date_type):
rel["date"] = d.isoformat()
def find_reuse_source(svc, version):
"""reuse 服务的 sourceTag/digest 从既有 release-notes 中该服务该版本的条目拷贝"""
for rel in releases:
for s in (rel.get("services") or []):
if s.get("name") == svc and str(s.get("to")) == version:
return str(s.get("sourceTag") or ""), str(s.get("digest") or "")
return "", ""
svc_entries, src_tags = [], {}
for e in actions:
svc, action = e["service"], e["action"]
if CHART_ONLY:
# CHART_ONLY 条目:from/to 记 chart tag 变化,sourceTag/digest 留空
frm, to = chart_from.get(svc, ""), chart_to.get(svc, "")
source_tag = digest = ""
elif action in ("deliver", "ci-now"):
frm, to = from_tags.get(svc, ""), to_tags.get(svc, "")
source_tag = e.get("harborTag", "")
# 前后端共用同一 tag,digest 取首个 repo(后端)
digest = digests.get(e["repos"][0], "")
if not digest:
print(f"[promote] 警告: {svc} 未取到镜像 digest,release-notes 留空")
else: # reuse
frm, to = from_tags.get(svc, ""), e["version"]
source_tag, digest = find_reuse_source(svc, e["version"])
if not source_tag and not digest:
print(f"[promote] 警告: 既往 release-notes 中未找到 {svc} {e['version']} 的交付记录,"
f"sourceTag/digest 留空")
src_tags[svc] = source_tag
svc_entries.append({"name": svc, "action": action, "from": frm, "to": to,
"sourceTag": source_tag, "digest": digest,
"dbChange": svc in DB_CHANGE})
if svc_entries or NOTES.strip():
now = datetime.now(timezone(timedelta(hours=8))).replace(microsecond=0).isoformat()
releases.insert(0, {"date": now, "operator": OPERATOR, "notes": NOTES,
"services": svc_entries})
rn["releases"] = releases
yaml.safe_dump(rn, open(rn_path, "w", encoding="utf-8"),
default_flow_style=False, sort_keys=False, allow_unicode=True)
print(f"[promote] {rn_path} 已追加发布记录({len(svc_entries)} 个服务)")
else:
print("[promote] 全部服务 keep 且无 RELEASE_NOTES,release-notes 不变")
# ── 4) db-scripts 检查(只警告不 fail)──
# 2b 改造后:sso/agent/ultra 构建流水线在构建时生成幂等迁移 SQL,以 harbor tag 命名
# 存放于仓库根 db-scripts/<svc>/(如 db-scripts/sso/develop-v.1.0.1-xxx.sql),pin 时带至 release
for svc in DB_CHANGE:
d = os.path.join("db-scripts", svc)
st = src_tags.get(svc, "")
hit = os.path.isdir(d) and bool(st) and any(st in f for f in os.listdir(d))
if not hit:
print(f"[promote] 警告: {svc} 声明了 DB 变更,但 db-scripts/{svc}/ 下未找到与 "
f"{st or '(无 sourceTag)'} 对应的脚本,请确认迁移 SQL 已随构建流水线写回")
# ── 5) commit message:服务清单(action/from→to)与 RELEASE_NOTES ──
if PURE_REUSE:
title = f"release: {CUSTOMER} 纯复用发布(无新版本号)"
elif CHART_ONLY:
title = f"release: {CUSTOMER} chart 交付 {CHART_TAG}(CHART_ONLY)"
else:
title = f"release: {CUSTOMER} 交付 {RELEASE_VERSION}({CHART_TAG})"
lines = [title, "", "服务清单:"]
for e in svc_entries:
seg = f"- {e['name']}: {e['action']} {e['from']} → {e['to']}"
if e["sourceTag"]:
seg += f"(source: {e['sourceTag']})"
if e["dbChange"]:
seg += " [db-change]"
lines.append(seg)
if not svc_entries:
lines.append("- (无服务变更)")
kept = [e["service"] for e in plan if e["action"] == "keep"]
if kept:
lines.append(f"其余服务保持现状(keep): {', '.join(kept)}")
if NOTES.strip():
lines += ["", f"release-notes: {NOTES}"]
lines += ["", f"operator: {OPERATOR}"]
open(commit_msg_path, "w", encoding="utf-8").write("\n".join(lines) + "\n")
PY
git add "$ENVDIR" "$APPDIR"
if git diff --cached --quiet; then
# 纯 keep(且无 release-notes 变化)是合法空操作,明确提示而非困惑报错
log "本次发布为空操作(全部服务 keep 且无 release-notes 等变化),release 分支未产生提交"
exit 0
fi
git commit -q -F "$COMMIT_MSG_FILE"
run git push -q origin release || die "release 分支 push 失败(分支保护?netrc 凭证?)"
log "交付分支已更新: environments/$CUSTOMER"
log ""
log "════════ 发布完成 ════════"
if [ "$PURE_REUSE" = "true" ]; then
log "纯复用发布(无新版本号)"
else
log "版本: $RELEASE_VERSION (chart: $CHART_TAG)"
fi
log "现场: ArgoCD 约 3 分钟内自动 sync"
}
case "${1:-}" in
prepare) do_prepare ;;
retag) do_retag ;;
chart) do_chart ;;
pin) do_pin ;;
*) echo "用法: promote.sh prepare|retag|chart|pin" >&2; exit 1 ;;
esac
@@ -1,268 +0,0 @@
-- MixingX SSO idempotent migration script (PostgreSQL)
-- Image tag: develop-v.1.0.1-202608270652-42
-- Generated by CI: dotnet ef migrations script --idempotent
-- Apply manually per ADR-0074 (生产 DB 变更全人工).
-- ===== ApplicationDbContext =====
CREATE TABLE IF NOT EXISTS "__EFMigrationsHistory" (
"MigrationId" character varying(150) NOT NULL,
"ProductVersion" character varying(32) NOT NULL,
CONSTRAINT "PK___EFMigrationsHistory" PRIMARY KEY ("MigrationId")
);
START TRANSACTION;
DO $EF$
BEGIN
IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "MigrationId" = '20260526021536_Init') THEN
CREATE TABLE "CAPLock" (
"Key" character varying(128) NOT NULL,
"Instance" character varying(256),
"LastLockTime" TIMESTAMP,
CONSTRAINT "PK_CAPLock" PRIMARY KEY ("Key")
);
END IF;
END $EF$;
DO $EF$
BEGIN
IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "MigrationId" = '20260526021536_Init') THEN
CREATE TABLE "CAPPublishedMessage" (
"Id" bigint GENERATED BY DEFAULT AS IDENTITY,
"Version" character varying(20),
"Name" character varying(200) NOT NULL,
"Content" TEXT,
"Retries" integer,
"Added" TIMESTAMP NOT NULL,
"ExpiresAt" TIMESTAMP,
"StatusName" character varying(40) NOT NULL,
CONSTRAINT "PK_CAPPublishedMessage" PRIMARY KEY ("Id")
);
END IF;
END $EF$;
DO $EF$
BEGIN
IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "MigrationId" = '20260526021536_Init') THEN
CREATE TABLE "CAPReceivedMessage" (
"Id" bigint GENERATED BY DEFAULT AS IDENTITY,
"Version" character varying(20),
"Name" character varying(400) NOT NULL,
"Group" character varying(200),
"Content" TEXT,
"Retries" integer,
"Added" TIMESTAMP NOT NULL,
"ExpiresAt" TIMESTAMP,
"StatusName" character varying(50) NOT NULL,
CONSTRAINT "PK_CAPReceivedMessage" PRIMARY KEY ("Id")
);
END IF;
END $EF$;
DO $EF$
BEGIN
IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "MigrationId" = '20260526021536_Init') THEN
CREATE TABLE role (
"Id" bigint NOT NULL,
"RoleName" character varying(100) NOT NULL,
"CreatedAt" TIMESTAMP NOT NULL,
"UpdatedAt" TIMESTAMP NOT NULL,
"Deleted" boolean NOT NULL,
"RowVersion" integer NOT NULL,
CONSTRAINT "PK_role" PRIMARY KEY ("Id")
);
END IF;
END $EF$;
DO $EF$
BEGIN
IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "MigrationId" = '20260526021536_Init') THEN
CREATE TABLE "user" (
"Id" bigint NOT NULL,
"Username" character varying(100) NOT NULL,
"Password" character varying(500) NOT NULL,
"Email" character varying(200),
"Phone" character varying(200),
"IsActive" boolean NOT NULL,
"IsAdmin" boolean NOT NULL,
"RowVersion" integer NOT NULL,
"CreatedAt" TIMESTAMP NOT NULL,
"UpdatedAt" TIMESTAMP NOT NULL,
"Deleted" boolean NOT NULL,
CONSTRAINT "PK_user" PRIMARY KEY ("Id")
);
END IF;
END $EF$;
DO $EF$
BEGIN
IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "MigrationId" = '20260526021536_Init') THEN
CREATE TABLE role_app_item (
"Id" bigint NOT NULL,
"AppId" character varying(100) NOT NULL,
"AppName" character varying(100) NOT NULL,
"Permissions" text[] NOT NULL,
role_id bigint NOT NULL,
CONSTRAINT "PK_role_app_item" PRIMARY KEY ("Id"),
CONSTRAINT "FK_role_app_item_role_role_id" FOREIGN KEY (role_id) REFERENCES role ("Id") ON DELETE CASCADE
);
END IF;
END $EF$;
DO $EF$
BEGIN
IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "MigrationId" = '20260526021536_Init') THEN
CREATE TABLE user_role (
"Id" bigint NOT NULL,
"RoleId" bigint NOT NULL,
"RoleName" character varying(100) NOT NULL,
user_id bigint NOT NULL,
CONSTRAINT "PK_user_role" PRIMARY KEY ("Id"),
CONSTRAINT "FK_user_role_user_user_id" FOREIGN KEY (user_id) REFERENCES "user" ("Id") ON DELETE CASCADE
);
END IF;
END $EF$;
DO $EF$
BEGIN
IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "MigrationId" = '20260526021536_Init') THEN
CREATE INDEX "IX_ExpiresAt_StatusName" ON "CAPPublishedMessage" ("ExpiresAt", "StatusName");
END IF;
END $EF$;
DO $EF$
BEGIN
IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "MigrationId" = '20260526021536_Init') THEN
CREATE INDEX "IX_Version_ExpiresAt_StatusName" ON "CAPPublishedMessage" ("Version", "ExpiresAt", "StatusName");
END IF;
END $EF$;
DO $EF$
BEGIN
IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "MigrationId" = '20260526021536_Init') THEN
CREATE INDEX "IX_ExpiresAt_StatusName1" ON "CAPReceivedMessage" ("ExpiresAt", "StatusName");
END IF;
END $EF$;
DO $EF$
BEGIN
IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "MigrationId" = '20260526021536_Init') THEN
CREATE INDEX "IX_Version_ExpiresAt_StatusName1" ON "CAPReceivedMessage" ("Version", "ExpiresAt", "StatusName");
END IF;
END $EF$;
DO $EF$
BEGIN
IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "MigrationId" = '20260526021536_Init') THEN
CREATE INDEX "IX_role_app_item_role_id" ON role_app_item (role_id);
END IF;
END $EF$;
DO $EF$
BEGIN
IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "MigrationId" = '20260526021536_Init') THEN
CREATE INDEX "IX_user_role_user_id" ON user_role (user_id);
END IF;
END $EF$;
DO $EF$
BEGIN
IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "MigrationId" = '20260526021536_Init') THEN
INSERT INTO "__EFMigrationsHistory" ("MigrationId", "ProductVersion")
VALUES ('20260526021536_Init', '9.0.0');
END IF;
END $EF$;
DO $EF$
BEGIN
IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "MigrationId" = '20260713013128_AddServiceConfig') THEN
CREATE TABLE service_config (
"Id" bigint NOT NULL,
"ServiceId" character varying(100) NOT NULL,
"ServiceName" character varying(100) NOT NULL,
"CreatedAt" TIMESTAMP NOT NULL,
"UpdatedAt" TIMESTAMP NOT NULL,
CONSTRAINT "PK_service_config" PRIMARY KEY ("Id")
);
END IF;
END $EF$;
DO $EF$
BEGIN
IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "MigrationId" = '20260713013128_AddServiceConfig') THEN
CREATE UNIQUE INDEX "IX_service_config_ServiceId" ON service_config ("ServiceId");
END IF;
END $EF$;
DO $EF$
BEGIN
IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "MigrationId" = '20260713013128_AddServiceConfig') THEN
INSERT INTO "__EFMigrationsHistory" ("MigrationId", "ProductVersion")
VALUES ('20260713013128_AddServiceConfig', '9.0.0');
END IF;
END $EF$;
DO $EF$
BEGIN
IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "MigrationId" = '20260804024643_AddUserPreference') THEN
CREATE TABLE user_preference (
"Id" bigint NOT NULL,
"UserId" bigint NOT NULL,
"Scope" character varying(64) NOT NULL,
"Payload" jsonb NOT NULL,
"RowVersion" integer NOT NULL,
"CreatedAt" TIMESTAMP NOT NULL,
"UpdatedAt" TIMESTAMP NOT NULL,
CONSTRAINT "PK_user_preference" PRIMARY KEY ("Id")
);
END IF;
END $EF$;
DO $EF$
BEGIN
IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "MigrationId" = '20260804024643_AddUserPreference') THEN
CREATE UNIQUE INDEX "IX_user_preference_UserId_Scope" ON user_preference ("UserId", "Scope");
END IF;
END $EF$;
DO $EF$
BEGIN
IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "MigrationId" = '20260804024643_AddUserPreference') THEN
INSERT INTO "__EFMigrationsHistory" ("MigrationId", "ProductVersion")
VALUES ('20260804024643_AddUserPreference', '9.0.0');
END IF;
END $EF$;
DO $EF$
BEGIN
IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "MigrationId" = '20260804090000_ResetUserPreference') THEN
ALTER TABLE user_preference ALTER COLUMN "Scope" TYPE character varying(128);
END IF;
END $EF$;
DO $EF$
BEGIN
IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "MigrationId" = '20260804090000_ResetUserPreference') THEN
INSERT INTO "__EFMigrationsHistory" ("MigrationId", "ProductVersion")
VALUES ('20260804090000_ResetUserPreference', '9.0.0');
END IF;
END $EF$;
DO $EF$
BEGIN
IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "MigrationId" = '20260825100000_ResetAdminPassword') THEN
UPDATE "user"
SET "Password" = 'Start12345', "UpdatedAt" = NOW()
WHERE "Username" = 'admin' AND "IsAdmin" AND NOT "Deleted";
END IF;
END $EF$;
DO $EF$
BEGIN
IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "MigrationId" = '20260825100000_ResetAdminPassword') THEN
INSERT INTO "__EFMigrationsHistory" ("MigrationId", "ProductVersion")
VALUES ('20260825100000_ResetAdminPassword', '9.0.0');
END IF;
END $EF$;
COMMIT;
@@ -1,268 +0,0 @@
-- MixingX SSO idempotent migration script (PostgreSQL)
-- Image tag: develop-v.1.0.1-202608280622-43
-- Generated by CI: dotnet ef migrations script --idempotent
-- Apply manually per ADR-0074 (生产 DB 变更全人工).
-- ===== ApplicationDbContext =====
CREATE TABLE IF NOT EXISTS "__EFMigrationsHistory" (
"MigrationId" character varying(150) NOT NULL,
"ProductVersion" character varying(32) NOT NULL,
CONSTRAINT "PK___EFMigrationsHistory" PRIMARY KEY ("MigrationId")
);
START TRANSACTION;
DO $EF$
BEGIN
IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "MigrationId" = '20260526021536_Init') THEN
CREATE TABLE "CAPLock" (
"Key" character varying(128) NOT NULL,
"Instance" character varying(256),
"LastLockTime" TIMESTAMP,
CONSTRAINT "PK_CAPLock" PRIMARY KEY ("Key")
);
END IF;
END $EF$;
DO $EF$
BEGIN
IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "MigrationId" = '20260526021536_Init') THEN
CREATE TABLE "CAPPublishedMessage" (
"Id" bigint GENERATED BY DEFAULT AS IDENTITY,
"Version" character varying(20),
"Name" character varying(200) NOT NULL,
"Content" TEXT,
"Retries" integer,
"Added" TIMESTAMP NOT NULL,
"ExpiresAt" TIMESTAMP,
"StatusName" character varying(40) NOT NULL,
CONSTRAINT "PK_CAPPublishedMessage" PRIMARY KEY ("Id")
);
END IF;
END $EF$;
DO $EF$
BEGIN
IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "MigrationId" = '20260526021536_Init') THEN
CREATE TABLE "CAPReceivedMessage" (
"Id" bigint GENERATED BY DEFAULT AS IDENTITY,
"Version" character varying(20),
"Name" character varying(400) NOT NULL,
"Group" character varying(200),
"Content" TEXT,
"Retries" integer,
"Added" TIMESTAMP NOT NULL,
"ExpiresAt" TIMESTAMP,
"StatusName" character varying(50) NOT NULL,
CONSTRAINT "PK_CAPReceivedMessage" PRIMARY KEY ("Id")
);
END IF;
END $EF$;
DO $EF$
BEGIN
IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "MigrationId" = '20260526021536_Init') THEN
CREATE TABLE role (
"Id" bigint NOT NULL,
"RoleName" character varying(100) NOT NULL,
"CreatedAt" TIMESTAMP NOT NULL,
"UpdatedAt" TIMESTAMP NOT NULL,
"Deleted" boolean NOT NULL,
"RowVersion" integer NOT NULL,
CONSTRAINT "PK_role" PRIMARY KEY ("Id")
);
END IF;
END $EF$;
DO $EF$
BEGIN
IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "MigrationId" = '20260526021536_Init') THEN
CREATE TABLE "user" (
"Id" bigint NOT NULL,
"Username" character varying(100) NOT NULL,
"Password" character varying(500) NOT NULL,
"Email" character varying(200),
"Phone" character varying(200),
"IsActive" boolean NOT NULL,
"IsAdmin" boolean NOT NULL,
"RowVersion" integer NOT NULL,
"CreatedAt" TIMESTAMP NOT NULL,
"UpdatedAt" TIMESTAMP NOT NULL,
"Deleted" boolean NOT NULL,
CONSTRAINT "PK_user" PRIMARY KEY ("Id")
);
END IF;
END $EF$;
DO $EF$
BEGIN
IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "MigrationId" = '20260526021536_Init') THEN
CREATE TABLE role_app_item (
"Id" bigint NOT NULL,
"AppId" character varying(100) NOT NULL,
"AppName" character varying(100) NOT NULL,
"Permissions" text[] NOT NULL,
role_id bigint NOT NULL,
CONSTRAINT "PK_role_app_item" PRIMARY KEY ("Id"),
CONSTRAINT "FK_role_app_item_role_role_id" FOREIGN KEY (role_id) REFERENCES role ("Id") ON DELETE CASCADE
);
END IF;
END $EF$;
DO $EF$
BEGIN
IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "MigrationId" = '20260526021536_Init') THEN
CREATE TABLE user_role (
"Id" bigint NOT NULL,
"RoleId" bigint NOT NULL,
"RoleName" character varying(100) NOT NULL,
user_id bigint NOT NULL,
CONSTRAINT "PK_user_role" PRIMARY KEY ("Id"),
CONSTRAINT "FK_user_role_user_user_id" FOREIGN KEY (user_id) REFERENCES "user" ("Id") ON DELETE CASCADE
);
END IF;
END $EF$;
DO $EF$
BEGIN
IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "MigrationId" = '20260526021536_Init') THEN
CREATE INDEX "IX_ExpiresAt_StatusName" ON "CAPPublishedMessage" ("ExpiresAt", "StatusName");
END IF;
END $EF$;
DO $EF$
BEGIN
IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "MigrationId" = '20260526021536_Init') THEN
CREATE INDEX "IX_Version_ExpiresAt_StatusName" ON "CAPPublishedMessage" ("Version", "ExpiresAt", "StatusName");
END IF;
END $EF$;
DO $EF$
BEGIN
IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "MigrationId" = '20260526021536_Init') THEN
CREATE INDEX "IX_ExpiresAt_StatusName1" ON "CAPReceivedMessage" ("ExpiresAt", "StatusName");
END IF;
END $EF$;
DO $EF$
BEGIN
IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "MigrationId" = '20260526021536_Init') THEN
CREATE INDEX "IX_Version_ExpiresAt_StatusName1" ON "CAPReceivedMessage" ("Version", "ExpiresAt", "StatusName");
END IF;
END $EF$;
DO $EF$
BEGIN
IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "MigrationId" = '20260526021536_Init') THEN
CREATE INDEX "IX_role_app_item_role_id" ON role_app_item (role_id);
END IF;
END $EF$;
DO $EF$
BEGIN
IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "MigrationId" = '20260526021536_Init') THEN
CREATE INDEX "IX_user_role_user_id" ON user_role (user_id);
END IF;
END $EF$;
DO $EF$
BEGIN
IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "MigrationId" = '20260526021536_Init') THEN
INSERT INTO "__EFMigrationsHistory" ("MigrationId", "ProductVersion")
VALUES ('20260526021536_Init', '9.0.0');
END IF;
END $EF$;
DO $EF$
BEGIN
IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "MigrationId" = '20260713013128_AddServiceConfig') THEN
CREATE TABLE service_config (
"Id" bigint NOT NULL,
"ServiceId" character varying(100) NOT NULL,
"ServiceName" character varying(100) NOT NULL,
"CreatedAt" TIMESTAMP NOT NULL,
"UpdatedAt" TIMESTAMP NOT NULL,
CONSTRAINT "PK_service_config" PRIMARY KEY ("Id")
);
END IF;
END $EF$;
DO $EF$
BEGIN
IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "MigrationId" = '20260713013128_AddServiceConfig') THEN
CREATE UNIQUE INDEX "IX_service_config_ServiceId" ON service_config ("ServiceId");
END IF;
END $EF$;
DO $EF$
BEGIN
IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "MigrationId" = '20260713013128_AddServiceConfig') THEN
INSERT INTO "__EFMigrationsHistory" ("MigrationId", "ProductVersion")
VALUES ('20260713013128_AddServiceConfig', '9.0.0');
END IF;
END $EF$;
DO $EF$
BEGIN
IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "MigrationId" = '20260804024643_AddUserPreference') THEN
CREATE TABLE user_preference (
"Id" bigint NOT NULL,
"UserId" bigint NOT NULL,
"Scope" character varying(64) NOT NULL,
"Payload" jsonb NOT NULL,
"RowVersion" integer NOT NULL,
"CreatedAt" TIMESTAMP NOT NULL,
"UpdatedAt" TIMESTAMP NOT NULL,
CONSTRAINT "PK_user_preference" PRIMARY KEY ("Id")
);
END IF;
END $EF$;
DO $EF$
BEGIN
IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "MigrationId" = '20260804024643_AddUserPreference') THEN
CREATE UNIQUE INDEX "IX_user_preference_UserId_Scope" ON user_preference ("UserId", "Scope");
END IF;
END $EF$;
DO $EF$
BEGIN
IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "MigrationId" = '20260804024643_AddUserPreference') THEN
INSERT INTO "__EFMigrationsHistory" ("MigrationId", "ProductVersion")
VALUES ('20260804024643_AddUserPreference', '9.0.0');
END IF;
END $EF$;
DO $EF$
BEGIN
IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "MigrationId" = '20260804090000_ResetUserPreference') THEN
ALTER TABLE user_preference ALTER COLUMN "Scope" TYPE character varying(128);
END IF;
END $EF$;
DO $EF$
BEGIN
IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "MigrationId" = '20260804090000_ResetUserPreference') THEN
INSERT INTO "__EFMigrationsHistory" ("MigrationId", "ProductVersion")
VALUES ('20260804090000_ResetUserPreference', '9.0.0');
END IF;
END $EF$;
DO $EF$
BEGIN
IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "MigrationId" = '20260825100000_ResetAdminPassword') THEN
UPDATE "user"
SET "Password" = 'Start12345', "UpdatedAt" = NOW()
WHERE "Username" = 'admin' AND "IsAdmin" AND NOT "Deleted";
END IF;
END $EF$;
DO $EF$
BEGIN
IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "MigrationId" = '20260825100000_ResetAdminPassword') THEN
INSERT INTO "__EFMigrationsHistory" ("MigrationId", "ProductVersion")
VALUES ('20260825100000_ResetAdminPassword', '9.0.0');
END IF;
END $EF$;
COMMIT;
@@ -1,268 +0,0 @@
-- MixingX SSO idempotent migration script (PostgreSQL)
-- Image tag: develop-v.1.0.1-202608280736-44
-- Generated by CI: dotnet ef migrations script --idempotent
-- Apply manually per ADR-0074 (生产 DB 变更全人工).
-- ===== ApplicationDbContext =====
CREATE TABLE IF NOT EXISTS "__EFMigrationsHistory" (
"MigrationId" character varying(150) NOT NULL,
"ProductVersion" character varying(32) NOT NULL,
CONSTRAINT "PK___EFMigrationsHistory" PRIMARY KEY ("MigrationId")
);
START TRANSACTION;
DO $EF$
BEGIN
IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "MigrationId" = '20260526021536_Init') THEN
CREATE TABLE "CAPLock" (
"Key" character varying(128) NOT NULL,
"Instance" character varying(256),
"LastLockTime" TIMESTAMP,
CONSTRAINT "PK_CAPLock" PRIMARY KEY ("Key")
);
END IF;
END $EF$;
DO $EF$
BEGIN
IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "MigrationId" = '20260526021536_Init') THEN
CREATE TABLE "CAPPublishedMessage" (
"Id" bigint GENERATED BY DEFAULT AS IDENTITY,
"Version" character varying(20),
"Name" character varying(200) NOT NULL,
"Content" TEXT,
"Retries" integer,
"Added" TIMESTAMP NOT NULL,
"ExpiresAt" TIMESTAMP,
"StatusName" character varying(40) NOT NULL,
CONSTRAINT "PK_CAPPublishedMessage" PRIMARY KEY ("Id")
);
END IF;
END $EF$;
DO $EF$
BEGIN
IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "MigrationId" = '20260526021536_Init') THEN
CREATE TABLE "CAPReceivedMessage" (
"Id" bigint GENERATED BY DEFAULT AS IDENTITY,
"Version" character varying(20),
"Name" character varying(400) NOT NULL,
"Group" character varying(200),
"Content" TEXT,
"Retries" integer,
"Added" TIMESTAMP NOT NULL,
"ExpiresAt" TIMESTAMP,
"StatusName" character varying(50) NOT NULL,
CONSTRAINT "PK_CAPReceivedMessage" PRIMARY KEY ("Id")
);
END IF;
END $EF$;
DO $EF$
BEGIN
IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "MigrationId" = '20260526021536_Init') THEN
CREATE TABLE role (
"Id" bigint NOT NULL,
"RoleName" character varying(100) NOT NULL,
"CreatedAt" TIMESTAMP NOT NULL,
"UpdatedAt" TIMESTAMP NOT NULL,
"Deleted" boolean NOT NULL,
"RowVersion" integer NOT NULL,
CONSTRAINT "PK_role" PRIMARY KEY ("Id")
);
END IF;
END $EF$;
DO $EF$
BEGIN
IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "MigrationId" = '20260526021536_Init') THEN
CREATE TABLE "user" (
"Id" bigint NOT NULL,
"Username" character varying(100) NOT NULL,
"Password" character varying(500) NOT NULL,
"Email" character varying(200),
"Phone" character varying(200),
"IsActive" boolean NOT NULL,
"IsAdmin" boolean NOT NULL,
"RowVersion" integer NOT NULL,
"CreatedAt" TIMESTAMP NOT NULL,
"UpdatedAt" TIMESTAMP NOT NULL,
"Deleted" boolean NOT NULL,
CONSTRAINT "PK_user" PRIMARY KEY ("Id")
);
END IF;
END $EF$;
DO $EF$
BEGIN
IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "MigrationId" = '20260526021536_Init') THEN
CREATE TABLE role_app_item (
"Id" bigint NOT NULL,
"AppId" character varying(100) NOT NULL,
"AppName" character varying(100) NOT NULL,
"Permissions" text[] NOT NULL,
role_id bigint NOT NULL,
CONSTRAINT "PK_role_app_item" PRIMARY KEY ("Id"),
CONSTRAINT "FK_role_app_item_role_role_id" FOREIGN KEY (role_id) REFERENCES role ("Id") ON DELETE CASCADE
);
END IF;
END $EF$;
DO $EF$
BEGIN
IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "MigrationId" = '20260526021536_Init') THEN
CREATE TABLE user_role (
"Id" bigint NOT NULL,
"RoleId" bigint NOT NULL,
"RoleName" character varying(100) NOT NULL,
user_id bigint NOT NULL,
CONSTRAINT "PK_user_role" PRIMARY KEY ("Id"),
CONSTRAINT "FK_user_role_user_user_id" FOREIGN KEY (user_id) REFERENCES "user" ("Id") ON DELETE CASCADE
);
END IF;
END $EF$;
DO $EF$
BEGIN
IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "MigrationId" = '20260526021536_Init') THEN
CREATE INDEX "IX_ExpiresAt_StatusName" ON "CAPPublishedMessage" ("ExpiresAt", "StatusName");
END IF;
END $EF$;
DO $EF$
BEGIN
IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "MigrationId" = '20260526021536_Init') THEN
CREATE INDEX "IX_Version_ExpiresAt_StatusName" ON "CAPPublishedMessage" ("Version", "ExpiresAt", "StatusName");
END IF;
END $EF$;
DO $EF$
BEGIN
IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "MigrationId" = '20260526021536_Init') THEN
CREATE INDEX "IX_ExpiresAt_StatusName1" ON "CAPReceivedMessage" ("ExpiresAt", "StatusName");
END IF;
END $EF$;
DO $EF$
BEGIN
IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "MigrationId" = '20260526021536_Init') THEN
CREATE INDEX "IX_Version_ExpiresAt_StatusName1" ON "CAPReceivedMessage" ("Version", "ExpiresAt", "StatusName");
END IF;
END $EF$;
DO $EF$
BEGIN
IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "MigrationId" = '20260526021536_Init') THEN
CREATE INDEX "IX_role_app_item_role_id" ON role_app_item (role_id);
END IF;
END $EF$;
DO $EF$
BEGIN
IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "MigrationId" = '20260526021536_Init') THEN
CREATE INDEX "IX_user_role_user_id" ON user_role (user_id);
END IF;
END $EF$;
DO $EF$
BEGIN
IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "MigrationId" = '20260526021536_Init') THEN
INSERT INTO "__EFMigrationsHistory" ("MigrationId", "ProductVersion")
VALUES ('20260526021536_Init', '9.0.0');
END IF;
END $EF$;
DO $EF$
BEGIN
IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "MigrationId" = '20260713013128_AddServiceConfig') THEN
CREATE TABLE service_config (
"Id" bigint NOT NULL,
"ServiceId" character varying(100) NOT NULL,
"ServiceName" character varying(100) NOT NULL,
"CreatedAt" TIMESTAMP NOT NULL,
"UpdatedAt" TIMESTAMP NOT NULL,
CONSTRAINT "PK_service_config" PRIMARY KEY ("Id")
);
END IF;
END $EF$;
DO $EF$
BEGIN
IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "MigrationId" = '20260713013128_AddServiceConfig') THEN
CREATE UNIQUE INDEX "IX_service_config_ServiceId" ON service_config ("ServiceId");
END IF;
END $EF$;
DO $EF$
BEGIN
IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "MigrationId" = '20260713013128_AddServiceConfig') THEN
INSERT INTO "__EFMigrationsHistory" ("MigrationId", "ProductVersion")
VALUES ('20260713013128_AddServiceConfig', '9.0.0');
END IF;
END $EF$;
DO $EF$
BEGIN
IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "MigrationId" = '20260804024643_AddUserPreference') THEN
CREATE TABLE user_preference (
"Id" bigint NOT NULL,
"UserId" bigint NOT NULL,
"Scope" character varying(64) NOT NULL,
"Payload" jsonb NOT NULL,
"RowVersion" integer NOT NULL,
"CreatedAt" TIMESTAMP NOT NULL,
"UpdatedAt" TIMESTAMP NOT NULL,
CONSTRAINT "PK_user_preference" PRIMARY KEY ("Id")
);
END IF;
END $EF$;
DO $EF$
BEGIN
IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "MigrationId" = '20260804024643_AddUserPreference') THEN
CREATE UNIQUE INDEX "IX_user_preference_UserId_Scope" ON user_preference ("UserId", "Scope");
END IF;
END $EF$;
DO $EF$
BEGIN
IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "MigrationId" = '20260804024643_AddUserPreference') THEN
INSERT INTO "__EFMigrationsHistory" ("MigrationId", "ProductVersion")
VALUES ('20260804024643_AddUserPreference', '9.0.0');
END IF;
END $EF$;
DO $EF$
BEGIN
IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "MigrationId" = '20260804090000_ResetUserPreference') THEN
ALTER TABLE user_preference ALTER COLUMN "Scope" TYPE character varying(128);
END IF;
END $EF$;
DO $EF$
BEGIN
IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "MigrationId" = '20260804090000_ResetUserPreference') THEN
INSERT INTO "__EFMigrationsHistory" ("MigrationId", "ProductVersion")
VALUES ('20260804090000_ResetUserPreference', '9.0.0');
END IF;
END $EF$;
DO $EF$
BEGIN
IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "MigrationId" = '20260825100000_ResetAdminPassword') THEN
UPDATE "user"
SET "Password" = 'Start12345', "UpdatedAt" = NOW()
WHERE "Username" = 'admin' AND "IsAdmin" AND NOT "Deleted";
END IF;
END $EF$;
DO $EF$
BEGIN
IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "MigrationId" = '20260825100000_ResetAdminPassword') THEN
INSERT INTO "__EFMigrationsHistory" ("MigrationId", "ProductVersion")
VALUES ('20260825100000_ResetAdminPassword', '9.0.0');
END IF;
END $EF$;
COMMIT;
@@ -1,268 +0,0 @@
-- MixingX SSO idempotent migration script (PostgreSQL)
-- Image tag: develop-v.1.0.1-202608310638-45
-- Generated by CI: dotnet ef migrations script --idempotent
-- Apply manually per ADR-0074 (生产 DB 变更全人工).
-- ===== ApplicationDbContext =====
CREATE TABLE IF NOT EXISTS "__EFMigrationsHistory" (
"MigrationId" character varying(150) NOT NULL,
"ProductVersion" character varying(32) NOT NULL,
CONSTRAINT "PK___EFMigrationsHistory" PRIMARY KEY ("MigrationId")
);
START TRANSACTION;
DO $EF$
BEGIN
IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "MigrationId" = '20260526021536_Init') THEN
CREATE TABLE "CAPLock" (
"Key" character varying(128) NOT NULL,
"Instance" character varying(256),
"LastLockTime" TIMESTAMP,
CONSTRAINT "PK_CAPLock" PRIMARY KEY ("Key")
);
END IF;
END $EF$;
DO $EF$
BEGIN
IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "MigrationId" = '20260526021536_Init') THEN
CREATE TABLE "CAPPublishedMessage" (
"Id" bigint GENERATED BY DEFAULT AS IDENTITY,
"Version" character varying(20),
"Name" character varying(200) NOT NULL,
"Content" TEXT,
"Retries" integer,
"Added" TIMESTAMP NOT NULL,
"ExpiresAt" TIMESTAMP,
"StatusName" character varying(40) NOT NULL,
CONSTRAINT "PK_CAPPublishedMessage" PRIMARY KEY ("Id")
);
END IF;
END $EF$;
DO $EF$
BEGIN
IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "MigrationId" = '20260526021536_Init') THEN
CREATE TABLE "CAPReceivedMessage" (
"Id" bigint GENERATED BY DEFAULT AS IDENTITY,
"Version" character varying(20),
"Name" character varying(400) NOT NULL,
"Group" character varying(200),
"Content" TEXT,
"Retries" integer,
"Added" TIMESTAMP NOT NULL,
"ExpiresAt" TIMESTAMP,
"StatusName" character varying(50) NOT NULL,
CONSTRAINT "PK_CAPReceivedMessage" PRIMARY KEY ("Id")
);
END IF;
END $EF$;
DO $EF$
BEGIN
IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "MigrationId" = '20260526021536_Init') THEN
CREATE TABLE role (
"Id" bigint NOT NULL,
"RoleName" character varying(100) NOT NULL,
"CreatedAt" TIMESTAMP NOT NULL,
"UpdatedAt" TIMESTAMP NOT NULL,
"Deleted" boolean NOT NULL,
"RowVersion" integer NOT NULL,
CONSTRAINT "PK_role" PRIMARY KEY ("Id")
);
END IF;
END $EF$;
DO $EF$
BEGIN
IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "MigrationId" = '20260526021536_Init') THEN
CREATE TABLE "user" (
"Id" bigint NOT NULL,
"Username" character varying(100) NOT NULL,
"Password" character varying(500) NOT NULL,
"Email" character varying(200),
"Phone" character varying(200),
"IsActive" boolean NOT NULL,
"IsAdmin" boolean NOT NULL,
"RowVersion" integer NOT NULL,
"CreatedAt" TIMESTAMP NOT NULL,
"UpdatedAt" TIMESTAMP NOT NULL,
"Deleted" boolean NOT NULL,
CONSTRAINT "PK_user" PRIMARY KEY ("Id")
);
END IF;
END $EF$;
DO $EF$
BEGIN
IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "MigrationId" = '20260526021536_Init') THEN
CREATE TABLE role_app_item (
"Id" bigint NOT NULL,
"AppId" character varying(100) NOT NULL,
"AppName" character varying(100) NOT NULL,
"Permissions" text[] NOT NULL,
role_id bigint NOT NULL,
CONSTRAINT "PK_role_app_item" PRIMARY KEY ("Id"),
CONSTRAINT "FK_role_app_item_role_role_id" FOREIGN KEY (role_id) REFERENCES role ("Id") ON DELETE CASCADE
);
END IF;
END $EF$;
DO $EF$
BEGIN
IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "MigrationId" = '20260526021536_Init') THEN
CREATE TABLE user_role (
"Id" bigint NOT NULL,
"RoleId" bigint NOT NULL,
"RoleName" character varying(100) NOT NULL,
user_id bigint NOT NULL,
CONSTRAINT "PK_user_role" PRIMARY KEY ("Id"),
CONSTRAINT "FK_user_role_user_user_id" FOREIGN KEY (user_id) REFERENCES "user" ("Id") ON DELETE CASCADE
);
END IF;
END $EF$;
DO $EF$
BEGIN
IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "MigrationId" = '20260526021536_Init') THEN
CREATE INDEX "IX_ExpiresAt_StatusName" ON "CAPPublishedMessage" ("ExpiresAt", "StatusName");
END IF;
END $EF$;
DO $EF$
BEGIN
IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "MigrationId" = '20260526021536_Init') THEN
CREATE INDEX "IX_Version_ExpiresAt_StatusName" ON "CAPPublishedMessage" ("Version", "ExpiresAt", "StatusName");
END IF;
END $EF$;
DO $EF$
BEGIN
IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "MigrationId" = '20260526021536_Init') THEN
CREATE INDEX "IX_ExpiresAt_StatusName1" ON "CAPReceivedMessage" ("ExpiresAt", "StatusName");
END IF;
END $EF$;
DO $EF$
BEGIN
IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "MigrationId" = '20260526021536_Init') THEN
CREATE INDEX "IX_Version_ExpiresAt_StatusName1" ON "CAPReceivedMessage" ("Version", "ExpiresAt", "StatusName");
END IF;
END $EF$;
DO $EF$
BEGIN
IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "MigrationId" = '20260526021536_Init') THEN
CREATE INDEX "IX_role_app_item_role_id" ON role_app_item (role_id);
END IF;
END $EF$;
DO $EF$
BEGIN
IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "MigrationId" = '20260526021536_Init') THEN
CREATE INDEX "IX_user_role_user_id" ON user_role (user_id);
END IF;
END $EF$;
DO $EF$
BEGIN
IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "MigrationId" = '20260526021536_Init') THEN
INSERT INTO "__EFMigrationsHistory" ("MigrationId", "ProductVersion")
VALUES ('20260526021536_Init', '9.0.0');
END IF;
END $EF$;
DO $EF$
BEGIN
IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "MigrationId" = '20260713013128_AddServiceConfig') THEN
CREATE TABLE service_config (
"Id" bigint NOT NULL,
"ServiceId" character varying(100) NOT NULL,
"ServiceName" character varying(100) NOT NULL,
"CreatedAt" TIMESTAMP NOT NULL,
"UpdatedAt" TIMESTAMP NOT NULL,
CONSTRAINT "PK_service_config" PRIMARY KEY ("Id")
);
END IF;
END $EF$;
DO $EF$
BEGIN
IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "MigrationId" = '20260713013128_AddServiceConfig') THEN
CREATE UNIQUE INDEX "IX_service_config_ServiceId" ON service_config ("ServiceId");
END IF;
END $EF$;
DO $EF$
BEGIN
IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "MigrationId" = '20260713013128_AddServiceConfig') THEN
INSERT INTO "__EFMigrationsHistory" ("MigrationId", "ProductVersion")
VALUES ('20260713013128_AddServiceConfig', '9.0.0');
END IF;
END $EF$;
DO $EF$
BEGIN
IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "MigrationId" = '20260804024643_AddUserPreference') THEN
CREATE TABLE user_preference (
"Id" bigint NOT NULL,
"UserId" bigint NOT NULL,
"Scope" character varying(64) NOT NULL,
"Payload" jsonb NOT NULL,
"RowVersion" integer NOT NULL,
"CreatedAt" TIMESTAMP NOT NULL,
"UpdatedAt" TIMESTAMP NOT NULL,
CONSTRAINT "PK_user_preference" PRIMARY KEY ("Id")
);
END IF;
END $EF$;
DO $EF$
BEGIN
IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "MigrationId" = '20260804024643_AddUserPreference') THEN
CREATE UNIQUE INDEX "IX_user_preference_UserId_Scope" ON user_preference ("UserId", "Scope");
END IF;
END $EF$;
DO $EF$
BEGIN
IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "MigrationId" = '20260804024643_AddUserPreference') THEN
INSERT INTO "__EFMigrationsHistory" ("MigrationId", "ProductVersion")
VALUES ('20260804024643_AddUserPreference', '9.0.0');
END IF;
END $EF$;
DO $EF$
BEGIN
IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "MigrationId" = '20260804090000_ResetUserPreference') THEN
ALTER TABLE user_preference ALTER COLUMN "Scope" TYPE character varying(128);
END IF;
END $EF$;
DO $EF$
BEGIN
IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "MigrationId" = '20260804090000_ResetUserPreference') THEN
INSERT INTO "__EFMigrationsHistory" ("MigrationId", "ProductVersion")
VALUES ('20260804090000_ResetUserPreference', '9.0.0');
END IF;
END $EF$;
DO $EF$
BEGIN
IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "MigrationId" = '20260825100000_ResetAdminPassword') THEN
UPDATE "user"
SET "Password" = 'Start12345', "UpdatedAt" = NOW()
WHERE "Username" = 'admin' AND "IsAdmin" AND NOT "Deleted";
END IF;
END $EF$;
DO $EF$
BEGIN
IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "MigrationId" = '20260825100000_ResetAdminPassword') THEN
INSERT INTO "__EFMigrationsHistory" ("MigrationId", "ProductVersion")
VALUES ('20260825100000_ResetAdminPassword', '9.0.0');
END IF;
END $EF$;
COMMIT;
@@ -1,268 +0,0 @@
-- MixingX SSO idempotent migration script (PostgreSQL)
-- Image tag: develop-v.1.0.1-202609020612-46
-- Generated by CI: dotnet ef migrations script --idempotent
-- Apply manually per ADR-0074 (生产 DB 变更全人工).
-- ===== ApplicationDbContext =====
CREATE TABLE IF NOT EXISTS "__EFMigrationsHistory" (
"MigrationId" character varying(150) NOT NULL,
"ProductVersion" character varying(32) NOT NULL,
CONSTRAINT "PK___EFMigrationsHistory" PRIMARY KEY ("MigrationId")
);
START TRANSACTION;
DO $EF$
BEGIN
IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "MigrationId" = '20260526021536_Init') THEN
CREATE TABLE "CAPLock" (
"Key" character varying(128) NOT NULL,
"Instance" character varying(256),
"LastLockTime" TIMESTAMP,
CONSTRAINT "PK_CAPLock" PRIMARY KEY ("Key")
);
END IF;
END $EF$;
DO $EF$
BEGIN
IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "MigrationId" = '20260526021536_Init') THEN
CREATE TABLE "CAPPublishedMessage" (
"Id" bigint GENERATED BY DEFAULT AS IDENTITY,
"Version" character varying(20),
"Name" character varying(200) NOT NULL,
"Content" TEXT,
"Retries" integer,
"Added" TIMESTAMP NOT NULL,
"ExpiresAt" TIMESTAMP,
"StatusName" character varying(40) NOT NULL,
CONSTRAINT "PK_CAPPublishedMessage" PRIMARY KEY ("Id")
);
END IF;
END $EF$;
DO $EF$
BEGIN
IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "MigrationId" = '20260526021536_Init') THEN
CREATE TABLE "CAPReceivedMessage" (
"Id" bigint GENERATED BY DEFAULT AS IDENTITY,
"Version" character varying(20),
"Name" character varying(400) NOT NULL,
"Group" character varying(200),
"Content" TEXT,
"Retries" integer,
"Added" TIMESTAMP NOT NULL,
"ExpiresAt" TIMESTAMP,
"StatusName" character varying(50) NOT NULL,
CONSTRAINT "PK_CAPReceivedMessage" PRIMARY KEY ("Id")
);
END IF;
END $EF$;
DO $EF$
BEGIN
IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "MigrationId" = '20260526021536_Init') THEN
CREATE TABLE role (
"Id" bigint NOT NULL,
"RoleName" character varying(100) NOT NULL,
"CreatedAt" TIMESTAMP NOT NULL,
"UpdatedAt" TIMESTAMP NOT NULL,
"Deleted" boolean NOT NULL,
"RowVersion" integer NOT NULL,
CONSTRAINT "PK_role" PRIMARY KEY ("Id")
);
END IF;
END $EF$;
DO $EF$
BEGIN
IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "MigrationId" = '20260526021536_Init') THEN
CREATE TABLE "user" (
"Id" bigint NOT NULL,
"Username" character varying(100) NOT NULL,
"Password" character varying(500) NOT NULL,
"Email" character varying(200),
"Phone" character varying(200),
"IsActive" boolean NOT NULL,
"IsAdmin" boolean NOT NULL,
"RowVersion" integer NOT NULL,
"CreatedAt" TIMESTAMP NOT NULL,
"UpdatedAt" TIMESTAMP NOT NULL,
"Deleted" boolean NOT NULL,
CONSTRAINT "PK_user" PRIMARY KEY ("Id")
);
END IF;
END $EF$;
DO $EF$
BEGIN
IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "MigrationId" = '20260526021536_Init') THEN
CREATE TABLE role_app_item (
"Id" bigint NOT NULL,
"AppId" character varying(100) NOT NULL,
"AppName" character varying(100) NOT NULL,
"Permissions" text[] NOT NULL,
role_id bigint NOT NULL,
CONSTRAINT "PK_role_app_item" PRIMARY KEY ("Id"),
CONSTRAINT "FK_role_app_item_role_role_id" FOREIGN KEY (role_id) REFERENCES role ("Id") ON DELETE CASCADE
);
END IF;
END $EF$;
DO $EF$
BEGIN
IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "MigrationId" = '20260526021536_Init') THEN
CREATE TABLE user_role (
"Id" bigint NOT NULL,
"RoleId" bigint NOT NULL,
"RoleName" character varying(100) NOT NULL,
user_id bigint NOT NULL,
CONSTRAINT "PK_user_role" PRIMARY KEY ("Id"),
CONSTRAINT "FK_user_role_user_user_id" FOREIGN KEY (user_id) REFERENCES "user" ("Id") ON DELETE CASCADE
);
END IF;
END $EF$;
DO $EF$
BEGIN
IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "MigrationId" = '20260526021536_Init') THEN
CREATE INDEX "IX_ExpiresAt_StatusName" ON "CAPPublishedMessage" ("ExpiresAt", "StatusName");
END IF;
END $EF$;
DO $EF$
BEGIN
IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "MigrationId" = '20260526021536_Init') THEN
CREATE INDEX "IX_Version_ExpiresAt_StatusName" ON "CAPPublishedMessage" ("Version", "ExpiresAt", "StatusName");
END IF;
END $EF$;
DO $EF$
BEGIN
IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "MigrationId" = '20260526021536_Init') THEN
CREATE INDEX "IX_ExpiresAt_StatusName1" ON "CAPReceivedMessage" ("ExpiresAt", "StatusName");
END IF;
END $EF$;
DO $EF$
BEGIN
IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "MigrationId" = '20260526021536_Init') THEN
CREATE INDEX "IX_Version_ExpiresAt_StatusName1" ON "CAPReceivedMessage" ("Version", "ExpiresAt", "StatusName");
END IF;
END $EF$;
DO $EF$
BEGIN
IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "MigrationId" = '20260526021536_Init') THEN
CREATE INDEX "IX_role_app_item_role_id" ON role_app_item (role_id);
END IF;
END $EF$;
DO $EF$
BEGIN
IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "MigrationId" = '20260526021536_Init') THEN
CREATE INDEX "IX_user_role_user_id" ON user_role (user_id);
END IF;
END $EF$;
DO $EF$
BEGIN
IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "MigrationId" = '20260526021536_Init') THEN
INSERT INTO "__EFMigrationsHistory" ("MigrationId", "ProductVersion")
VALUES ('20260526021536_Init', '9.0.0');
END IF;
END $EF$;
DO $EF$
BEGIN
IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "MigrationId" = '20260713013128_AddServiceConfig') THEN
CREATE TABLE service_config (
"Id" bigint NOT NULL,
"ServiceId" character varying(100) NOT NULL,
"ServiceName" character varying(100) NOT NULL,
"CreatedAt" TIMESTAMP NOT NULL,
"UpdatedAt" TIMESTAMP NOT NULL,
CONSTRAINT "PK_service_config" PRIMARY KEY ("Id")
);
END IF;
END $EF$;
DO $EF$
BEGIN
IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "MigrationId" = '20260713013128_AddServiceConfig') THEN
CREATE UNIQUE INDEX "IX_service_config_ServiceId" ON service_config ("ServiceId");
END IF;
END $EF$;
DO $EF$
BEGIN
IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "MigrationId" = '20260713013128_AddServiceConfig') THEN
INSERT INTO "__EFMigrationsHistory" ("MigrationId", "ProductVersion")
VALUES ('20260713013128_AddServiceConfig', '9.0.0');
END IF;
END $EF$;
DO $EF$
BEGIN
IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "MigrationId" = '20260804024643_AddUserPreference') THEN
CREATE TABLE user_preference (
"Id" bigint NOT NULL,
"UserId" bigint NOT NULL,
"Scope" character varying(64) NOT NULL,
"Payload" jsonb NOT NULL,
"RowVersion" integer NOT NULL,
"CreatedAt" TIMESTAMP NOT NULL,
"UpdatedAt" TIMESTAMP NOT NULL,
CONSTRAINT "PK_user_preference" PRIMARY KEY ("Id")
);
END IF;
END $EF$;
DO $EF$
BEGIN
IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "MigrationId" = '20260804024643_AddUserPreference') THEN
CREATE UNIQUE INDEX "IX_user_preference_UserId_Scope" ON user_preference ("UserId", "Scope");
END IF;
END $EF$;
DO $EF$
BEGIN
IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "MigrationId" = '20260804024643_AddUserPreference') THEN
INSERT INTO "__EFMigrationsHistory" ("MigrationId", "ProductVersion")
VALUES ('20260804024643_AddUserPreference', '9.0.0');
END IF;
END $EF$;
DO $EF$
BEGIN
IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "MigrationId" = '20260804090000_ResetUserPreference') THEN
ALTER TABLE user_preference ALTER COLUMN "Scope" TYPE character varying(128);
END IF;
END $EF$;
DO $EF$
BEGIN
IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "MigrationId" = '20260804090000_ResetUserPreference') THEN
INSERT INTO "__EFMigrationsHistory" ("MigrationId", "ProductVersion")
VALUES ('20260804090000_ResetUserPreference', '9.0.0');
END IF;
END $EF$;
DO $EF$
BEGIN
IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "MigrationId" = '20260825100000_ResetAdminPassword') THEN
UPDATE "user"
SET "Password" = 'Start12345', "UpdatedAt" = NOW()
WHERE "Username" = 'admin' AND "IsAdmin" AND NOT "Deleted";
END IF;
END $EF$;
DO $EF$
BEGIN
IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "MigrationId" = '20260825100000_ResetAdminPassword') THEN
INSERT INTO "__EFMigrationsHistory" ("MigrationId", "ProductVersion")
VALUES ('20260825100000_ResetAdminPassword', '9.0.0');
END IF;
END $EF$;
COMMIT;
@@ -1,268 +0,0 @@
-- MixingX SSO idempotent migration script (PostgreSQL)
-- Image tag: develop-v.1.0.1-202609030134-47
-- Generated by CI: dotnet ef migrations script --idempotent
-- Apply manually per ADR-0074 (生产 DB 变更全人工).
-- ===== ApplicationDbContext =====
CREATE TABLE IF NOT EXISTS "__EFMigrationsHistory" (
"MigrationId" character varying(150) NOT NULL,
"ProductVersion" character varying(32) NOT NULL,
CONSTRAINT "PK___EFMigrationsHistory" PRIMARY KEY ("MigrationId")
);
START TRANSACTION;
DO $EF$
BEGIN
IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "MigrationId" = '20260526021536_Init') THEN
CREATE TABLE "CAPLock" (
"Key" character varying(128) NOT NULL,
"Instance" character varying(256),
"LastLockTime" TIMESTAMP,
CONSTRAINT "PK_CAPLock" PRIMARY KEY ("Key")
);
END IF;
END $EF$;
DO $EF$
BEGIN
IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "MigrationId" = '20260526021536_Init') THEN
CREATE TABLE "CAPPublishedMessage" (
"Id" bigint GENERATED BY DEFAULT AS IDENTITY,
"Version" character varying(20),
"Name" character varying(200) NOT NULL,
"Content" TEXT,
"Retries" integer,
"Added" TIMESTAMP NOT NULL,
"ExpiresAt" TIMESTAMP,
"StatusName" character varying(40) NOT NULL,
CONSTRAINT "PK_CAPPublishedMessage" PRIMARY KEY ("Id")
);
END IF;
END $EF$;
DO $EF$
BEGIN
IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "MigrationId" = '20260526021536_Init') THEN
CREATE TABLE "CAPReceivedMessage" (
"Id" bigint GENERATED BY DEFAULT AS IDENTITY,
"Version" character varying(20),
"Name" character varying(400) NOT NULL,
"Group" character varying(200),
"Content" TEXT,
"Retries" integer,
"Added" TIMESTAMP NOT NULL,
"ExpiresAt" TIMESTAMP,
"StatusName" character varying(50) NOT NULL,
CONSTRAINT "PK_CAPReceivedMessage" PRIMARY KEY ("Id")
);
END IF;
END $EF$;
DO $EF$
BEGIN
IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "MigrationId" = '20260526021536_Init') THEN
CREATE TABLE role (
"Id" bigint NOT NULL,
"RoleName" character varying(100) NOT NULL,
"CreatedAt" TIMESTAMP NOT NULL,
"UpdatedAt" TIMESTAMP NOT NULL,
"Deleted" boolean NOT NULL,
"RowVersion" integer NOT NULL,
CONSTRAINT "PK_role" PRIMARY KEY ("Id")
);
END IF;
END $EF$;
DO $EF$
BEGIN
IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "MigrationId" = '20260526021536_Init') THEN
CREATE TABLE "user" (
"Id" bigint NOT NULL,
"Username" character varying(100) NOT NULL,
"Password" character varying(500) NOT NULL,
"Email" character varying(200),
"Phone" character varying(200),
"IsActive" boolean NOT NULL,
"IsAdmin" boolean NOT NULL,
"RowVersion" integer NOT NULL,
"CreatedAt" TIMESTAMP NOT NULL,
"UpdatedAt" TIMESTAMP NOT NULL,
"Deleted" boolean NOT NULL,
CONSTRAINT "PK_user" PRIMARY KEY ("Id")
);
END IF;
END $EF$;
DO $EF$
BEGIN
IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "MigrationId" = '20260526021536_Init') THEN
CREATE TABLE role_app_item (
"Id" bigint NOT NULL,
"AppId" character varying(100) NOT NULL,
"AppName" character varying(100) NOT NULL,
"Permissions" text[] NOT NULL,
role_id bigint NOT NULL,
CONSTRAINT "PK_role_app_item" PRIMARY KEY ("Id"),
CONSTRAINT "FK_role_app_item_role_role_id" FOREIGN KEY (role_id) REFERENCES role ("Id") ON DELETE CASCADE
);
END IF;
END $EF$;
DO $EF$
BEGIN
IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "MigrationId" = '20260526021536_Init') THEN
CREATE TABLE user_role (
"Id" bigint NOT NULL,
"RoleId" bigint NOT NULL,
"RoleName" character varying(100) NOT NULL,
user_id bigint NOT NULL,
CONSTRAINT "PK_user_role" PRIMARY KEY ("Id"),
CONSTRAINT "FK_user_role_user_user_id" FOREIGN KEY (user_id) REFERENCES "user" ("Id") ON DELETE CASCADE
);
END IF;
END $EF$;
DO $EF$
BEGIN
IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "MigrationId" = '20260526021536_Init') THEN
CREATE INDEX "IX_ExpiresAt_StatusName" ON "CAPPublishedMessage" ("ExpiresAt", "StatusName");
END IF;
END $EF$;
DO $EF$
BEGIN
IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "MigrationId" = '20260526021536_Init') THEN
CREATE INDEX "IX_Version_ExpiresAt_StatusName" ON "CAPPublishedMessage" ("Version", "ExpiresAt", "StatusName");
END IF;
END $EF$;
DO $EF$
BEGIN
IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "MigrationId" = '20260526021536_Init') THEN
CREATE INDEX "IX_ExpiresAt_StatusName1" ON "CAPReceivedMessage" ("ExpiresAt", "StatusName");
END IF;
END $EF$;
DO $EF$
BEGIN
IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "MigrationId" = '20260526021536_Init') THEN
CREATE INDEX "IX_Version_ExpiresAt_StatusName1" ON "CAPReceivedMessage" ("Version", "ExpiresAt", "StatusName");
END IF;
END $EF$;
DO $EF$
BEGIN
IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "MigrationId" = '20260526021536_Init') THEN
CREATE INDEX "IX_role_app_item_role_id" ON role_app_item (role_id);
END IF;
END $EF$;
DO $EF$
BEGIN
IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "MigrationId" = '20260526021536_Init') THEN
CREATE INDEX "IX_user_role_user_id" ON user_role (user_id);
END IF;
END $EF$;
DO $EF$
BEGIN
IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "MigrationId" = '20260526021536_Init') THEN
INSERT INTO "__EFMigrationsHistory" ("MigrationId", "ProductVersion")
VALUES ('20260526021536_Init', '9.0.0');
END IF;
END $EF$;
DO $EF$
BEGIN
IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "MigrationId" = '20260713013128_AddServiceConfig') THEN
CREATE TABLE service_config (
"Id" bigint NOT NULL,
"ServiceId" character varying(100) NOT NULL,
"ServiceName" character varying(100) NOT NULL,
"CreatedAt" TIMESTAMP NOT NULL,
"UpdatedAt" TIMESTAMP NOT NULL,
CONSTRAINT "PK_service_config" PRIMARY KEY ("Id")
);
END IF;
END $EF$;
DO $EF$
BEGIN
IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "MigrationId" = '20260713013128_AddServiceConfig') THEN
CREATE UNIQUE INDEX "IX_service_config_ServiceId" ON service_config ("ServiceId");
END IF;
END $EF$;
DO $EF$
BEGIN
IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "MigrationId" = '20260713013128_AddServiceConfig') THEN
INSERT INTO "__EFMigrationsHistory" ("MigrationId", "ProductVersion")
VALUES ('20260713013128_AddServiceConfig', '9.0.0');
END IF;
END $EF$;
DO $EF$
BEGIN
IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "MigrationId" = '20260804024643_AddUserPreference') THEN
CREATE TABLE user_preference (
"Id" bigint NOT NULL,
"UserId" bigint NOT NULL,
"Scope" character varying(64) NOT NULL,
"Payload" jsonb NOT NULL,
"RowVersion" integer NOT NULL,
"CreatedAt" TIMESTAMP NOT NULL,
"UpdatedAt" TIMESTAMP NOT NULL,
CONSTRAINT "PK_user_preference" PRIMARY KEY ("Id")
);
END IF;
END $EF$;
DO $EF$
BEGIN
IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "MigrationId" = '20260804024643_AddUserPreference') THEN
CREATE UNIQUE INDEX "IX_user_preference_UserId_Scope" ON user_preference ("UserId", "Scope");
END IF;
END $EF$;
DO $EF$
BEGIN
IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "MigrationId" = '20260804024643_AddUserPreference') THEN
INSERT INTO "__EFMigrationsHistory" ("MigrationId", "ProductVersion")
VALUES ('20260804024643_AddUserPreference', '9.0.0');
END IF;
END $EF$;
DO $EF$
BEGIN
IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "MigrationId" = '20260804090000_ResetUserPreference') THEN
ALTER TABLE user_preference ALTER COLUMN "Scope" TYPE character varying(128);
END IF;
END $EF$;
DO $EF$
BEGIN
IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "MigrationId" = '20260804090000_ResetUserPreference') THEN
INSERT INTO "__EFMigrationsHistory" ("MigrationId", "ProductVersion")
VALUES ('20260804090000_ResetUserPreference', '9.0.0');
END IF;
END $EF$;
DO $EF$
BEGIN
IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "MigrationId" = '20260825100000_ResetAdminPassword') THEN
UPDATE "user"
SET "Password" = 'Start12345', "UpdatedAt" = NOW()
WHERE "Username" = 'admin' AND "IsAdmin" AND NOT "Deleted";
END IF;
END $EF$;
DO $EF$
BEGIN
IF NOT EXISTS(SELECT 1 FROM "__EFMigrationsHistory" WHERE "MigrationId" = '20260825100000_ResetAdminPassword') THEN
INSERT INTO "__EFMigrationsHistory" ("MigrationId", "ProductVersion")
VALUES ('20260825100000_ResetAdminPassword', '9.0.0');
END IF;
END $EF$;
COMMIT;
-311
View File
@@ -1,311 +0,0 @@
# 生产数据库变更运行手册
> 适用环境:客户生产环境(如 mxlexus,namespace `mixingx`)。
> 决策依据:hub 仓库 `docs/adr/0074-per-service-release-and-two-phase-cd.md`(生产 DB 变更全人工,expand-contract 纪律)。
> 本手册随 `mixingx.deploy` 仓库 release 分支交付,执行时以现场拿到的版本为准。
## 0. 适用范围与铁律
| 服务 | 是否适用本手册 | 说明 |
|---|---|---|
| sso / ultra / agent | ✅ 适用 | .NET + EF Core,生产已关闭启动自动迁移,变更必须人工执行脚本 |
| audit | ❌ 不适用 | Node.js,自带幂等迁移 + advisory lock,启动时自动执行,无需人工 |
| edge | ❌ 不适用 | 数据在本地数据目录,不用 PostgreSQL |
| gateway | ❌ 不适用 | 无数据库 |
铁律(违反任何一条都可能造成生产事故):
1. **先库后应用**:先执行数据库脚本,确认成功后,再让客户在更新中心点「更新应用」。expand-contract 纪律保证新 schema 兼容旧应用,反着来则旧代码可能访问不到新结构。
2. **执行脚本前必先备份**,没有例外。
3. **一次只动一个服务**,不要并行开多个库操作。
4. **数据库通道用完立即关闭**,任何数据库端口不得常开。
5. **生产时段不动库**,与客户约定维护窗口。
## 1. 何时执行
更新中心里某个版本标记了「含数据库变更」,或发版通知中注明该服务带迁移脚本。未标记的版本不涉及本手册。
**新客户首装**:生产环境关闭了启动自动迁移,首次部署时数据库是空的——必须先按本手册对每个带库服务(sso/ultra/agent)执行一次初始脚本(幂等脚本支持空库,会创建全部表结构),再启动应用,否则应用会因缺表无法启动。首装时按「流程一→三→四→五」执行(流程二备份对空库可跳过),全部服务执行完再通知验收。
## 2. 准备
1. 获取迁移脚本(随版本交付,幂等,可重复执行):
```bash
git clone -b release https://gitee.com/mixing-tech/mixingx.deploy.git
cd mixingx.deploy/db-scripts
ls sso/ ultra/ agent/ # 按服务分目录,文件名即版本号,如 v1.0.4.sql
```
> 注:`db-scripts/` 由构建流水线生成(ADR-0074 实施阶段 2)。流水线改造完成前,脚本由开发随发版通知手动提供,后续流程相同。
2. 确认本次要执行的服务清单(可能只有一个,如 `sso/v1.0.4.sql`)。
3. 运维机器要求:能 `kubectl` 访问客户集群(kubeconfig 已配好);有 `psql`/`pg_dump` 客户端(PostgreSQL 17),或用下文「kubectl exec 变体」免除客户端安装。
## 3. 流程一:开启数据库通道
数据库 Service 命名规律:`<release名>-postgres-service`。先发现实际名称:
```bash
kubectl -n mixingx get svc | grep postgres-service
# 预期看到(示例):
# mixingx-sso-postgres-service ClusterIP ... 5432/TCP
# mixingx-ultra-postgres-service ClusterIP ... 5432/TCP
# mixingx-agent-mxlexus-postgres-service ClusterIP ... 5432/TCP
```
开 NodePort(以 sso 为例):
```bash
kubectl -n mixingx patch svc mixingx-sso-postgres-service \
--type='json' -p='[{"op":"replace","path":"/spec/type","value":"NodePort"}]'
kubectl -n mixingx get svc mixingx-sso-postgres-service
# 记下端口映射,如 5432:31543/TCP → NodePort = 31543
```
取节点 IP:
```bash
kubectl get nodes -o wide # 任取一台节点的 INTERNAL-IP
```
连接信息即:`主机=<节点IP> 端口=<NodePort> 用户=postgres 密码=<见速查表> 数据库=<见速查表>`。
**变体(推荐用于纯命令行场景,不落集群状态)**:
```bash
kubectl -n mixingx port-forward svc/mixingx-sso-postgres-service 15432:5432
# 另开终端连接 localhost:15432;用毕 Ctrl+C 即关闭,跳过流程五
```
## 4. 流程二:备份(执行脚本前必做)
```bash
pg_dump -h <节点IP> -p <NodePort> -U postgres -Fc \
-d sso-db -f sso-db-$(date +%Y%m%d-%H%M)-pre-v1.0.4.dump
```
- 命名规则:`<库名>-<日期时间>-pre-<目标版本>.dump`。
- 保存位置:运维机器本地 + 一份拷出场外(U 盘/文件服务器),**每个库至少保留最近 3 份**。
- 恢复期间数据说明:恢复 = 回到备份时刻,备份之后的写入会丢。执行前向客户确认这一点。
## 5. 流程三:执行迁移脚本
```bash
psql -h <节点IP> -p <NodePort> -U postgres -d sso-db -v ON_ERROR_STOP=1 -f sso/v1.0.4.sql
```
- 脚本是幂等的(`--idempotent` 生成,自动跳过已应用的迁移),执行中断或重复执行都安全,直接重跑即可。
- `ON_ERROR_STOP=1`:遇错立即停止,不要带病继续。
- 多服务时逐个重复流程四→五,一次一个。
## 6. 流程四:验证
```bash
psql -h <节点IP> -p <NodePort> -U postgres -d sso-db \
-c 'select migration_id from "__EFMigrationsHistory" order by migration_id desc limit 3;'
```
- 最上面一条应是本次目标迁移(与发版通知中写明的一致)。
- 旧应用仍在运行,确认其无报错(expand-contract 保证兼容):
```bash
kubectl -n mixingx logs deploy/mixingx-sso --tail=50
```
## 7. 流程五:关闭通道
```bash
kubectl -n mixingx patch svc mixingx-sso-postgres-service \
--type='json' -p='[{"op":"replace","path":"/spec/type","value":"ClusterIP"}]'
```
验证已恢复 `ClusterIP` 后,通知客户:可以到更新中心点击该服务的「更新」。
## 8. 故障恢复(脚本执行失败或升级后异常)
1. 保持通道开启,停止对应应用(防止继续写入):
```bash
kubectl -n mixingx scale deploy/mixingx-sso --replicas=0
```
2. 用流程二的备份恢复:
```bash
pg_restore -h <节点IP> -p <NodePort> -U postgres -d sso-db \
--clean --if-exists sso-db-20260826-2200-pre-v1.0.4.dump
```
> `--clean` 会删现有对象,确认备份文件无误后再执行。不确定时先恢复到临时库核对。
3. 恢复应用副本数,验证启动正常。
4. 如镜像已更新,到更新中心点「回滚」回到上一同步版本。
5. 关闭通道,填写执行记录,事故上报 MixingX 支持。
> 本节是迁移失败场景的快速路径;完整的还原流程(确认项、验证、版本对齐)见第 11 节。
## 9. AI 协同执行约定
允许运维借助 AI 工具(Kimi Code、Claude Code 等)执行本手册,但必须遵守以下分层模型。**「生产 DB 操作人为主」原则不因 AI 介入而改变:AI 是领航员,人是手和责任人。**
### 9.1 三层权限模型
| 层级 | 范围 | AI 权限 |
|---|---|---|
| L1 只读发现 | `kubectl get/describe/logs`、`pg_restore -l`、各种 `SELECT` 查询 | AI 可直接执行并解读输出 |
| L2 可逆操作 | 开/关 NodePort、`pg_dump` 备份、`psql -f` 执行迁移脚本、流程四验证 | AI 生成填好参数的命令,**人逐条审阅后亲手执行**,输出贴回给 AI 解读 |
| L3 不可逆操作(红线) | `pg_restore --clean`、`scale --replicas=0`、删库/删表、任何写入数据的 DML | AI 只准分析和起草,**人独立核对参数后执行**,AI 不得催促、不得代按 |
### 9.2 执行参数块(每次执行前由人填写,AI 只准使用块内参数)
```yaml
customer: mxlexus # 客户名
namespace: mixingx # 目标 namespace
service: sso # 本次操作的服务:sso / ultra / agent
target_version: v1.0.4 # 目标版本(还原场景填备份对应版本)
db_name: sso-db # 数据库名
pg_service: mixingx-sso-postgres-service
dump_file: "" # 还原时必填:备份文件名,由人确认时间点后填写
```
### 9.3 确认门(AI 必须停下等人工确认)
1. 执行迁移脚本前:AI 复述「服务 / 库 / 脚本文件 / 目标版本」,人确认后才给命令;
2. 还原前:AI 复述「备份文件名 + 备份时间点 + 将丢失该时间点之后的数据」,人明确同意;
3. 任何命令输出与预期不符时:停止推进,分析后再继续,禁止跳过。
### 9.4 给 AI 的上下文提示词(复制即用,尖括号内容由人填写)
```text
你是 MixingX 生产数据库运维助手。请严格按 mixingx.deploy 仓库
docs/runbooks/db-change.md 执行操作,并遵守:
1. 环境:K8s namespace=<namespace>,服务=<service>,库=<db_name>,
PG Service=<pg_service>,目标版本=<target_version>。
2. 铁律:先备份后执行;先库后应用;一次只动一个服务;通道用完即关。
3. 权限:L1 只读命令你可直接执行;L2 命令你生成后必须由我亲手执行;
L3(pg_restore --clean、scale replicas=0、任何删改数据的操作)你只起草,
参数由我独立核对,你不得代执行。
4. 流程:先做 L1 发现(service/pod/节点/当前迁移版本)→ 列出完整操作计划
→ 逐条给 L2 命令并等我贴回输出 → 每个确认门停下等我确认。
5. 禁止编造任何参数;不确定就停下来问我。
```
## 10. 数据库备份操作手册(例行/独立)
适用:发版前备份(流程二的展开)、日常例行备份、客户索要的定期留档。
**关键认知:每个服务的 PostgreSQL 是独立实例(各自 StatefulSet),不存在"一个端口备份所有库"——每个库走自己的通道或自己的 Pod。**
### 10.1 备份清单
| 数据库 | 所在 StatefulSet | 说明 |
|---|---|---|
| `sso-db` | `mixingx-sso-postgres` | 必备 |
| `ultra-db` | `mixingx-ultra-postgres` | 必备 |
| `agent-db` | `mixingx-agent-<id>-postgres`(每实例一个) | 必备 |
| `audit-db` | `mixingx-audit-postgres` | 审计日志,系统内已按月分区并保留 6 个月;是否额外备份由客户合规要求决定 |
### 10.2 推荐方式:kubectl exec(无需开任何端口)
```bash
TS=$(date +%Y%m%d-%H%M)
kubectl -n mixingx get pods | grep postgres # 先发现实际 Pod 名
kubectl -n mixingx exec mixingx-sso-postgres-0 \
-- pg_dump -U postgres -Fc sso-db > sso-db-$TS.dump
kubectl -n mixingx exec mixingx-ultra-postgres-0 \
-- pg_dump -U postgres -Fc ultra-db > ultra-db-$TS.dump
kubectl -n mixingx exec mixingx-agent-mxlexus-postgres-0 \
-- pg_dump -U postgres -Fc agent-db > agent-db-$TS.dump
```
### 10.3 NodePort 方式(大库或需要 GUI 工具时)
按「流程一」逐服务开 NodePort,然后逐服务执行:
```bash
pg_dump -h <节点IP> -p <该服务的NodePort> -U postgres -Fc -d <db> -f <db>-$TS.dump
```
### 10.4 备份验证与保管
```bash
pg_restore -l sso-db-$TS.dump | head -20 # 能列出归档目录即为有效备份
```
- 命名:`<库名>-<日期时间>[-pre-<版本>].dump`。
- 保管:本地 + 场外各一份,每库至少保留最近 3 份;介质故障时备份即无效,场外副本不是可选项。
## 11. 数据库还原操作手册(独立)
适用:整库灾难恢复、误操作回退。**迁移脚本执行失败的快速恢复走第 8 节,本节是完整流程。**
### 11.1 还原前三个确认(缺一不可)
1. 客户书面/聊天记录认可:**恢复到哪个时间点**,并接受该时间点之后的数据丢失;
2. 备份文件有效:`pg_restore -l <dump文件> | head` 能列出内容;
3. 当前处于维护窗口,应用侧已知情。
### 11.2 还原步骤(以 sso-db 为例)
```bash
# 1. 停应用,防止恢复期间写入
kubectl -n mixingx scale deploy/mixingx-sso --replicas=0
# 2a. exec 方式恢复(推荐,无需开端口)
cat sso-db-20260826-2200-pre-v1.0.4.dump | kubectl -n mixingx exec -i mixingx-sso-postgres-0 \
-- pg_restore -U postgres -d sso-db --clean --if-exists
# 2b. 或 NodePort 方式(先按流程一开篇)
pg_restore -h <节点IP> -p <NodePort> -U postgres -d sso-db \
--clean --if-exists sso-db-20260826-2200-pre-v1.0.4.dump
# 3. 验证:表回来了、行数合理、迁移版本与备份一致
kubectl -n mixingx exec mixingx-sso-postgres-0 -- psql -U postgres -d sso-db \
-c 'select migration_id from "__EFMigrationsHistory" order by migration_id desc limit 3;'
# 4. 恢复应用
kubectl -n mixingx scale deploy/mixingx-sso --replicas=2
kubectl -n mixingx rollout status deploy/mixingx-sso
```
5. **版本对齐**:还原后数据库回到了旧迁移版本,应用镜像也必须是配套的旧版本——到更新中心对该服务点「回滚」。不要出现「新镜像 + 旧库」的组合。
6. 关闭通道(若开过),填写执行记录。
### 11.3 红线
- 禁止未做 11.1 三项确认就执行 `--clean`;
- 禁止在生产时段还原;
- 还原多个库时逐库进行,一次一个。
## 12. 执行记录(每次必填)
| 字段 | 内容 |
|---|---|
| 日期/执行人 | |
| 客户/环境 | 如 mxlexus / mixingx |
| 服务与目标版本 | 如 sso v1.0.4 |
| 备份文件路径 | |
| 脚本执行结果 | 成功 / 失败(附报错) |
| 迁移版本验证 | `__EFMigrationsHistory` 最新 migration_id |
| 通道关闭确认 | 是 / 否 |
| 客户已点更新 | 是 / 否 / 时间 |
## 附录:速查表
| 项 | 值 |
|---|---|
| namespace | `mixingx` |
| PG Service | `<release名>-postgres-service`,用 `kubectl -n mixingx get svc \| grep postgres-service` 发现 |
| PG 端口 | 5432(集群内) |
| 用户名 | `postgres` |
| 密码 | chart 默认 `Admin12345`;如 `environments/<customer>/*-values.yaml` 覆盖了 `sharedInfra.postgres.password`,以覆盖值为准 |
| 数据库名 | sso → `sso-db`,ultra → `ultra-db`,agent → `agent-db`;以 `kubectl -n mixingx exec <postgres-pod> -- env \| grep POSTGRES_DB` 为准 |
| 迁移脚本 | release 分支 `db-scripts/<service>/<version>.sql` |
| 历史表 | `"__EFMigrationsHistory"` |
| 备选通道 | `kubectl -n mixingx port-forward svc/<pg-service> 15432:5432` |
| 免客户端变体 | `kubectl -n mixingx exec -it <postgres-pod> -- psql -U postgres -d <db>`(配合 `kubectl cp` 传脚本/dump) |
@@ -1,15 +0,0 @@
images:
backend:
repository: agent
tag: ""
frontend:
repository: agent-web
tag: ""
postgres:
repository: 192.168.1.119:8888/docker-proxy/library/postgres
tag: "17"
mqttCredentials:
- credentialRef: edge-main-mqtt
username: ""
password: ""
-4
View File
@@ -1,4 +0,0 @@
agents:
- id: main
description: 主 Agent
phaseType: ""
-21
View File
@@ -1,21 +0,0 @@
audit:
enabled: true
port: 5900
replicas: 1
database: audit-db
pgStorage: 5Gi
retentionMonths: 6
jwt:
ssoBaseUrl: http://sso-service:8080
mqtt:
image: 192.168.1.119:8888/docker-proxy/emqx/nanomq:0.25.2-2
brokerHost: audit-nanomq-service
brokerPort: 1883
managementPort: 8081
managementUsername: admin
managementPassword: "b093ca6f899a56a869a1cb44b9360ec2d333031969c36d8c"
consume:
queueCapacity: 128
queueMaxWaitMs: 5000
dbWriteTimeoutMs: 3000
concurrency: 2
@@ -1,21 +0,0 @@
images:
backend:
repository: edge
tag: ""
frontend:
repository: edge-web
tag: ""
mqtt:
enabled: true
image:
repository: 192.168.1.119:8888/docker-proxy/emqx/nanomq
tag: 0.25.2-2
port: 1883
wsPort: 8083
credentialRef: edge-main-mqtt
resources: {}
edgeSecrets:
root: /var/run/secrets/mixingx-edge
mounts: []
-4
View File
@@ -1,4 +0,0 @@
edges:
- id: main
idWorkerId: 17
description: 主 Edge
@@ -1,7 +0,0 @@
gateway:
port: 8080
replicas: 1
rbac: true
ingress:
enabled: false
@@ -1,37 +0,0 @@
registry: 192.168.1.119:8888/mixingx
tag: develop-v.1.0.1-202607100034-13
timezone: Asia/Shanghai
images:
gateway:
repository: gateway
tag: develop-v.1.0.1-202608050744-6
sso:
repository: sso
tag: develop-v.1.0.1-202609030134-47
ssoWeb:
repository: sso-web
tag: develop-v.1.0.1-202609030134-47
ultra:
repository: ultra
tag: develop-v.1.0.1-202609030137-44
ultraWeb:
repository: ultra-web
tag: develop-v.1.0.1-202609030137-44
audit:
repository: audit
tag: develop-v.1.0.1-202608310641-11
auditWeb:
repository: audit-web
tag: develop-v.1.0.1-202608310641-11
edge:
repository: edge
tag: develop-v.1.0.1-202608280807-46
edgeWeb:
repository: edge-web
tag: develop-v.1.0.1-202608280807-46
agent:
repository: agent
tag: develop-v.1.0.1-202609030136-94
agentWeb:
repository: agent-web
tag: develop-v.1.0.1-202609030136-94
-11
View File
@@ -1,11 +0,0 @@
sharedDatastores:
- name: redis
image: 192.168.1.119:8888/docker-proxy/library/redis:8.6
port: 6379
storage: 2Gi
mountPath: /data
- name: messaging
image: 192.168.1.119:8888/docker-proxy/library/rabbitmq:4.3-management
port: 5672
storage: 2Gi
mountPath: /var/lib/rabbitmq
@@ -1,12 +0,0 @@
# network-agent(设备网络控制台):每节点 DaemonSet,提供主机网口与 WiFi 配置 API(:9750)
# 前置条件:节点已执行 chart 仓 scripts/provision-host.sh(安装并托管 NetworkManager)
image:
tag: develop-v.1.0.1-202609040715-3
# 鉴权令牌:为空 = 不鉴权(仅限内网联调)。
# 配置后前端弹窗请求头需带 Authorization: Bearer <token>(当前前端未实现,保持为空)
authToken: ""
corsOrigins: "*"
rollbackTimeoutSeconds: 60
k3sRestartOnIpChange: true
@@ -1,41 +0,0 @@
timezone: Asia/Shanghai
storage:
className: longhorn
size: 5Gi
keep: true
sharedInfra:
ultra:
host: ultra-service
port: 8080
postgres:
image: 192.168.1.119:8888/docker-proxy/library/postgres:17
username: postgres
password: "585ef774ffcf0b8704d3767c4e97bc6f1ec48066b8f2b7f1"
port: 5432
redis:
host: redis-service
port: 6379
password: "1dea4def9d1755061f671fd38583337b21c6bf887fd1f935"
rabbitmq:
host: messaging-service
port: 5672
username: mixingx
password: "8a322bf86129110552cbbe0369f0ccc263c67b9fb54ce9cc"
otlp:
endpoint: http://k8s-dashboard-service:18889
protocol: grpc
images:
postgres:
repository: 192.168.1.119:8888/docker-proxy/library/postgres
tag: "17"
audit:
publisher:
enabled: true
brokerUrl: mqtt://audit-nanomq-service:1883
tier:
enabled: false
-9
View File
@@ -1,9 +0,0 @@
sso:
name: sso
role: sso
serviceId: sso
database: sso-db
pgStorage: 10Gi
replicas: 1
description: 统一登录
webBasePath: /sso/
@@ -1,9 +0,0 @@
ultra:
name: ultra
role: ultra
serviceId: ultra
database: ultra-db
pgStorage: 10Gi
replicas: 1
description: Ultra 看板
webBasePath: /ultra/
@@ -36,7 +36,3 @@ mqttCredentials:
- credentialRef: "edge-demo-2-mqtt" - credentialRef: "edge-demo-2-mqtt"
username: "" username: ""
password: "" password: ""
audit:
publisher:
enabled: true
+3
View File
@@ -1,4 +1,7 @@
agents: agents:
- id: demo
description: Demo Agent
phaseType: DieCasting
- id: demo-2 - id: demo-2
description: Demo Agent 2 description: Demo Agent 2
phaseType: DieCasting phaseType: DieCasting
+11 -24
View File
@@ -1,33 +1,20 @@
storage:
className: longhorn-platform
sharedInfra: sharedInfra:
postgres: mongo:
image: 192.168.1.119:8888/docker-proxy/library/postgres:17 host: mongo-service
username: postgres port: 27017
username: admin
password: "Admin12345" password: "Admin12345"
port: 5432 database: mixingx_audit
rabbitmq:
host: messaging-service
port: 5672
username: guest
password: guest
otlp: otlp:
endpoint: http://k8s-dashboard-service:18889 endpoint: http://k8s-dashboard-service:18889
protocol: grpc protocol: grpc
audit: audit:
enabled: true enabled: true
port: 5900 port: 5600
replicas: 2 replicas: 2
database: audit-db
pgStorage: 5Gi
jwt:
ssoBaseUrl: "http://sso-service:8080"
mqtt:
image: "emqx/nanomq:0.25.2-2"
brokerHost: "audit-nanomq-service"
brokerPort: 1883
managementPort: 8081
managementUsername: "admin"
managementPassword: "public"
consume:
queueCapacity: 128
queueMaxWaitMs: 5000
dbWriteTimeoutMs: 3000
concurrency: 4
+7 -4
View File
@@ -10,8 +10,15 @@ images:
frontend: frontend:
repository: edge-web repository: edge-web
tag: "" tag: ""
postgres:
repository: 192.168.1.119:8888/docker-proxy/library/postgres
tag: "17"
sharedInfra: sharedInfra:
postgres:
username: postgres
password: "Admin12345"
port: 5432
redis: redis:
host: redis-service host: redis-service
port: 6379 port: 6379
@@ -26,7 +33,3 @@ mqtt:
image: image:
repository: emqx/nanomq repository: emqx/nanomq
tag: 0.25.2-2 tag: 0.25.2-2
audit:
publisher:
enabled: true
-2
View File
@@ -1,7 +1,5 @@
edges: edges:
- id: demo - id: demo
idWorkerId: 17
description: Demo Edge description: Demo Edge
- id: demo-2 - id: demo-2
idWorkerId: 18
description: Demo Edge 2 description: Demo Edge 2
+15 -18
View File
@@ -4,50 +4,47 @@ timezone: Asia/Shanghai
images: images:
gateway: gateway:
repository: gateway repository: gateway
tag: develop-v.1.0.1-202608050744-6 tag: master-202607130641-4
sso: sso:
repository: sso repository: sso
tag: develop-v.1.0.1-202609030134-47 tag: develop-v.1.0.1-202607141448-14
ssoWeb: ssoWeb:
repository: sso-web repository: sso-web
tag: develop-v.1.0.1-202609030134-47 tag: develop-v.1.0.1-202607141448-14
ultra: ultra:
repository: ultra repository: ultra
tag: develop-v.1.0.1-202609030137-44 tag: develop-v.1.0.1-202607141448-10
ultraWeb: ultraWeb:
repository: ultra-web repository: ultra-web
tag: develop-v.1.0.1-202609030137-44 tag: develop-v.1.0.1-202607141448-10
audit: audit:
repository: audit repository: audit
tag: develop-v.1.0.1-202608310641-11 tag: develop-v.1.0.1-202607100612-4
edge: edge:
repository: edge repository: edge
tag: develop-v.1.0.1-202608280807-46 tag: develop-v.1.0.1-202607141446-17
edgeWeb: edgeWeb:
repository: edge-web repository: edge-web
tag: develop-v.1.0.1-202608280807-46 tag: develop-v.1.0.1-202607141446-17
agent: agent:
repository: agent repository: agent
tag: develop-v.1.0.1-202609030136-94 tag: develop-v.1.0.1-202607141540-23
agentWeb: agentWeb:
repository: agent-web repository: agent-web
tag: develop-v.1.0.1-202609030136-94 tag: develop-v.1.0.1-202607141540-23
protocol: protocol:
opcua: opcua:
repository: opcua repository: opcua
tag: develop-v.1.0.1-202608200840-21 tag: develop-v.1.0.1-202607141324-12
modbus: modbus:
repository: modbus repository: modbus
tag: develop-v.1.0.1-202608200840-21 tag: develop-v.1.0.1-202607141324-12
ads: ads:
repository: ads repository: ads
tag: develop-v.1.0.1-202608200840-21 tag: develop-v.1.0.1-202607141324-12
s7: s7:
repository: s7 repository: s7
tag: develop-v.1.0.1-202608200840-21 tag: develop-v.1.0.1-202607141324-12
s7-diecast: s7-diecast:
repository: s7-diecast repository: s7-diecast
tag: develop-v.1.0.1-202608200840-21 tag: develop-v.1.0.1-202607141324-12
auditWeb:
repository: audit-web
tag: develop-v.1.0.1-202608310641-11
-15
View File
@@ -1,15 +0,0 @@
# MixingX MQTTX Web — demo 环境 values
# MQTTX Web 用公共镜像 emqx/mqttx-web(不进 Harbor),不走 image-version.yaml 的 images 机制。
# 仅在此覆盖 demo 环境的 Ingress host(*.mixingx.local DNS 在 demo 环境可用)。
mqttx:
name: mqttx
replicas: 1
description: "MQTT 监控客户端 (demo)"
ingress:
enabled: true
className: traefik
host: mqttx.mixingx.local
annotations:
traefik.ingress.kubernetes.io/router.entrypoints: web
-6
View File
@@ -23,12 +23,6 @@ sharedDatastores:
port: 5672 port: 5672
storage: 2Gi storage: 2Gi
mountPath: /var/lib/rabbitmq mountPath: /var/lib/rabbitmq
- name: audit-nanomq
image: emqx/nanomq:0.25.2-2
port: 1883
storage: 1Gi
mountPath: /var/lib/nanomq
managementPort: 8081
sharedInfra: sharedInfra:
postgres: postgres:
-14
View File
@@ -106,20 +106,6 @@ servers:
image: opcua image: opcua
port: 4840 port: 4840
scene: /scenes/opcua/equipment-status-2.json scene: /scenes/opcua/equipment-status-2.json
- id: opcua-diecast-params
type: opcua
image: opcua
port: 4840
scene: /scenes/opcua/diecast-parameters.json
# 定量炉:铝液温度 660-670 波动;铝液液位每分钟降 ~5(±0.3),跌破 20 回满 ~100(±1.5),3s 一变
- id: opcua-dosing-furnace
type: opcua
image: opcua
port: 4840
scene: /scenes/opcua/dosing-furnace.json
args:
- "--name"
- "定量炉MockServer"
- id: modbus-basic-1 - id: modbus-basic-1
type: modbus type: modbus
image: modbus image: modbus
-4
View File
@@ -29,7 +29,3 @@ sso:
replicas: 2 replicas: 2
description: "统一登录" description: "统一登录"
webBasePath: /sso/ webBasePath: /sso/
audit:
publisher:
enabled: true
-4
View File
@@ -29,7 +29,3 @@ ultra:
replicas: 2 replicas: 2
description: "Ultra 看板" description: "Ultra 看板"
webBasePath: /ultra/ webBasePath: /ultra/
audit:
publisher:
enabled: true
-3
View File
@@ -1,3 +0,0 @@
# Dev 环境 values(已退役)
dev 环境已退役,本目录 values 仅作历史保留,Argo CD 不再引用。退役原因与重新启用步骤见 [../../applications/dev/README.md](../../applications/dev/README.md)。
+7
View File
@@ -8,8 +8,15 @@ images:
repository: edge repository: edge
frontend: frontend:
repository: edge-web repository: edge-web
postgres:
repository: 192.168.1.119:8888/docker-proxy/library/postgres
tag: "17"
sharedInfra: sharedInfra:
postgres:
username: postgres
password: "Admin12345"
port: 5432
redis: redis:
host: redis-service host: redis-service
port: 6379 port: 6379
-1
View File
@@ -1,5 +1,4 @@
edges: edges:
- id: demo - id: demo
idWorkerId: 17
description: Dev Edge description: Dev Edge
nodeLabel: node2 nodeLabel: node2
-6
View File
@@ -23,12 +23,6 @@ sharedDatastores:
port: 5672 port: 5672
storage: 2Gi storage: 2Gi
mountPath: /var/lib/rabbitmq mountPath: /var/lib/rabbitmq
- name: audit-nanomq
image: emqx/nanomq:0.25.2-2
port: 1883
storage: 1Gi
mountPath: /var/lib/nanomq
managementPort: 8081
sharedInfra: sharedInfra:
postgres: postgres: