Files
jiu/.gitea/workflows/seed.yml
T
wangjia acf2b22201
Deploy / deploy (push) Successful in 1m14s
fix(seeds): 修复多门店种子数据互不干扰
- S001.sql: 修复 INSERT IGNORE INTO 缺少空格的语法错误
- S002.sql: 重写为动态 @shop_id 模式,移除 TRUNCATE,改用 INSERT IGNORE INTO
- clear_shop.sql: 新增按 @shop_code 清空单店数据的参数化脚本
- scripts/dev.sh: seed 命令支持 --clear 参数(先清空再写入)
- seed.yml: 新增 clear 输入参数,支持按需清空后写入

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-24 13:52:47 +08:00

58 lines
1.9 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.EC2_SSH_KEY }}" > ~/.ssh/ec2_deploy.pem
chmod 600 ~/.ssh/ec2_deploy.pem
ssh-keyscan -H ${{ secrets.EC2_HOST }} >> ~/.ssh/known_hosts
- name: Seed databases
env:
EC2_HOST: ${{ secrets.EC2_HOST }}
EC2_USER: ${{ secrets.EC2_USER }}
DB_PASSWORD: ${{ secrets.DB_PASSWORD }}
SHOPS: ${{ github.event.inputs.shops }}
CLEAR: ${{ github.event.inputs.clear }}
run: |
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 ..."
if [ "$CLEAR" = "true" ]; then
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 mysql -uroot -p${DB_PASSWORD} --default-character-set=utf8mb4 jiu_db"
fi
ssh -i ~/.ssh/ec2_deploy.pem ${EC2_USER}@${EC2_HOST} \
"docker exec -i jiu_mysql mysql -uroot -p${DB_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