#!/usr/bin/env bats load $BATS_TEST_DIRNAME/helper/common.bash setup() { setup_common } teardown() { assert_feature_version teardown_common } @test "import-replace-tables: replace table using csv" { dolt sql < unexpected.json run dolt table import -r employees unexpected.json [ "$status" -eq 1 ] [[ "$output" =~ "An error occurred while moving data" ]] || false [[ "$output" =~ "unexpected JSON format received, expected format: { \"rows\": [ json_row_objects... ] }" ]] || false } @test "import-replace-tables: replace table using xlsx file" { dolt sql < 1pk5col-ints-updt.csv pk,c2 0,7 DELIM run dolt table import -r test 1pk5col-ints-updt.csv [ "$status" -eq 0 ] [[ "$output" =~ "Warning: The import file's schema does not match the table's schema" ]] || false [[ "$output" =~ "Rows Processed: 1, Additions: 1, Modifications: 0, Had No Effect: 0" ]] || false [[ "$output" =~ "Import completed successfully." ]] || false run dolt sql -r csv -q "select * from test" [ "${lines[1]}" = "0,,7,,," ] } @test "import-replace-tables: csv files has more columns than schema" { cat < schema.sql CREATE TABLE subset ( pk INT NOT NULL, c1 INT, c2 INT, c3 INT, PRIMARY KEY (pk) ); SQL cat < data.csv pk,c4,c1,c2,c3 0,4,1,2,3 DELIM dolt sql < schema.sql dolt sql -q "insert into subset values (1000, 100, 1000, 10000)" run dolt table import -r subset data.csv [ "$status" -eq 0 ] [[ "$output" =~ "Warning: The import file's schema does not match the table's schema" ]] || false [[ "$output" =~ "If unintentional, check for any typos in the import file's header" ]] || false [[ "$output" =~ "Extra columns in import file:" ]] || false [[ "$output" =~ " c4" ]] || false # schema argument subsets the data and adds empty column run dolt sql -r csv -q "select * from subset ORDER BY pk" [ "$status" -eq 0 ] [ "${#lines[@]}" -eq 2 ] [ "${lines[1]}" = "0,1,2,3" ] } @test "import-replace-tables: different schema warning lists differing columns" { cat < schema.sql CREATE TABLE t ( pk INT NOT NULL, c1 INT, c2 INT, c3 INT, PRIMARY KEY (pk) ); SQL cat < data.csv pk,c4,c1,c3 0,4,1,3 DELIM dolt sql < schema.sql dolt sql -q "insert into t values (1000, 100, 1000, 10000)" run dolt table import -r t data.csv [ "$status" -eq 0 ] [[ "$output" =~ "Warning: The import file's schema does not match the table's schema" ]] || false [[ "$output" =~ "If unintentional, check for any typos in the import file's header" ]] || false [[ "$output" =~ "Missing columns in t:" ]] || false [[ "$output" =~ " c2" ]] || false [[ "$output" =~ "Extra columns in import file:" ]] || false [[ "$output" =~ " c4" ]] || false } @test "import-replace-tables: Replace that breaks fk constraints correctly errors" { dolt sql < colors-bad.csv id,name 1,'red' DELIM run dolt table import -r colors colors-bad.csv [ "$status" -eq 1 ] [[ "$output" =~ "cannot truncate table colors as it is referenced in foreign key" ]] || false } @test "import-replace-tables: can't use --all-text with -r" { dolt sql <