Files
jiu/.gitea/workflows/seed.yml
T
wangjia 824992fe6e devops: 备案通过回切 https 域名 + 流水线 Ali 单轨
- nginx-jiu-ali.conf:443 ssl+http2 正式入口(HSTS/XFO/nosniff 安全头、
  ACME webroot 续期通道、80→443 跳转);8443 明文过渡口拆除
- 客户端构建 URL 全量回切 https://jiu.51yanmei.com(compile×5/local_test/
  release-client/notify)
- 流水线去 EC2:deploy-client/site 单轨 Ali、manual 回滚与每日备份切 ali、
  seed/reset/debug-db 改容器内取密码(SEC-003,退役 DB_PASSWORD secret)

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01JJ1g8XV1YhhmHRzhwWEW7o
2026-07-03 09:58:30 +08:00

66 lines
2.3 KiB
YAML
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
name: Seed DB
on:
workflow_dispatch:
inputs:
shops:
description: '要写入的门店(逗号分隔,如 S001,S002,S003'
required: true
default: 'S001,S002,S003'
clear:
description: '写入前先清空各门店数据(true/false'
required: false
default: 'false'
jobs:
seed:
runs-on: mac
steps:
- uses: actions/checkout@v4
- name: Setup SSH
run: |
mkdir -p ~/.ssh
printf '%s' "${{ secrets.ALI_SSH_KEY }}" > ~/.ssh/ec2_deploy.pem
chmod 600 ~/.ssh/ec2_deploy.pem
ssh-keyscan -H ${{ secrets.ALI_HOST }} >> ~/.ssh/known_hosts
- name: Seed databases
env:
EC2_HOST: ${{ secrets.ALI_HOST }}
EC2_USER: ${{ secrets.ALI_USER }}
SHOPS: ${{ github.event.inputs.shops }}
CLEAR: ${{ github.event.inputs.clear }}
run: |
# 第一步:若需要清空,先把所有门店都清掉再写入
# 避免 S001(id=1 硬编码) 因 S002 占用 id=1 而被 INSERT IGNORE 跳过
if [ "$CLEAR" = "true" ]; then
echo "=== 清空阶段 ==="
for SHOP in $(echo "$SHOPS" | tr ',' ' '); do
echo " 清空 ${SHOP}..."
printf "SET @shop_code='%s';\n" "$SHOP" | cat - backend/seeds/clear_shop.sql | \
ssh -i ~/.ssh/ec2_deploy.pem ${EC2_USER}@${EC2_HOST} \
"docker exec -i jiu_mysql sh -c 'exec mysql -uroot -p\$MYSQL_ROOT_PASSWORD --default-character-set=utf8mb4 jiu_db'"
done
echo "✓ 清空完成"
fi
# 第二步:依次写入所有门店
echo "=== 写入阶段 ==="
for SHOP in $(echo "$SHOPS" | tr ',' ' '); do
FILE="backend/seeds/${SHOP}.sql"
if [ ! -f "$FILE" ]; then
echo "⚠️ $FILE not found, skipping"
continue
fi
echo "→ Seeding $SHOP ..."
ssh -i ~/.ssh/ec2_deploy.pem ${EC2_USER}@${EC2_HOST} \
"docker exec -i jiu_mysql sh -c 'exec mysql -uroot -p\$MYSQL_ROOT_PASSWORD --default-character-set=utf8mb4 jiu_db'" \
< "$FILE"
echo "✓ $SHOP done"
done
- name: Cleanup SSH key
if: always()
run: rm -f ~/.ssh/ec2_deploy.pem