From 23c2912ea804682227d6d7c484076f750cc3c90b Mon Sep 17 00:00:00 2001 From: Toys-A Date: Fri, 7 Aug 2026 03:45:01 +0800 Subject: [PATCH] fix(nacos): Avoid reimporting existing schema - Check for the Nacos config table before importing schema - Preserve config seeding only when no config rows exist - Prevent init failures when the database is already initialized --- backend/sql/nacos-init.sh | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/backend/sql/nacos-init.sh b/backend/sql/nacos-init.sh index e5ce285..e849eab 100644 --- a/backend/sql/nacos-init.sh +++ b/backend/sql/nacos-init.sh @@ -16,7 +16,14 @@ mysql_exec() { echo "Preparing Nacos database ${MYSQL_DB}..." mysql_exec -e "CREATE DATABASE IF NOT EXISTS \`${MYSQL_DB}\` CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;" -mysql_exec "$MYSQL_DB" < /init-sql/nacos-schema.sql + +schema_exists="$(mysql_exec -N -s -e "SELECT COUNT(*) FROM information_schema.TABLES WHERE TABLE_SCHEMA='${MYSQL_DB}' AND TABLE_NAME='config_info';" 2>/dev/null || echo 0)" +if [ "${schema_exists}" -eq 0 ]; then + echo "Initializing Nacos schema..." + mysql_exec "$MYSQL_DB" < /init-sql/nacos-schema.sql +else + echo "Nacos schema already exists, skip schema import." +fi if row_count="$(mysql_exec -N -s -e "SELECT COUNT(*) FROM \`${MYSQL_DB}\`.config_info;" 2>/dev/null)"; then : @@ -30,4 +37,3 @@ if [ "${row_count}" -eq 0 ]; then else echo "Nacos config already exists, skip seeding." fi -