Vinai/update dolt sql session variables (#1283)

This pr fixes a bug where session variables were not being properly handled between commit and reset.
This commit is contained in:
Vinai Rachakonda
2021-02-02 18:51:34 -05:00
committed by GitHub
parent 32c4598d29
commit d8b3cdd9c3
8 changed files with 296 additions and 38 deletions
+66 -4
View File
@@ -10,10 +10,6 @@ CREATE TABLE test (
);
INSERT INTO test VALUES (0),(1),(2);
SQL
dolt sql <<SQL
DELETE FROM test WHERE pk = 0;
INSERT INTO test VALUES (3);
SQL
}
@@ -115,4 +111,70 @@ teardown() {
run dolt sql -q "SELECT * from dolt_commits ORDER BY Date DESC;"
[ $status -eq 0 ]
[[ "$output" =~ "Commit1" ]] || false
}
@test "DOLT_COMMIT immediately updates dolt log system table." {
run dolt sql << SQL
SELECT DOLT_COMMIT('-a', '-m', 'Commit1');
SELECT * FROM dolt_log;
SQL
[ $status -eq 0 ]
[[ "$output" =~ "Commit1" ]] || false
}
@test "DOLT_COMMIT immediately updates dolt diff system table." {
original_hash=$(get_head_commit)
run dolt sql << SQL
SELECT DOLT_COMMIT('-a', '-m', 'Commit1');
SELECT from_commit FROM dolt_diff_test WHERE to_commit = hashof('head');
SQL
[ $status -eq 0 ]
# Represents that the diff table marks a change from the recent commit.
[[ "$output" =~ $original_hash ]] || false
}
@test "DOLT_COMMIT updates session variables" {
head_variable=@@dolt_repo_$$_head
head_commit=$(get_head_commit)
run dolt sql << SQL
SELECT DOLT_COMMIT('-a', '-m', 'Commit1');
SELECT $head_variable = HASHOF('head');
SELECT $head_variable
SQL
[ $status -eq 0 ]
[[ "$output" =~ "true" ]] || false
# Verify that the head commit changes.
[[ ! "$output" =~ $head_commit ]] || false
# Verify that head on log matches the new session variable.
head_commit=$(get_head_commit)
[[ "$output" =~ $head_commit ]] || false
}
@test "DOLT_COMMIT with unstaged tables correctly gets new head root but does not overwrite working" {
head_variable=@@dolt_repo_$$_head
run dolt sql << SQL
CREATE TABLE test2 (
pk int primary key
);
SELECT DOLT_ADD('test');
SELECT DOLT_COMMIT('-m', 'Commit1');
SELECT $head_variable = HASHOF('head');
SQL
[ $status -eq 0 ]
[[ "$output" =~ "true" ]] || false
run dolt sql -r csv -q "select * from dolt_status;"
[ $status -eq 0 ]
[[ "$output" =~ 'test2,false,new table' ]] || false
}
get_head_commit() {
dolt log -n 1 | grep -m 1 commit | cut -c 8-
}