Skip to content

Commit

Permalink
lando/lando#2679: Use DROP/CREATE strategy for MySQL DB reset
Browse files Browse the repository at this point in the history
  • Loading branch information
xurizaemon committed Oct 10, 2022
1 parent 1903ca7 commit 30155c8
Showing 1 changed file with 8 additions and 14 deletions.
22 changes: 8 additions & 14 deletions plugins/lando-services/scripts/sql-import.sh
Original file line number Diff line number Diff line change
Expand Up @@ -109,20 +109,14 @@ if [ "$WIPE" == "true" ]; then
psql postgresql://$USER@$HOST:$PORT/postgres -c "create database $DATABASE"
else
# Build the SQL prefix
SQLSTART="mysql -h $HOST -P $PORT -u $USER ${LANDO_EXTRA_DB_IMPORT_ARGS} $DATABASE"

# Gather and destroy tables
TABLES=$($SQLSTART -e 'SHOW TABLES' | awk '{ print $1}' | grep -v '^Tables' || true)

# PURGE IT ALL! Drop views and tables as needed
for t in $TABLES; do
echo "Dropping $t from $DATABASE database..."
$SQLSTART <<-EOF
SET FOREIGN_KEY_CHECKS=0;
DROP VIEW IF EXISTS \`$t\`;
DROP TABLE IF EXISTS \`$t\`;
EOF
done
SQLSTART="mysql -h $HOST -P $PORT -u $USER ${LANDO_EXTRA_DB_IMPORT_ARGS}"

# Drop and recreate database
lando_yellow "Dropping database ...\n"
$SQLSTART -e "DROP DATABASE IF EXISTS ${DATABASE}"

lando_green "Creating database ...\n"
$SQLSTART -e "CREATE DATABASE ${DATABASE}"
fi
fi

Expand Down

0 comments on commit 30155c8

Please sign in to comment.