Merge pull request #325 from mbentley/db-exist-check

Added check to skip db import if exists
This commit is contained in:
Ying Li 2015-12-02 15:27:46 -08:00
commit cb2b2951e0
1 changed files with 16 additions and 12 deletions

View File

@ -95,6 +95,9 @@ if [ -n "${DB_USER}" -o -n "${DB_NAME}" ]; then
if [ -n "${DB_NAME}" ]; then if [ -n "${DB_NAME}" ]; then
for db in $(awk -F',' '{for (i = 1 ; i <= NF ; i++) print $i}' <<< "${DB_NAME}"); do for db in $(awk -F',' '{for (i = 1 ; i <= NF ; i++) print $i}' <<< "${DB_NAME}"); do
if mysql --defaults-file=/etc/mysql/debian.cnf -e "USE $db;" 2>/dev/null; then
echo "Database \"$db\" exists"
else
echo "Creating database \"$db\"..." echo "Creating database \"$db\"..."
mysql --defaults-file=/etc/mysql/debian.cnf \ mysql --defaults-file=/etc/mysql/debian.cnf \
-e "CREATE DATABASE IF NOT EXISTS \`$db\` DEFAULT CHARACTER SET \`utf8\` COLLATE \`utf8_unicode_ci\`;" -e "CREATE DATABASE IF NOT EXISTS \`$db\` DEFAULT CHARACTER SET \`utf8\` COLLATE \`utf8_unicode_ci\`;"
@ -106,6 +109,7 @@ if [ -n "${DB_USER}" -o -n "${DB_NAME}" ]; then
# Create our Database: # Create our Database:
mysql -uroot $db < ./initial.sql mysql -uroot $db < ./initial.sql
mysql -uroot $db < ./migrate.sql mysql -uroot $db < ./migrate.sql
fi
done done
fi fi
/usr/bin/mysqladmin --defaults-file=/etc/mysql/debian.cnf shutdown /usr/bin/mysqladmin --defaults-file=/etc/mysql/debian.cnf shutdown