Skip to content

Commit 6b6f201

Browse files
authored
Merge pull request #116 from wp-cli/fix/add-support-for-mariadb
Add support for MariaDB
2 parents 38a511e + 41d80e5 commit 6b6f201

File tree

1 file changed

+16
-7
lines changed

1 file changed

+16
-7
lines changed

bin/install-package-tests

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,29 +42,38 @@ if [ -n "$WP_CLI_TEST_DBPASS" ]; then
4242
fi
4343

4444
# Prepare the database for running the tests with a MySQL version 8.0 or higher.
45-
install_db_8_0_plus() {
45+
install_mysql_db_8_0_plus() {
46+
set -ex
4647
mysql -e "CREATE DATABASE IF NOT EXISTS \`wp_cli_test\`;" $HOST_STRING -u"$USER" "$PASSWORD_STRING"
4748
mysql -e "CREATE USER IF NOT EXISTS \`wp_cli_test\`@'%' IDENTIFIED WITH mysql_native_password BY '$TEST_PASSWORD'" $HOST_STRING -u"$USER" "$PASSWORD_STRING"
4849
mysql -e "GRANT ALL PRIVILEGES ON \`wp_cli_test\`.* TO '$TEST_USER'@'%'" $HOST_STRING -u"$USER" "$PASSWORD_STRING"
4950
mysql -e "GRANT ALL PRIVILEGES ON \`wp_cli_test_scaffold\`.* TO '$TEST_USER'@'%'" $HOST_STRING -u"$USER" "$PASSWORD_STRING"
5051
}
5152

5253
# Prepare the database for running the tests with a MySQL version lower than 8.0.
53-
install_db_lower_than_8_0() {
54+
install_mysql_db_lower_than_8_0() {
55+
set -ex
5456
mysql -e "CREATE DATABASE IF NOT EXISTS \`wp_cli_test\`;" $HOST_STRING -u"$USER" "$PASSWORD_STRING"
5557
mysql -e "GRANT ALL ON \`wp_cli_test\`.* TO '$TEST_USER'@'%' IDENTIFIED BY '$TEST_PASSWORD'" $HOST_STRING -u"$USER" "$PASSWORD_STRING"
5658
mysql -e "GRANT ALL ON \`wp_cli_test_scaffold\`.* TO '$TEST_USER'@'%' IDENTIFIED BY '$TEST_PASSWORD'" $HOST_STRING -u"$USER" "$PASSWORD_STRING"
5759
}
5860

59-
set -ex
60-
6161
VERSION_STRING=$(mysql -e "SELECT VERSION()" --skip-column-names $HOST_STRING -u"$USER" "$PASSWORD_STRING")
6262
VERSION=$(echo "$VERSION_STRING" | grep -o '^[^-]*')
6363
MAJOR=$(echo "$VERSION" | cut -d. -f1)
6464
MINOR=$(echo "$VERSION" | cut -d. -f2)
65+
TYPE="MySQL"
66+
case "$VERSION_STRING" in
67+
*"MariaDB"*)
68+
TYPE="MariaDB"
69+
;;
70+
esac
71+
72+
echo "Detected $TYPE at version $MAJOR.$MINOR"
73+
6574

66-
if [ "$MAJOR" -ge 8 ]; then
67-
install_db_8_0_plus
75+
if [ "$TYPE" != "MariaDB" ] && [ "$MAJOR" -ge 8 ]; then
76+
install_mysql_db_8_0_plus
6877
else
69-
install_db_lower_than_8_0
78+
install_mysql_db_lower_than_8_0
7079
fi

0 commit comments

Comments
 (0)