Skip to content

Commit 1548bee

Browse files
committed
Add better testing conditionals for Mariadb < 10.7
1 parent cc53c23 commit 1548bee

2 files changed

Lines changed: 42 additions & 10 deletions

File tree

src/sql_bridge_test.erl

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,10 +75,20 @@ gen_setup(Adapter, ReplacementType, Host, Port) ->
7575
check_mysql_feature(uuid) ->
7676
Vsn = ?DB:fffr("select @@version"),
7777
io:format("MySQL Version: ~p", [Vsn]),
78-
Enabled = case re:run(Vsn, "mariadb", [caseless, {capture, none}]) of
79-
match ->
80-
io:format("UUID Support Enabled~n"),
81-
true;
78+
79+
Enabled = case re:run(Vsn, "^(\\d+)\\.(\\d+)\\.(\\d+)-mariadb", [caseless, {capture, all_but_first, list}]) of
80+
{match, [Maj, Min, Pat]} ->
81+
Major = list_to_integer(Maj),
82+
Minor = list_to_integer(Min),
83+
Patch = list_to_integer(Pat),
84+
case {Major, Minor, Patch} >= {10, 7, 0} of
85+
true ->
86+
io:format("UUID Support Enabled~n"),
87+
true;
88+
false ->
89+
io:format("UUID Support Disabled (10.7+ Required~n"),
90+
false
91+
end;
8292
nomatch ->
8393
io:format("UUID Tests Disabled~n"),
8494
false

test/db_config.sh

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,20 @@
11
#!/bin/bash
22

3+
compare_versions() {
4+
#if [ $# -ne 2 ]; then
5+
# echo "Usage: compare_versions <version1> <version2>" >&2
6+
# return 2
7+
#fi
8+
9+
if printf '%s\n%s\n' "$1" "$2" | sort -V -c 2>/dev/null; then
10+
echo "$1 <= $2"
11+
return 0
12+
else
13+
echo "$1 > $2"
14+
return 1
15+
fi
16+
}
17+
318
PGCMD="/usr/bin/psql -q"
419
MYSQLCMD="/usr/bin/mysql --verbose"
520

@@ -22,13 +37,20 @@ $PGCMD sql_bridge_test <test/postgres/pg-test-2.sql
2237
echo "[*] Creating and populating the MySQL database"
2338
$MYSQLCMD <test/mysql/create-database.sql
2439

25-
echo "[*] Checking if MySQL is actually MariaDB"
26-
MARIA=$($MYSQLCMD -B sql_bridge_test -e "select version()" | grep -i mariadb)
27-
if [[ -n $MARIA ]]; then
28-
echo "[*] MySQL is MariaDB ($MARIA). Adding UUID Field Types"
29-
$MYSQLCMD <test/mysql/uuid.sql
40+
echo "[*] Checking MySQL Version"
41+
MY_VSN=$($MYSQLCMD -B -e "select version()" | grep "[0-9]")
42+
echo "[*] MySQL Version: $MY_VSN"
43+
IS_MARIA=$(echo $MY_VSN | grep -i mariadb)
44+
if [[ -n $IS_MARIA ]]; then
45+
echo "[*] MySQL is MariaDB"
46+
if [[ $(compare_versions "10.6.99999" "$MY_VSN") ]]; then
47+
echo "[*] MariaDB Version is 10.7+. Enabling UUID Field Types"
48+
$MYSQLCMD <test/mysql/uuid.sql
49+
else
50+
echo "[ ] MariaDB is not 10.7+. Skipping UUID Field Types"
51+
fi
3052
else
31-
echo "[ ] MySQL is NOT MariaDB. Skipping UUID Type Fields"
53+
echo "[ ] MySQL is NOT MariaDB. Skipping UUID Type Fields."
3254
fi
3355

3456
if [[ -z $GITHUB_ACTION ]]; then

0 commit comments

Comments
 (0)