增加权限系统

This commit is contained in:
yml2213
2026-05-27 05:41:59 +08:00
parent a04327fd05
commit 1458fc279c
29 changed files with 2276 additions and 46 deletions
+22 -5
View File
@@ -74,20 +74,37 @@ init_database() {
local migration
for migration in "${ROOT_DIR}"/backend/migrations/*.sql; do
log "执行迁移:$(basename "${migration}")"
docker exec -i hfb-mysql mysql -uhfb -psecret hfb_sys < "${migration}"
docker exec -i hfb-mysql mysql -uhfb -psecret --default-character-set=utf8mb4 hfb_sys < "${migration}"
done
else
local chat_table_count
chat_table_count="$(
docker exec hfb-mysql mysql -uhfb -psecret -N -s -e \
"SELECT COUNT(*) FROM information_schema.tables WHERE table_schema = 'hfb_sys' AND table_name = 'chat_conversations';" 2>/dev/null
)"
)" || chat_table_count="0"
if [[ "${chat_table_count}" == "0" ]]; then
log "补充聊天表迁移:000002_chat.sql"
docker exec -i hfb-mysql mysql -uhfb -psecret hfb_sys < "${ROOT_DIR}/backend/migrations/000002_chat.sql"
else
log "数据库结构已存在,跳过迁移"
docker exec -i hfb-mysql mysql -uhfb -psecret --default-character-set=utf8mb4 hfb_sys < "${ROOT_DIR}/backend/migrations/000002_chat.sql"
fi
local role_count
role_count="$(
docker exec hfb-mysql mysql -uhfb -psecret -N -s -e \
"SELECT COUNT(*) FROM information_schema.tables WHERE table_schema = 'hfb_sys' AND table_name = 'roles';" 2>/dev/null
)" || role_count="0"
if [[ "${role_count}" != "0" ]]; then
local seed_count
seed_count="$(
docker exec hfb-mysql mysql -uhfb -psecret -N -s -e \
"SELECT COUNT(*) FROM roles;" 2>/dev/null
)" || seed_count="0"
if [[ "${seed_count}" == "0" ]]; then
log "补充 RBAC 种子数据:000002_rbac_seed.sql"
docker exec -i hfb-mysql mysql -uhfb -psecret --default-character-set=utf8mb4 hfb_sys < "${ROOT_DIR}/backend/migrations/000002_rbac_seed.sql" || true
fi
fi
log "数据库迁移检查完成"
fi
}