Skip to content

Commit

Permalink
fix: 修正数据库检测
Browse files Browse the repository at this point in the history
  • Loading branch information
wojiushixiaobai committed Jul 4, 2024
1 parent cfa3557 commit 2de3ccd
Showing 1 changed file with 36 additions and 13 deletions.
49 changes: 36 additions & 13 deletions scripts/utils.sh
Original file line number Diff line number Diff line change
Expand Up @@ -108,29 +108,52 @@ function disable_config() {
}

function check_db_data() {
db_type=$1
if [[ ! -f "${CONFIG_FILE}" ]]; then
return
fi
volume_dir=$(get_config VOLUME_DIR)
db_name=$(get_config DB_NAME)
if [[ -d "${volume_dir}/${db_type}/data/${db_name}" ]]; then
echo "1"
fi
db_type=$1
if [[ ! -f "${CONFIG_FILE}" ]]; then
return
fi
volume_dir=$(get_config VOLUME_DIR)
if [[ -d "${volume_dir}/${db_type}/data" ]]; then
echo "1"
else
echo "0"
fi
}

function get_db_info() {
info_type=$1
mysql_data_exists=$(check_db_data "mysql")
mariadb_data_exists=$(check_db_data "mariadb")
db_engine=$(get_config DB_ENGINE "mysql")
db_host=$(get_config DB_HOST)

mysql_data_exists="0"
mariadb_data_exists="0"
postgres_data_exists="0"

case "${db_engine}" in
"mysql")
if [[ "${db_host}" == "mysql" ]]; then
mysql_data_exists=$(check_db_data "mysql")
mariadb_data_exists=$(check_db_data "mariadb")
else
mariadb_data_exists="1"
fi
;;
"postgresql")
if [[ "${db_host}" == "postgresql" ]]; then
postgres_data_exists=$(check_db_data "postgresql")
else
postgres_data_exists="1"
fi
;;
esac

case "${info_type}" in
"image")
if [[ "${mysql_data_exists}" == "1" ]]; then
echo "mysql:5.7"
elif [[ "${mariadb_data_exists}" == "1" ]]; then
echo "mariadb:10.6"
else
elif [[ "${postgres_data_exists}" == "1" ]]; then
echo "postgres:16.3-bullseye"
fi
;;
Expand All @@ -139,7 +162,7 @@ function get_db_info() {
echo "compose/mysql.yml"
elif [[ "${mariadb_data_exists}" == "1" ]]; then
echo "compose/mariadb.yml"
else
elif [[ "${postgres_data_exists}" == "1" ]]; then
echo "compose/postgres.yml"
fi
;;
Expand Down

0 comments on commit 2de3ccd

Please sign in to comment.