mirror of
https://github.com/dolthub/dolt.git
synced 2026-05-04 11:30:14 -05:00
mv order to match mysql
This commit is contained in:
@@ -369,15 +369,6 @@ _main() {
|
||||
set -- "$@" --config="$CONFIG_PROVIDED"
|
||||
fi
|
||||
|
||||
if [[ ! -f $INIT_COMPLETED ]]; then
|
||||
if ls /docker-entrypoint-initdb.d/* >/dev/null 2>&1; then
|
||||
docker_process_init_files /docker-entrypoint-initdb.d/*
|
||||
else
|
||||
mysql_warn "No files found in /docker-entrypoint-initdb.d/ to process"
|
||||
fi
|
||||
touch "$INIT_COMPLETED"
|
||||
fi
|
||||
|
||||
create_database_from_env
|
||||
|
||||
mysql_note "Starting Dolt server in the background..."
|
||||
@@ -401,12 +392,22 @@ _main() {
|
||||
exec_mysql "CREATE USER IF NOT EXISTS 'root'@'${DOLT_ROOT_HOST}' IDENTIFIED BY '${DOLT_ROOT_PASSWORD}';" "Could not create root user: " # override password
|
||||
exec_mysql "GRANT ALL PRIVILEGES ON *.* TO 'root'@'${DOLT_ROOT_HOST}' WITH GRANT OPTION;" "Could not set root privileges: "
|
||||
fi
|
||||
|
||||
mysql_note "'root@${DOLT_ROOT_HOST}' user successfully configured!"
|
||||
|
||||
create_user_from_env
|
||||
|
||||
exec_mysql "SELECT User, Host FROM mysql.user;" "Could not list users: " 1
|
||||
|
||||
if [[ ! -f $INIT_COMPLETED ]]; then
|
||||
if ls /docker-entrypoint-initdb.d/* >/dev/null 2>&1; then
|
||||
docker_process_init_files /docker-entrypoint-initdb.d/*
|
||||
else
|
||||
mysql_warn "No files found in /docker-entrypoint-initdb.d/ to process"
|
||||
fi
|
||||
touch "$INIT_COMPLETED"
|
||||
fi
|
||||
|
||||
mysql_note "Server initialization complete!"
|
||||
|
||||
# No need to relaunch, we wait for the background server process to exit and can still see the logs
|
||||
|
||||
@@ -112,7 +112,7 @@ $ docker build -f dolt/docker/serverDockerfile --build-arg DOLT_VERSION=source -
|
||||
# Note: This should contain dolt/ at the minimum, any other repos need to be
|
||||
# added via COPY in serverDockerfile.
|
||||
|
||||
$ docker run -e DOLT_ROOT_PASSWORD=secret2 -e DOLT_ROOT_HOST=% -p 3307:3306 dolt-sql-server:source
|
||||
$ docker run -p 3307:3306 -e DOLT_ROOT_PASSWORD=secret2 -e DOLT_ROOT_HOST=% dolt-sql-server:source
|
||||
```
|
||||
|
||||
### Connect to the server in the container from the host system
|
||||
|
||||
@@ -29,7 +29,7 @@ setup() {
|
||||
|
||||
teardown() {
|
||||
docker ps -a --filter "name=$TEST_PREFIX" --format '{{.Names}}' | xargs -r docker stop >/dev/null 2>&1 || true
|
||||
# docker ps -a --filter "name=$TEST_PREFIX" --format '{{.Names}}' | xargs -r docker rm -f >/dev/null 2>&1 || true
|
||||
docker ps -a --filter "name=$TEST_PREFIX" --format '{{.Names}}' | xargs -r docker rm -f >/dev/null 2>&1 || true
|
||||
teardown_common
|
||||
}
|
||||
|
||||
@@ -544,7 +544,7 @@ INSERT INTO init_test VALUES (3, 'Compressed SQL executed');
|
||||
EOF
|
||||
gzip "$temp_dir/03-data.sql"
|
||||
|
||||
run_container_with_port "$cname" 3306 -e DOLT_ROOT_PASSWORD=rootpass -e DOLT_ROOT_HOST=% -e DOLT_TIMEOUT=3 -v "$temp_dir:/docker-entrypoint-initdb.d"
|
||||
run_container_with_port "$cname" 3306 -e DOLT_ROOT_PASSWORD=rootpass -e DOLT_ROOT_HOST=% -v "$temp_dir:/docker-entrypoint-initdb.d"
|
||||
|
||||
run docker run --rm --network host mysql:8.0 mysql -h 127.0.0.1 -P 3306 -u root --password=rootpass -e "SHOW DATABASES;"
|
||||
[ $status -eq 0 ]
|
||||
@@ -562,10 +562,10 @@ EOF
|
||||
# bats test_tags=no_lambda
|
||||
@test "docker-entrypoint: plain .sql file processing" {
|
||||
cname="${TEST_PREFIX}plain-sql"
|
||||
|
||||
|
||||
local temp_dir="/tmp/plain-sql-test-$$"
|
||||
mkdir -p "$temp_dir"
|
||||
|
||||
|
||||
cat > "$temp_dir/01-init.sql" << 'EOF'
|
||||
CREATE DATABASE IF NOT EXISTS plain_sql_db;
|
||||
USE plain_sql_db;
|
||||
@@ -576,21 +576,21 @@ CREATE USER IF NOT EXISTS 'plainsqluser'@'%' IDENTIFIED BY 'plainsqlpass';
|
||||
GRANT ALL ON `plain_sql_db`.* TO 'plainsqluser'@'%';
|
||||
GRANT USAGE ON *.* TO 'plainsqluser'@'%';
|
||||
EOF
|
||||
|
||||
|
||||
run_container_with_port "$cname" 3306 -e DOLT_ROOT_PASSWORD=rootpass -e DOLT_ROOT_HOST=% -v "$temp_dir:/docker-entrypoint-initdb.d"
|
||||
|
||||
|
||||
run docker run --rm --network host mysql:8.0 mysql -h 127.0.0.1 -P 3306 -u root --password=rootpass -e "SHOW DATABASES;"
|
||||
[ $status -eq 0 ]
|
||||
[[ "$output" =~ "plain_sql_db" ]] || false
|
||||
|
||||
|
||||
run docker run --rm --network host mysql:8.0 mysql -h 127.0.0.1 -P 3306 -u root --password=rootpass -e "USE plain_sql_db; SELECT COUNT(*) as count FROM users_table;"
|
||||
[ $status -eq 0 ]
|
||||
[[ "$output" =~ "2" ]] || false
|
||||
|
||||
|
||||
run docker run --rm --network host mysql:8.0 mysql -h 127.0.0.1 -P 3306 -u plainsqluser --password=plainsqlpass -e "USE plain_sql_db; SELECT * FROM users_table WHERE username='alice';"
|
||||
[ $status -eq 0 ]
|
||||
[[ "$output" =~ "alice@example.com" ]] || false
|
||||
|
||||
|
||||
rm -rf "$temp_dir"
|
||||
}
|
||||
|
||||
@@ -601,10 +601,10 @@ EOF
|
||||
fi
|
||||
|
||||
cname="${TEST_PREFIX}gzip-sql"
|
||||
|
||||
|
||||
local temp_dir="/tmp/gzip-sql-test-$$"
|
||||
mkdir -p "$temp_dir"
|
||||
|
||||
|
||||
cat > "$temp_dir/01-init.sql" << 'EOF'
|
||||
CREATE DATABASE IF NOT EXISTS gzip_sql_db;
|
||||
USE gzip_sql_db;
|
||||
@@ -617,22 +617,22 @@ GRANT ALL ON `gzip_sql_db`.* TO 'gzipuser'@'%';
|
||||
GRANT USAGE ON *.* TO 'gzipuser'@'%';
|
||||
EOF
|
||||
gzip "$temp_dir/01-init.sql"
|
||||
|
||||
|
||||
run_container_with_port "$cname" 3306 -e DOLT_ROOT_PASSWORD=rootpass -e DOLT_ROOT_HOST=% -v "$temp_dir:/docker-entrypoint-initdb.d"
|
||||
|
||||
|
||||
run docker run --rm --network host mysql:8.0 mysql -h 127.0.0.1 -P 3306 -u root --password=rootpass -e "SHOW DATABASES;"
|
||||
[ $status -eq 0 ]
|
||||
[[ "$output" =~ "gzip_sql_db" ]] || false
|
||||
|
||||
|
||||
run docker run --rm --network host mysql:8.0 mysql -h 127.0.0.1 -P 3306 -u root --password=rootpass -e "USE gzip_sql_db; SELECT COUNT(*) as count FROM products;"
|
||||
[ $status -eq 0 ]
|
||||
[[ "$output" =~ "3" ]] || false
|
||||
|
||||
|
||||
run docker run --rm --network host mysql:8.0 mysql -h 127.0.0.1 -P 3306 -u gzipuser --password=gzippass -e "USE gzip_sql_db; SELECT name FROM products WHERE price > 25.00;"
|
||||
[ $status -eq 0 ]
|
||||
[[ "$output" =~ "Gadget" ]] || false
|
||||
[[ "$output" =~ "Doohickey" ]] || false
|
||||
|
||||
|
||||
rm -rf "$temp_dir"
|
||||
}
|
||||
|
||||
@@ -641,12 +641,12 @@ EOF
|
||||
if ! command -v bzip2 >/dev/null 2>&1; then
|
||||
skip "bzip2 not installed on host system"
|
||||
fi
|
||||
|
||||
|
||||
cname="${TEST_PREFIX}bzip2-sql"
|
||||
|
||||
|
||||
local temp_dir="/tmp/bzip2-sql-test-$$"
|
||||
mkdir -p "$temp_dir"
|
||||
|
||||
|
||||
cat > "$temp_dir/01-init.sql" << 'EOF'
|
||||
CREATE DATABASE IF NOT EXISTS bzip2_sql_db;
|
||||
USE bzip2_sql_db;
|
||||
@@ -659,13 +659,9 @@ GRANT ALL ON `bzip2_sql_db`.* TO 'bzip2user'@'%';
|
||||
GRANT USAGE ON *.* TO 'bzip2user'@'%';
|
||||
EOF
|
||||
bzip2 "$temp_dir/01-init.sql"
|
||||
|
||||
|
||||
run_container_with_port "$cname" 3306 -e DOLT_ROOT_PASSWORD=rootpass -e DOLT_ROOT_HOST=% -v "$temp_dir:/docker-entrypoint-initdb.d"
|
||||
|
||||
echo "=== Container logs for $cname ==="
|
||||
docker logs "$cname" 2>&1 || true
|
||||
echo "=== End of container logs ==="
|
||||
|
||||
|
||||
run docker run --rm --network host mysql:8.0 mysql -h 127.0.0.1 -P 3306 -u root --password=rootpass -e "SHOW DATABASES;"
|
||||
if [ $status -ne 0 ]; then
|
||||
echo "Failed to show databases. Output: $output"
|
||||
@@ -673,7 +669,7 @@ EOF
|
||||
return 1
|
||||
fi
|
||||
[[ "$output" =~ "bzip2_sql_db" ]] || { echo "Database bzip2_sql_db not found in: $output"; docker logs "$cname" 2>&1; false; }
|
||||
|
||||
|
||||
run docker run --rm --network host mysql:8.0 mysql -h 127.0.0.1 -P 3306 -u root --password=rootpass -e "USE bzip2_sql_db; SELECT SUM(total) as total FROM orders;"
|
||||
if [ $status -ne 0 ]; then
|
||||
echo "Failed to query orders table. Output: $output"
|
||||
@@ -681,14 +677,14 @@ EOF
|
||||
return 1
|
||||
fi
|
||||
[[ "$output" =~ "475.75" ]] || { echo "Expected sum 475.75 not found in: $output"; false; }
|
||||
|
||||
|
||||
run docker run --rm --network host mysql:8.0 mysql -h 127.0.0.1 -P 3306 -u bzip2user --password=bzip2pass -e "USE bzip2_sql_db; INSERT INTO orders VALUES (4, 'Alice Brown', 99.99, 'shipped');"
|
||||
if [ $status -ne 0 ]; then
|
||||
echo "Failed to insert as bzip2user. Output: $output"
|
||||
docker logs "$cname" 2>&1
|
||||
return 1
|
||||
fi
|
||||
|
||||
|
||||
run docker run --rm --network host mysql:8.0 mysql -h 127.0.0.1 -P 3306 -u bzip2user --password=bzip2pass -e "USE bzip2_sql_db; SELECT customer FROM orders WHERE status='completed';"
|
||||
if [ $status -ne 0 ]; then
|
||||
echo "Failed to select as bzip2user. Output: $output"
|
||||
@@ -697,17 +693,17 @@ EOF
|
||||
fi
|
||||
[[ "$output" =~ "John Doe" ]] || { echo "Expected 'John Doe' not found in: $output"; false; }
|
||||
[[ "$output" =~ "Bob Johnson" ]] || { echo "Expected 'Bob Johnson' not found in: $output"; false; }
|
||||
|
||||
|
||||
rm -rf "$temp_dir"
|
||||
}
|
||||
|
||||
# bats test_tags=no_lambda
|
||||
@test "docker-entrypoint: .sql.xz xz compressed file processing" {
|
||||
cname="${TEST_PREFIX}xz-sql"
|
||||
|
||||
|
||||
local temp_dir="/tmp/xz-sql-test-$$"
|
||||
mkdir -p "$temp_dir"
|
||||
|
||||
|
||||
cat > "$temp_dir/01-init.sql" << 'EOF'
|
||||
CREATE DATABASE IF NOT EXISTS xz_sql_db;
|
||||
USE xz_sql_db;
|
||||
@@ -721,25 +717,25 @@ GRANT ALL ON `xz_sql_db`.* TO 'xzuser'@'%';
|
||||
GRANT USAGE ON *.* TO 'xzuser'@'%';
|
||||
EOF
|
||||
xz "$temp_dir/01-init.sql"
|
||||
|
||||
|
||||
run_container_with_port "$cname" 3306 -e DOLT_ROOT_PASSWORD=rootpass -e DOLT_ROOT_HOST=% -v "$temp_dir:/docker-entrypoint-initdb.d"
|
||||
|
||||
|
||||
run docker run --rm --network host mysql:8.0 mysql -h 127.0.0.1 -P 3306 -u root --password=rootpass -e "SHOW DATABASES;"
|
||||
[ $status -eq 0 ]
|
||||
[[ "$output" =~ "xz_sql_db" ]] || false
|
||||
|
||||
|
||||
run docker run --rm --network host mysql:8.0 mysql -h 127.0.0.1 -P 3306 -u root --password=rootpass -e "USE xz_sql_db; SELECT COUNT(*) as count FROM inventory;"
|
||||
[ $status -eq 0 ]
|
||||
[[ "$output" =~ "4" ]] || false
|
||||
|
||||
|
||||
run docker run --rm --network host mysql:8.0 mysql -h 127.0.0.1 -P 3306 -u xzuser --password=xzpass -e "USE xz_sql_db; UPDATE inventory SET quantity = 60 WHERE item_name='Laptop';"
|
||||
[ $status -eq 0 ]
|
||||
|
||||
|
||||
run docker run --rm --network host mysql:8.0 mysql -h 127.0.0.1 -P 3306 -u xzuser --password=xzpass -e "USE xz_sql_db; SELECT item_name, location FROM inventory WHERE location='Warehouse A';"
|
||||
[ $status -eq 0 ]
|
||||
[[ "$output" =~ "Laptop" ]] || false
|
||||
[[ "$output" =~ "Keyboard" ]] || false
|
||||
|
||||
|
||||
rm -rf "$temp_dir"
|
||||
}
|
||||
|
||||
@@ -775,19 +771,19 @@ EOF
|
||||
run docker run --rm --network host mysql:8.0 mysql -h 127.0.0.1 -P 3306 -u root --password=rootpass -e "SHOW DATABASES;"
|
||||
[ $status -eq 0 ]
|
||||
[[ "$output" =~ "zstd_sql_db" ]] || false
|
||||
|
||||
|
||||
run docker run --rm --network host mysql:8.0 mysql -h 127.0.0.1 -P 3306 -u root --password=rootpass -e "USE zstd_sql_db; SELECT COUNT(*) as count FROM employees;"
|
||||
[ $status -eq 0 ]
|
||||
[[ "$output" =~ "5" ]] || false
|
||||
|
||||
|
||||
run docker run --rm --network host mysql:8.0 mysql -h 127.0.0.1 -P 3306 -u zstduser --password=zstdpass -e "USE zstd_sql_db; SELECT name FROM employees WHERE department='Engineering' AND salary > 90000;"
|
||||
[ $status -eq 0 ]
|
||||
[[ "$output" =~ "Alice Johnson" ]] || false
|
||||
|
||||
|
||||
run docker run --rm --network host mysql:8.0 mysql -h 127.0.0.1 -P 3306 -u zstduser --password=zstdpass -e "USE zstd_sql_db; SELECT department, COUNT(*) as count FROM employees GROUP BY department ORDER BY count DESC;"
|
||||
[ $status -eq 0 ]
|
||||
[[ "$output" =~ "Engineering" ]] || false
|
||||
|
||||
|
||||
rm -rf "$temp_dir"
|
||||
}
|
||||
|
||||
@@ -809,7 +805,7 @@ EOF
|
||||
echo "INSERT INTO bulk_data VALUES" >> "$temp_dir/01-large-part1.sql"
|
||||
start=$(( (batch - 1) * 200 + 1 ))
|
||||
end=$(( batch * 200 ))
|
||||
|
||||
|
||||
for i in $(seq $start $end); do
|
||||
if [ $i -eq $end ]; then
|
||||
echo " ($i, 'value_$i', 'This is metadata for row $i with some additional text to make it larger');" >> "$temp_dir/01-large-part1.sql"
|
||||
@@ -828,7 +824,7 @@ EOF
|
||||
echo "INSERT INTO bulk_data VALUES" >> "$temp_dir/02-large-part2.sql"
|
||||
start=$(( 400 + (batch - 1) * 200 + 1 ))
|
||||
end=$(( 400 + batch * 200 ))
|
||||
|
||||
|
||||
for i in $(seq $start $end); do
|
||||
if [ $i -eq $end ]; then
|
||||
echo " ($i, 'value_$i', 'This is metadata for row $i with some additional text to make it larger');" >> "$temp_dir/02-large-part2.sql"
|
||||
@@ -847,7 +843,7 @@ EOF
|
||||
echo "INSERT INTO bulk_data VALUES" >> "$temp_dir/03-large-part3.sql"
|
||||
start=$(( 800 + (batch - 1) * 200 + 1 ))
|
||||
end=$(( 800 + batch * 200 ))
|
||||
|
||||
|
||||
for i in $(seq $start $end); do
|
||||
if [ $i -eq $end ]; then
|
||||
echo " ($i, 'value_$i', 'This is metadata for row $i with some additional text to make it larger');" >> "$temp_dir/03-large-part3.sql"
|
||||
@@ -863,7 +859,7 @@ EOF
|
||||
[ $status -eq 0 ]
|
||||
[[ "$output" =~ ^"$cname"$ ]] || false
|
||||
|
||||
wait_for_server_ready "$cname"
|
||||
wait_for_log "$cname" "Server initialization complete!" 45;
|
||||
|
||||
run docker run --rm --network host mysql:8.0 mysql -h 127.0.0.1 -P 3306 -u root --password=rootpass -e "SHOW DATABASES;"
|
||||
[ $status -eq 0 ]
|
||||
@@ -892,6 +888,39 @@ EOF
|
||||
rm -rf "$temp_dir"
|
||||
}
|
||||
|
||||
# bats test_tags=no_lambda
|
||||
@test "docker-entrypoint: GRANT privileges in init script does not require CREATE USER" {
|
||||
# Customer error: "error on line 5 for query GRANT ALL PRIVILEGES ON *.* TO 'nautobot'@'%':
|
||||
# You are not allowed to create a user with GRANT"
|
||||
|
||||
cname="${TEST_PREFIX}grant-init"
|
||||
|
||||
local temp_dir="/tmp/grant-init-test-$$"
|
||||
mkdir -p "$temp_dir"
|
||||
|
||||
cat > "$temp_dir/01-correct-grants.sql" << 'EOF'
|
||||
CREATE DATABASE IF NOT EXISTS nautobot_db;
|
||||
GRANT ALL PRIVILEGES ON *.* TO 'nautobot'@'%';
|
||||
FLUSH PRIVILEGES;
|
||||
EOF
|
||||
|
||||
run_container_with_port "$cname" 3306 -e DOLT_ROOT_PASSWORD=rootpass -e DOLT_ROOT_HOST=% -e DOLT_USER=nautobot -e DOLT_PASSWORD=nautobotpass -v "$temp_dir:/docker-entrypoint-initdb.d"
|
||||
|
||||
run docker run --rm --network host mysql:8.0 mysql -h 127.0.0.1 -P 3306 -u root --password=rootpass -e "SELECT User, Host FROM mysql.user WHERE User='nautobot';"
|
||||
[ $status -eq 0 ]
|
||||
[[ "$output" =~ "nautobot" ]] || false
|
||||
[[ "$output" =~ "%" ]] || false
|
||||
|
||||
run docker run --rm --network host mysql:8.0 mysql -h 127.0.0.1 -P 3306 -u nautobot --password=nautobotpass -e "SHOW DATABASES;"
|
||||
[ $status -eq 0 ]
|
||||
[[ "$output" =~ "nautobot_db" ]] || false
|
||||
|
||||
run docker run --rm --network host mysql:8.0 mysql -h 127.0.0.1 -P 3306 -u nautobot --password=nautobotpass -e "CREATE DATABASE nautobot_test; USE nautobot_test; CREATE TABLE test (id INT);"
|
||||
[ $status -eq 0 ]
|
||||
|
||||
rm -rf "$temp_dir"
|
||||
}
|
||||
|
||||
# bats test_tags=no_lambda
|
||||
@test "docker-entrypoint: CREATE SCHEMA without database name" {
|
||||
# DBeaver creates schemas (databases) without specifying a database name
|
||||
|
||||
@@ -1,25 +1,25 @@
|
||||
#!/usr/bin/env bats
|
||||
load $BATS_TEST_DIRNAME/helper/common.bash
|
||||
|
||||
setup() {
|
||||
if [ "$SQL_ENGINE" = "remote-engine" ]; then
|
||||
skip "This test tests remote connections directly, SQL_ENGINE is not needed."
|
||||
fi
|
||||
setup_common
|
||||
}
|
||||
|
||||
teardown() {
|
||||
stop_sql_server 1 && sleep 0.5
|
||||
teardown_common
|
||||
}
|
||||
|
||||
@test "dolt-test-run: sanity test on sql-server" {
|
||||
start_sql_server
|
||||
|
||||
dolt sql -q "insert into dolt_tests values ('test1', 'test1', 'select 1', 'expected_rows', '==', '1');"
|
||||
dolt sql -q "insert into dolt_tests values ('test2', 'test2', 'select 2', 'expected_single_value', '==', '2');"
|
||||
run dolt sql -q "select * from dolt_test_run()"
|
||||
[ $status -eq 0 ]
|
||||
[[ $output =~ "| test1 | test1 | select 1 | PASS | |" ]] || false
|
||||
[[ $output =~ "| test2 | test2 | select 2 | PASS | |" ]] || false
|
||||
}
|
||||
#!/usr/bin/env bats
|
||||
load $BATS_TEST_DIRNAME/helper/common.bash
|
||||
|
||||
setup() {
|
||||
if [ "$SQL_ENGINE" = "remote-engine" ]; then
|
||||
skip "This test tests remote connections directly, SQL_ENGINE is not needed."
|
||||
fi
|
||||
setup_common
|
||||
}
|
||||
|
||||
teardown() {
|
||||
stop_sql_server 1 && sleep 0.5
|
||||
teardown_common
|
||||
}
|
||||
|
||||
@test "dolt-test-run: sanity test on sql-server" {
|
||||
start_sql_server
|
||||
|
||||
dolt sql -q "insert into dolt_tests values ('test1', 'test1', 'select 1', 'expected_rows', '==', '1');"
|
||||
dolt sql -q "insert into dolt_tests values ('test2', 'test2', 'select 2', 'expected_single_value', '==', '2');"
|
||||
run dolt sql -q "select * from dolt_test_run()"
|
||||
[ $status -eq 0 ]
|
||||
[[ $output =~ "| test1 | test1 | select 1 | PASS | |" ]] || false
|
||||
[[ $output =~ "| test2 | test2 | select 2 | PASS | |" ]] || false
|
||||
}
|
||||
|
||||
@@ -1,73 +1,73 @@
|
||||
#!/usr/bin/env bats
|
||||
load $BATS_TEST_DIRNAME/helper/common.bash
|
||||
|
||||
setup() {
|
||||
setup_common
|
||||
dolt sql -q "create table t (i int primary key, j int);"
|
||||
dolt sql -q "insert into t values (1, 1), (2, 2), (3, 3)";
|
||||
dolt sql -q "create table tt (i int primary key, j int);"
|
||||
dolt sql -q "insert into tt values (1, 1), (2, 2), (3, 3)";
|
||||
dolt add .
|
||||
dolt commit -m "initial commit"
|
||||
dolt branch other
|
||||
dolt sql -q "update t set j = 10 where i = 2"
|
||||
dolt sql -q "delete from t where i = 3;"
|
||||
dolt sql -q "insert into t values (4, 4);"
|
||||
dolt add .
|
||||
dolt commit -m "changes"
|
||||
}
|
||||
|
||||
teardown() {
|
||||
assert_feature_version
|
||||
teardown_common
|
||||
}
|
||||
|
||||
@test "query-diff: no args" {
|
||||
run dolt query-diff
|
||||
[ "$status" -eq 1 ]
|
||||
[ "${#lines[@]}" -eq 1 ]
|
||||
[[ "${lines[0]}" =~ "please provide exactly two queries" ]] || false
|
||||
}
|
||||
|
||||
@test "query-diff: too many args" {
|
||||
run dolt query-diff "select * from t;" "select * from t;" "select * from t;"
|
||||
[ "$status" -eq 1 ]
|
||||
[ "${#lines[@]}" -eq 1 ]
|
||||
[[ "${lines[0]}" =~ "please provide exactly two queries" ]] || false
|
||||
}
|
||||
|
||||
@test "query-diff: no changes" {
|
||||
run dolt query-diff "select * from t;" "select * from t;"
|
||||
[ "$status" -eq 0 ]
|
||||
[ "${#lines[@]}" -eq 0 ]
|
||||
}
|
||||
|
||||
@test "query-diff: basic case" {
|
||||
run dolt query-diff "select * from t as of other;" "select * from t as of head;"
|
||||
[ "$status" -eq 0 ]
|
||||
[ "${#lines[@]}" -eq 7 ]
|
||||
[[ "${lines[0]}" =~ "+--------+--------+------+------+-----------+" ]] || false
|
||||
[[ "${lines[1]}" =~ "| from_i | from_j | to_i | to_j | diff_type |" ]] || false
|
||||
[[ "${lines[2]}" =~ "+--------+--------+------+------+-----------+" ]] || false
|
||||
[[ "${lines[3]}" =~ "| 2 | 2 | 2 | 10 | modified |" ]] || false
|
||||
[[ "${lines[4]}" =~ "| 3 | 3 | NULL | NULL | deleted |" ]] || false
|
||||
[[ "${lines[5]}" =~ "| NULL | NULL | 4 | 4 | added |" ]] || false
|
||||
[[ "${lines[6]}" =~ "+--------+--------+------+------+-----------+" ]] || false
|
||||
}
|
||||
|
||||
|
||||
@test "query-diff: other table" {
|
||||
run dolt query-diff "select * from t;" "select * from tt;"
|
||||
[ "$status" -eq 0 ]
|
||||
[ "${#lines[@]}" -eq 10 ]
|
||||
[[ "${lines[0]}" =~ "+--------+--------+------+------+-----------+" ]] || false
|
||||
[[ "${lines[1]}" =~ "| from_i | from_j | to_i | to_j | diff_type |" ]] || false
|
||||
[[ "${lines[2]}" =~ "+--------+--------+------+------+-----------+" ]] || false
|
||||
[[ "${lines[3]}" =~ "| 1 | 1 | NULL | NULL | deleted |" ]] || false
|
||||
[[ "${lines[4]}" =~ "| 2 | 10 | NULL | NULL | deleted |" ]] || false
|
||||
[[ "${lines[5]}" =~ "| 4 | 4 | NULL | NULL | deleted |" ]] || false
|
||||
[[ "${lines[6]}" =~ "| NULL | NULL | 1 | 1 | added |" ]] || false
|
||||
[[ "${lines[7]}" =~ "| NULL | NULL | 2 | 2 | added |" ]] || false
|
||||
[[ "${lines[8]}" =~ "| NULL | NULL | 3 | 3 | added |" ]] || false
|
||||
[[ "${lines[9]}" =~ "+--------+--------+------+------+-----------+" ]] || false
|
||||
#!/usr/bin/env bats
|
||||
load $BATS_TEST_DIRNAME/helper/common.bash
|
||||
|
||||
setup() {
|
||||
setup_common
|
||||
dolt sql -q "create table t (i int primary key, j int);"
|
||||
dolt sql -q "insert into t values (1, 1), (2, 2), (3, 3)";
|
||||
dolt sql -q "create table tt (i int primary key, j int);"
|
||||
dolt sql -q "insert into tt values (1, 1), (2, 2), (3, 3)";
|
||||
dolt add .
|
||||
dolt commit -m "initial commit"
|
||||
dolt branch other
|
||||
dolt sql -q "update t set j = 10 where i = 2"
|
||||
dolt sql -q "delete from t where i = 3;"
|
||||
dolt sql -q "insert into t values (4, 4);"
|
||||
dolt add .
|
||||
dolt commit -m "changes"
|
||||
}
|
||||
|
||||
teardown() {
|
||||
assert_feature_version
|
||||
teardown_common
|
||||
}
|
||||
|
||||
@test "query-diff: no args" {
|
||||
run dolt query-diff
|
||||
[ "$status" -eq 1 ]
|
||||
[ "${#lines[@]}" -eq 1 ]
|
||||
[[ "${lines[0]}" =~ "please provide exactly two queries" ]] || false
|
||||
}
|
||||
|
||||
@test "query-diff: too many args" {
|
||||
run dolt query-diff "select * from t;" "select * from t;" "select * from t;"
|
||||
[ "$status" -eq 1 ]
|
||||
[ "${#lines[@]}" -eq 1 ]
|
||||
[[ "${lines[0]}" =~ "please provide exactly two queries" ]] || false
|
||||
}
|
||||
|
||||
@test "query-diff: no changes" {
|
||||
run dolt query-diff "select * from t;" "select * from t;"
|
||||
[ "$status" -eq 0 ]
|
||||
[ "${#lines[@]}" -eq 0 ]
|
||||
}
|
||||
|
||||
@test "query-diff: basic case" {
|
||||
run dolt query-diff "select * from t as of other;" "select * from t as of head;"
|
||||
[ "$status" -eq 0 ]
|
||||
[ "${#lines[@]}" -eq 7 ]
|
||||
[[ "${lines[0]}" =~ "+--------+--------+------+------+-----------+" ]] || false
|
||||
[[ "${lines[1]}" =~ "| from_i | from_j | to_i | to_j | diff_type |" ]] || false
|
||||
[[ "${lines[2]}" =~ "+--------+--------+------+------+-----------+" ]] || false
|
||||
[[ "${lines[3]}" =~ "| 2 | 2 | 2 | 10 | modified |" ]] || false
|
||||
[[ "${lines[4]}" =~ "| 3 | 3 | NULL | NULL | deleted |" ]] || false
|
||||
[[ "${lines[5]}" =~ "| NULL | NULL | 4 | 4 | added |" ]] || false
|
||||
[[ "${lines[6]}" =~ "+--------+--------+------+------+-----------+" ]] || false
|
||||
}
|
||||
|
||||
|
||||
@test "query-diff: other table" {
|
||||
run dolt query-diff "select * from t;" "select * from tt;"
|
||||
[ "$status" -eq 0 ]
|
||||
[ "${#lines[@]}" -eq 10 ]
|
||||
[[ "${lines[0]}" =~ "+--------+--------+------+------+-----------+" ]] || false
|
||||
[[ "${lines[1]}" =~ "| from_i | from_j | to_i | to_j | diff_type |" ]] || false
|
||||
[[ "${lines[2]}" =~ "+--------+--------+------+------+-----------+" ]] || false
|
||||
[[ "${lines[3]}" =~ "| 1 | 1 | NULL | NULL | deleted |" ]] || false
|
||||
[[ "${lines[4]}" =~ "| 2 | 10 | NULL | NULL | deleted |" ]] || false
|
||||
[[ "${lines[5]}" =~ "| 4 | 4 | NULL | NULL | deleted |" ]] || false
|
||||
[[ "${lines[6]}" =~ "| NULL | NULL | 1 | 1 | added |" ]] || false
|
||||
[[ "${lines[7]}" =~ "| NULL | NULL | 2 | 2 | added |" ]] || false
|
||||
[[ "${lines[8]}" =~ "| NULL | NULL | 3 | 3 | added |" ]] || false
|
||||
[[ "${lines[9]}" =~ "+--------+--------+------+------+-----------+" ]] || false
|
||||
}
|
||||
@@ -1,106 +1,106 @@
|
||||
#!/usr/bin/env bats
|
||||
load $BATS_TEST_DIRNAME/helper/common.bash
|
||||
|
||||
setup() {
|
||||
setup_common
|
||||
dolt sql <<SQL
|
||||
create table t (i int, j int, k int);
|
||||
insert into t (i, j, k) values (1, 2, 3), (4, 5, 6), (7, 8, 9);
|
||||
create table emptytbl (i int, j int, k int);
|
||||
SQL
|
||||
}
|
||||
|
||||
teardown() {
|
||||
assert_feature_version
|
||||
teardown_common
|
||||
}
|
||||
|
||||
@test "sql-export: basic outfile" {
|
||||
run dolt sql -q "select * from t order by i, j, k into outfile './outfile.out';"
|
||||
[ "$status" -eq 0 ]
|
||||
[ -f outfile.out ]
|
||||
|
||||
run cat outfile.out
|
||||
[ "$status" -eq 0 ]
|
||||
[[ "${#lines[@]}" = "3" ]] || false
|
||||
[[ "${lines[0]}" =~ "1 2 3" ]] || false
|
||||
[[ "${lines[1]}" =~ "4 5 6" ]] || false
|
||||
[[ "${lines[2]}" =~ "7 8 9" ]] || false
|
||||
}
|
||||
|
||||
@test "sql-export: basic dumpfile" {
|
||||
run dolt sql -q "select * from t order by i, j, k limit 1 into dumpfile './dumpfile.out';"
|
||||
[ "$status" -eq 0 ]
|
||||
[ -f dumpfile.out ]
|
||||
|
||||
run cat dumpfile.out
|
||||
[ "$status" -eq 0 ]
|
||||
[[ "${#lines[@]}" = "1" ]] || false
|
||||
[[ "${lines[0]}" =~ "123" ]] || false
|
||||
}
|
||||
|
||||
@test "sql-export: test abs path outfile" {
|
||||
CURR_DIR=$(pwd)
|
||||
run dolt sql -q "select * from t order by i, j, k into outfile '$CURR_DIR/outfile.out';"
|
||||
[ "$status" -eq 0 ]
|
||||
[ -f outfile.out ]
|
||||
|
||||
run cat outfile.out
|
||||
[ "$status" -eq 0 ]
|
||||
[[ "${#lines[@]}" = "3" ]] || false
|
||||
[[ "${lines[0]}" =~ "1 2 3" ]] || false
|
||||
[[ "${lines[1]}" =~ "4 5 6" ]] || false
|
||||
[[ "${lines[2]}" =~ "7 8 9" ]] || false
|
||||
}
|
||||
|
||||
@test "sql-export: test abs path dumpfile" {
|
||||
CURR_DIR=$(pwd)
|
||||
run dolt sql -q "select * from t order by i, j, k limit 1 into dumpfile '$CURR_DIR/dumpfile.out';"
|
||||
[ "$status" -eq 0 ]
|
||||
[ -f dumpfile.out ]
|
||||
|
||||
run cat dumpfile.out
|
||||
[ "$status" -eq 0 ]
|
||||
[[ "${#lines[@]}" = "1" ]] || false
|
||||
[[ "${lines[0]}" =~ "123" ]] || false
|
||||
}
|
||||
|
||||
@test "sql-export: empty outfile" {
|
||||
run dolt sql -q "select * from emptytbl into outfile './outfile.out';"
|
||||
[ "$status" -eq 0 ]
|
||||
[ -f outfile.out ]
|
||||
|
||||
run cat outfile.out
|
||||
[ "$status" -eq 0 ]
|
||||
[[ "${#lines[@]}" = "0" ]] || false
|
||||
}
|
||||
|
||||
@test "sql-export: empty dumpfile" {
|
||||
run dolt sql -q "select * from emptytbl into dumpfile './dumpfile.out';"
|
||||
[ "$status" -eq 0 ]
|
||||
[ -f dumpfile.out ]
|
||||
|
||||
run cat dumpfile.out
|
||||
[ "$status" -eq 0 ]
|
||||
[[ "${#lines[@]}" = "0" ]] || false
|
||||
}
|
||||
|
||||
@test "sql-export: fails with existing files" {
|
||||
touch exists.out
|
||||
run dolt sql -q "select * from t order by i, j, k into outfile './exists.out';"
|
||||
[ "$status" -eq 1 ]
|
||||
[[ "$output" =~ "already exists" ]] || false
|
||||
|
||||
run dolt sql -q "select * from t order by i, j, k limit 1 into dumpfile './exists.out';"
|
||||
[ "$status" -eq 1 ]
|
||||
[[ "$output" =~ "already exists" ]] || false
|
||||
}
|
||||
|
||||
@test "sql-export: dumpfile fails with too many rows" {
|
||||
run dolt sql -q "select * from t order by i, j, k limit 3 into dumpfile './dumpfile.out';"
|
||||
[ "$status" -eq 1 ]
|
||||
[[ "$output" =~ "Result consisted of more than one row" ]] || false
|
||||
}
|
||||
#!/usr/bin/env bats
|
||||
load $BATS_TEST_DIRNAME/helper/common.bash
|
||||
|
||||
setup() {
|
||||
setup_common
|
||||
dolt sql <<SQL
|
||||
create table t (i int, j int, k int);
|
||||
insert into t (i, j, k) values (1, 2, 3), (4, 5, 6), (7, 8, 9);
|
||||
create table emptytbl (i int, j int, k int);
|
||||
SQL
|
||||
}
|
||||
|
||||
teardown() {
|
||||
assert_feature_version
|
||||
teardown_common
|
||||
}
|
||||
|
||||
@test "sql-export: basic outfile" {
|
||||
run dolt sql -q "select * from t order by i, j, k into outfile './outfile.out';"
|
||||
[ "$status" -eq 0 ]
|
||||
[ -f outfile.out ]
|
||||
|
||||
run cat outfile.out
|
||||
[ "$status" -eq 0 ]
|
||||
[[ "${#lines[@]}" = "3" ]] || false
|
||||
[[ "${lines[0]}" =~ "1 2 3" ]] || false
|
||||
[[ "${lines[1]}" =~ "4 5 6" ]] || false
|
||||
[[ "${lines[2]}" =~ "7 8 9" ]] || false
|
||||
}
|
||||
|
||||
@test "sql-export: basic dumpfile" {
|
||||
run dolt sql -q "select * from t order by i, j, k limit 1 into dumpfile './dumpfile.out';"
|
||||
[ "$status" -eq 0 ]
|
||||
[ -f dumpfile.out ]
|
||||
|
||||
run cat dumpfile.out
|
||||
[ "$status" -eq 0 ]
|
||||
[[ "${#lines[@]}" = "1" ]] || false
|
||||
[[ "${lines[0]}" =~ "123" ]] || false
|
||||
}
|
||||
|
||||
@test "sql-export: test abs path outfile" {
|
||||
CURR_DIR=$(pwd)
|
||||
run dolt sql -q "select * from t order by i, j, k into outfile '$CURR_DIR/outfile.out';"
|
||||
[ "$status" -eq 0 ]
|
||||
[ -f outfile.out ]
|
||||
|
||||
run cat outfile.out
|
||||
[ "$status" -eq 0 ]
|
||||
[[ "${#lines[@]}" = "3" ]] || false
|
||||
[[ "${lines[0]}" =~ "1 2 3" ]] || false
|
||||
[[ "${lines[1]}" =~ "4 5 6" ]] || false
|
||||
[[ "${lines[2]}" =~ "7 8 9" ]] || false
|
||||
}
|
||||
|
||||
@test "sql-export: test abs path dumpfile" {
|
||||
CURR_DIR=$(pwd)
|
||||
run dolt sql -q "select * from t order by i, j, k limit 1 into dumpfile '$CURR_DIR/dumpfile.out';"
|
||||
[ "$status" -eq 0 ]
|
||||
[ -f dumpfile.out ]
|
||||
|
||||
run cat dumpfile.out
|
||||
[ "$status" -eq 0 ]
|
||||
[[ "${#lines[@]}" = "1" ]] || false
|
||||
[[ "${lines[0]}" =~ "123" ]] || false
|
||||
}
|
||||
|
||||
@test "sql-export: empty outfile" {
|
||||
run dolt sql -q "select * from emptytbl into outfile './outfile.out';"
|
||||
[ "$status" -eq 0 ]
|
||||
[ -f outfile.out ]
|
||||
|
||||
run cat outfile.out
|
||||
[ "$status" -eq 0 ]
|
||||
[[ "${#lines[@]}" = "0" ]] || false
|
||||
}
|
||||
|
||||
@test "sql-export: empty dumpfile" {
|
||||
run dolt sql -q "select * from emptytbl into dumpfile './dumpfile.out';"
|
||||
[ "$status" -eq 0 ]
|
||||
[ -f dumpfile.out ]
|
||||
|
||||
run cat dumpfile.out
|
||||
[ "$status" -eq 0 ]
|
||||
[[ "${#lines[@]}" = "0" ]] || false
|
||||
}
|
||||
|
||||
@test "sql-export: fails with existing files" {
|
||||
touch exists.out
|
||||
run dolt sql -q "select * from t order by i, j, k into outfile './exists.out';"
|
||||
[ "$status" -eq 1 ]
|
||||
[[ "$output" =~ "already exists" ]] || false
|
||||
|
||||
run dolt sql -q "select * from t order by i, j, k limit 1 into dumpfile './exists.out';"
|
||||
[ "$status" -eq 1 ]
|
||||
[[ "$output" =~ "already exists" ]] || false
|
||||
}
|
||||
|
||||
@test "sql-export: dumpfile fails with too many rows" {
|
||||
run dolt sql -q "select * from t order by i, j, k limit 3 into dumpfile './dumpfile.out';"
|
||||
[ "$status" -eq 1 ]
|
||||
[[ "$output" =~ "Result consisted of more than one row" ]] || false
|
||||
}
|
||||
|
||||
@test "sql-export: bit union csv output regression test for dolt#9641" {
|
||||
dolt sql -q "CREATE TABLE collection (id INT, archived BIT(1));"
|
||||
|
||||
Reference in New Issue
Block a user