整理数据库迁移文件和开发脚本
- 合并迁移文件为 000001_init.sql(表结构)和 000002_seed.sql(初始数据) - 删除旧的迁移文件(000002_chat.sql、000002_rbac_seed.sql、000007_chat_enhancements.sql) - 简化 dev.sh 迁移逻辑,移除对已删除文件的引用 - 添加聊天相关表(chat_quick_replies)到初始化脚本 Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.7
parent
138f0514a9
commit
0d9fec01f3
+2
-29
@@ -70,41 +70,14 @@ init_database() {
|
||||
)"
|
||||
|
||||
if [[ "${table_count}" == "0" ]]; then
|
||||
log "首次启动,初始化数据库结构..."
|
||||
log "首次启动,初始化数据库..."
|
||||
local migration
|
||||
for migration in "${ROOT_DIR}"/backend/migrations/*.sql; do
|
||||
log "执行迁移:$(basename "${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 --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 "数据库迁移检查完成"
|
||||
log "数据库已存在,跳过迁移(使用 DEV_RESET_DB=1 重建)"
|
||||
fi
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user