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
This commit is contained in:
@@ -16,7 +16,14 @@ mysql_exec() {
|
|||||||
|
|
||||||
echo "Preparing Nacos database ${MYSQL_DB}..."
|
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 -e "CREATE DATABASE IF NOT EXISTS \`${MYSQL_DB}\` CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;"
|
||||||
|
|
||||||
|
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
|
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
|
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
|
else
|
||||||
echo "Nacos config already exists, skip seeding."
|
echo "Nacos config already exists, skip seeding."
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user