Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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