From 30155c8aac938040a333e7be2529cb1d41e0b7cc Mon Sep 17 00:00:00 2001 From: Chris Burgess Date: Wed, 3 Nov 2021 11:22:28 +1300 Subject: [PATCH] lando/lando#2679: Use DROP/CREATE strategy for MySQL DB reset --- plugins/lando-services/scripts/sql-import.sh | 22 +++++++------------- 1 file changed, 8 insertions(+), 14 deletions(-) diff --git a/plugins/lando-services/scripts/sql-import.sh b/plugins/lando-services/scripts/sql-import.sh index 688f4a18d..eed811c74 100755 --- a/plugins/lando-services/scripts/sql-import.sh +++ b/plugins/lando-services/scripts/sql-import.sh @@ -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