Files
wehub-resource-sync 5357c39144
Fuzzer / Run Fuzzer (push) Has been cancelled
Race tests / Go race tests (ubuntu-22.04) (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 13:01:40 +08:00

59 lines
1.4 KiB
Bash

setup_dolt_repo() {
REPO_NAME="dolt_repo_$$"
mkdir "$REPO_NAME"
cd "$REPO_NAME" || exit
dolt init
dolt sql -q "CREATE TABLE mysqldump_table(pk int)"
dolt sql -q "INSERT INTO mysqldump_table VALUES (1);"
dolt sql -q "CREATE TABLE warehouse(warehouse_id int primary key, warehouse_name longtext)"
dolt sql -q "INSERT into warehouse VALUES (1, 'UPS'), (2, 'TV'), (3, 'Table');"
PORT=$( definePORT )
USER="dolt"
VERSION_STRING="$1"
dolt sql -q "CREATE USER dolt@'%' IDENTIFIED BY ''; GRANT ALL ON *.* TO dolt@'%';"
if [[ -n "$VERSION_STRING" ]]; then
cat << YAML > config.yaml
listener:
host: "0.0.0.0"
port: $PORT
system_variables:
version: '$VERSION_STRING'
YAML
echo "config" "$1"
dolt sql-server --host 0.0.0.0 --port="$PORT" --loglevel=trace --config config.yaml &
else
echo "config" "$1"
dolt sql-server --host 0.0.0.0 --port="$PORT" --loglevel=trace &
fi
SERVER_PID=$!
# Give the server a chance to start
sleep 1
}
teardown_dolt_repo() {
kill $SERVER_PID || :
wait $SERVER_PID || :
SERVER_PID=
rm -rf $REPO_NAME
}
definePORT() {
local portInUse
local getPORT=""
local i
for i in {0..9}
do
((getPORT = ($$ + i) % (65536 - 1024) + 1024))
portInUse="$(lsof -i -P -n | grep LISTEN | grep -c "$getPORT")"
if [[ "$portInUse" -eq 0 ]] || false
then
echo "$getPORT"
break
fi
done
}