Skip to content

Instantly share code, notes, and snippets.

@jrobinsonc
Created September 21, 2018 13:24
Show Gist options
  • Select an option

  • Save jrobinsonc/b1a7692fade85b8d38eab4a89dfbb2d3 to your computer and use it in GitHub Desktop.

Select an option

Save jrobinsonc/b1a7692fade85b8d38eab4a89dfbb2d3 to your computer and use it in GitHub Desktop.
WordPress snippet: Check DB with WP CLI

Check the DB of WordPress

Check using the number of tables.

#/bin/bash

while [ true ]
do
    # Number of actual tables in the database.
    TABLES_QTY=$(wp db tables --allow-root 2>/dev/null | wc -l)
    # Expected number of tables.
    EXPECTED_QTY=12

    if [ $TABLES_QTY == $EXPECTED_QTY ]; then
        break
    fi
done

echo 'DB is ready.'

Check the status of the DB.

#/bin/bash

while [ true ]
do
	DB_STATUS=$(wp db check --allow-root 2>&1| grep "Success: Database checked." | wc -l)

	if [ $DB_STATUS == 1 ]; then
		break
    fi
    
    echo 'DB is ready.'
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment