Skip to content

Commit

Permalink
Use DROP/CREATE strategy for MySQL DB reset
Browse files Browse the repository at this point in the history
- Refs lando/lando#2679
- Replaces lando/legacy-cli#59
  • Loading branch information
xurizaemon committed Jul 21, 2023
1 parent 1c91e18 commit 03c9761
Showing 1 changed file with 5 additions and 13 deletions.
18 changes: 5 additions & 13 deletions plugins/services/scripts/sql-import.sh
Original file line number Diff line number Diff line change
Expand Up @@ -108,21 +108,13 @@ if [ "$WIPE" == "true" ]; then
lando_green "\t\tCreating database ...\n\n"
psql postgresql://$USER@$HOST:$PORT/postgres -c "create database $DATABASE"
else
# Build the SQL prefix
# Drop and recreate database
SQLSTART="mysql -h $HOST -P $PORT -u $USER ${LANDO_EXTRA_DB_IMPORT_ARGS} $DATABASE"
lando_yellow "\t\tDropping database ...\n\n"
$SQLSTART -e "DROP DATABASE IF EXISTS ${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
lando_green "\t\tCreating database ...\n\n"
$SQLSTART -e "CREATE DATABASE ${DATABASE}"
fi
fi

Expand Down

0 comments on commit 03c9761

Please sign in to comment.