diff --git a/bats/helper/1pk5col-ints.json b/bats/helper/1pk5col-ints.json new file mode 100644 index 0000000000..30c6167b68 --- /dev/null +++ b/bats/helper/1pk5col-ints.json @@ -0,0 +1,20 @@ +{ + "rows": [ + { + "pk": 0, + "c1": 1, + "c2": 2, + "c3": 3, + "c4": 4, + "c5": 5 + }, + { + "pk": 1, + "c1": 1, + "c2": 2, + "c3": 3, + "c4": 4, + "c5": 5 + } + ] +} diff --git a/bats/helper/employees-tbl-new.json b/bats/helper/employees-tbl-new.json new file mode 100644 index 0000000000..4a491d04dd --- /dev/null +++ b/bats/helper/employees-tbl-new.json @@ -0,0 +1,36 @@ +{ + "rows": [ + { + "id": 0, + "first name": "tim", + "last name": "sehn", + "title": "ceo", + "start date": "", + "end date": "" + }, + { + "id": 1, + "first name": "aaron", + "last name": "son", + "title": "founder", + "start date": "", + "end date": "" + }, + { + "id": 2, + "first name": "brian", + "last name": "hendricks", + "title": "founder", + "start date": "", + "end date": "" + }, + { + "id": 3, + "first name": "matt", + "last name": "jesuele", + "title": "software engineer", + "start date": "", + "end date": "" + } + ] +} diff --git a/bats/helper/employees-tbl-schema-wrong.csv b/bats/helper/employees-tbl-schema-wrong.csv new file mode 100644 index 0000000000..f93e2167ce --- /dev/null +++ b/bats/helper/employees-tbl-schema-wrong.csv @@ -0,0 +1,3 @@ +id, first name, last name, position +0, "tim", "sehn", "ceo" +1, "aaron", "son", "founder" diff --git a/bats/helper/employees-tbl-schema-wrong.json b/bats/helper/employees-tbl-schema-wrong.json new file mode 100644 index 0000000000..665fa446e2 --- /dev/null +++ b/bats/helper/employees-tbl-schema-wrong.json @@ -0,0 +1,32 @@ +{ + "rows": [ + { + "id": "0", + "first name": "tim", + "last name": "sehn", + "position": "ceo", + "children": true + }, + { + "id": "1", + "first name": "aaron", + "last name": "son", + "position": "founder", + "children": true + }, + { + "id": "2", + "first name": "brian", + "last name": "hendricks", + "position": "founder", + "children": true + }, + { + "id": "3", + "first name": "matt", + "last name": "jesuele", + "position": "software engineer", + "children": false + } + ] +} diff --git a/bats/replace-tables.bats b/bats/replace-tables.bats index 04770d6e59..0522834b2a 100644 --- a/bats/replace-tables.bats +++ b/bats/replace-tables.bats @@ -26,7 +26,59 @@ teardown() { @test "replace table using schema with csv" { run dolt table create -s `batshelper 1pk5col-ints.schema` test [ "$status" -eq 0 ] - run dolt table import -u -s `batshelper 1pk5col-ints.schema` test `batshelper 1pk5col-ints.csv` + run dolt table import -r -s `batshelper 1pk5col-ints.schema` test `batshelper 1pk5col-ints.csv` [ "$status" -eq 1 ] [[ "$output" =~ "schema is not supported for update or replace operations" ]] || false +} + +@test "replace table using json" { + run dolt table create -s `batshelper employees-sch.json` employees + [ "$status" -eq 0 ] + run dolt table import -r employees `batshelper employees-tbl.json` + [ "$status" -eq 0 ] + [[ "$output" =~ "Rows Processed: 3, Additions: 3, Modifications: 0, Had No Effect: 0" ]] || false + [[ "$output" =~ "Import completed successfully." ]] || false +} + +@test "replace table using wrong json" { + run dolt table create -s `batshelper employees-sch-wrong.json` employees + [ "$status" -eq 0 ] + run dolt table import -r employees `batshelper employees-tbl.json` + [ "$status" -eq 1 ] + [[ "$output" =~ "Error replacing table" ]] || false + [[ "$output" =~ "cause: Schema from file does not match existing table schema" ]] || false +} + +@test "replace table using schema with json" { + run dolt table create -s `batshelper employees-sch-wrong.json` employees + [ "$status" -eq 0 ] + run dolt table import -r -s `batshelper employees-sch.json` employees `batshelper employees-tbl.json` + [ "$status" -eq 1 ] + [[ "$output" =~ "fatal: schema is not supported for update or replace operations" ]] || false +} + +@test "replace table with json when table does not exist" { + run dolt table import -r employees `batshelper employees-tbl.json` + [ "$status" -eq 1 ] + [[ "$output" =~ "The following table could not be found:" ]] || false +} + +@test "replace table with existing imported data" { + run dolt table import -c -s `batshelper employees-sch.json` employees `batshelper employees-tbl.json` + [ "$status" -eq 0 ] + [[ "$output" =~ "Import completed successfully." ]] || false + run dolt table import -r employees `batshelper employees-tbl-new.json` + [ "$status" -eq 0 ] + [[ "$output" =~ "Rows Processed: 4, Additions: 4, Modifications: 0, Had No Effect: 0" ]] || false + [[ "$output" =~ "Import completed successfully." ]] || false +} + +@test "replace table with existing imported data with different schema" { + run dolt table import -c -s `batshelper employees-sch.json` employees `batshelper employees-tbl.json` + [ "$status" -eq 0 ] + [[ "$output" =~ "Import completed successfully." ]] || false + run dolt table import -r employees `batshelper employees-tbl-schema-wrong.json` + [ "$status" -eq 1 ] + [[ "$output" =~ "Error replacing table" ]] || false + [[ "$output" =~ "cause: Schema from file does not match existing table schema" ]] || false } \ No newline at end of file diff --git a/bats/update-tables.bats b/bats/update-tables.bats index 1af2a1530a..b4cdf7ed3d 100644 --- a/bats/update-tables.bats +++ b/bats/update-tables.bats @@ -28,7 +28,7 @@ teardown() { [ "$status" -eq 0 ] run dolt table import -u -s `batshelper 1pk5col-ints.schema` test `batshelper 1pk5col-ints.csv` [ "$status" -eq 1 ] - [[ "$output" =~ "schema is not supported for update operations" ]] || false + [[ "$output" =~ "fatal: schema is not supported for update or replace operations" ]] || false } @test "update table using csv with newlines" { @@ -61,7 +61,16 @@ teardown() { [ "$status" -eq 0 ] run dolt table import -u -s `batshelper employees-sch.json` employees `batshelper employees-tbl.json` [ "$status" -eq 1 ] - [[ "$output" =~ "schema is not supported for update operations" ]] || false + [[ "$output" =~ "fatal: schema is not supported for update or replace operations" ]] || false +} + +@test "update table with existing imported data with different schema" { + run dolt table import -c -s `batshelper employees-sch.json` employees `batshelper employees-tbl.json` + [ "$status" -eq 0 ] + [[ "$output" =~ "Import completed successfully." ]] || false + run dolt table import -u employees `batshelper employees-tbl-schema-wrong.json` + [ "$status" -eq 0 ] + [[ "$output" =~ "Rows Processed: 0, Additions: 0, Modifications: 0, Had No Effect: 0" ]] || false } @test "update table with json when table does not exist" {