Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
#This script changes the database with the latest file in repo's !sql folder. This script is triggered by a manual step in bitbucket pipeline
cd !sqldump;
latest_sql_file=`ls -Art | tail -n 1`;
cd ..
#connect to devel database and
#1. drop the current database there
TABLES=$(mysql --host <host> -u <user> -p<pass> <db-name> -e 'show tables' | awk '{ print $1}' | grep -v '^Tables' );
for t in $TABLES
echo "Deleting $t table from <db-name> database..."
mysql --host <host> -u <user> -p<pass> <db-name> -e "drop table $t"
#2 inject the new database
mysql --host "<host>" -u "user" -p<pass> "<db-name>" < pre_db.sql
echo "pre db script executed"
mysql --host "<host>" -u "user" -p<pass> "<db-name>" < "!sqldump/$latest_sql_file/$latest_sql_file.sql"
echo "new sql file inserted"
mysql --host "<host>" -u "user" -p<pass> "<db-name>" < post_db.sql
echo "post db escript executed"
mysql --host <host> -u <user> -p<pass> <db-name> -e update table wp_options set siteurl="<site-url>"
echo "changed wp_options table siteurl"
mysql --host <host> -u <user> -p<pass> <db-name> -e update table wp_options set home="<site-url>"
echo "changed wp_options table home url"
echo "database successfully changed on devel"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.