#!/usr/bin/env bats load $BATS_TEST_DIRNAME/helper/common.bash setup() { setup_common } teardown() { teardown_common } @test "diff sql output reconciles INSERT query" { dolt checkout -b firstbranch dolt sql < query dolt checkout firstbranch dolt sql < query rm query dolt add test dolt commit -m "Reconciled with newbranch" # confirm that both branches have the same content run dolt diff --sql newbranch firstbranch [ "$status" -eq 0 ] [ "$output" = "" ] } @test "diff sql output reconciles UPDATE query" { dolt checkout -b firstbranch dolt sql < query dolt checkout firstbranch dolt sql < query rm query dolt add test dolt commit -m "Reconciled with newbranch" # confirm that both branches have the same content run dolt diff --sql newbranch firstbranch [ "$status" -eq 0 ] [ "$output" = "" ] } @test "diff sql output reconciles DELETE query" { dolt checkout -b firstbranch dolt sql < query dolt checkout firstbranch dolt sql < query rm query dolt add test dolt commit -m "Reconciled with newbranch" # confirm that both branches have the same content run dolt diff --sql newbranch firstbranch [ "$status" -eq 0 ] [ "$output" = "" ] } @test "diff sql output reconciles change to PRIMARY KEY field in row " { dolt checkout -b firstbranch dolt sql < query dolt checkout firstbranch dolt sql < query rm query dolt add test dolt commit -m "Reconciled with newbranch" # confirm that both branches have the same content run dolt diff --sql newbranch firstbranch [ "$status" -eq 0 ] [ "$output" = "" ] } @test "diff sql output reconciles column rename" { dolt checkout -b firstbranch dolt sql < query dolt checkout firstbranch dolt sql < query rm query dolt add test dolt commit -m "Reconciled with newbranch" # confirm that both branches have the same content run dolt diff --sql newbranch firstbranch [ "$status" -eq 0 ] [ "$output" = "" ] } @test "diff sql output reconciles DROP column query" { dolt checkout -b firstbranch dolt sql < query dolt checkout firstbranch dolt sql < query rm query dolt add test dolt commit -m "Reconciled with newbranch" # confirm that both branches have the same content run dolt diff --sql newbranch firstbranch [ "$status" -eq 0 ] [ "$output" = "" ] } @test "diff sql output reconciles ADD column query" { dolt checkout -b firstbranch dolt sql < query dolt checkout firstbranch dolt sql < query rm query dolt add test dolt commit -m "Reconciled with newbranch" # confirm that both branches have the same content run dolt diff --sql newbranch firstbranch [ "$status" -eq 0 ] [ "$output" = "" ] } @test "diff sql reconciles CREATE TABLE" { # The docs break this test on `dolt add test` below. It is fixed by removing docs, or changing that line below to `dolt add .` rm LICENSE.md rm README.md dolt checkout -b firstbranch dolt checkout -b newbranch dolt sql < query dolt checkout firstbranch dolt sql < query rm query dolt add test dolt commit -m "Reconciled with newbranch" # confirm that both branches have the same content dolt diff --sql newbranch firstbranch run dolt diff --sql newbranch firstbranch [ "$status" -eq 0 ] [ "$output" = "" ] } @test "diff sql includes row INSERTSs to new tables after CREATE TABLE" { # The docs break this test on `dolt add test` below. It is fixed by removing docs, or changing that line below to `dolt add .` rm LICENSE.md rm README.md dolt checkout -b firstbranch dolt checkout -b newbranch dolt sql < query dolt checkout firstbranch dolt sql < query rm query dolt add test dolt commit -m "Reconciled with newbranch" # confirm that both branches have the same content dolt diff --sql newbranch firstbranch run dolt diff --sql newbranch firstbranch [ "$status" -eq 0 ] [ "$output" = "" ] } @test "diff sql reconciles DROP TABLE" { dolt checkout -b firstbranch dolt sql < query dolt checkout firstbranch dolt sql < query rm query dolt add test dolt commit -m "Reconciled with newbranch" # confirm that both branches have the same content run dolt diff --sql newbranch firstbranch [ "$status" -eq 0 ] [ "$output" = "" ] } @test "diff sql outputs RENAME TABLE if underlying data is unchanged" { dolt checkout -b firstbranch dolt sql < output # grep will exit error if it doesn't match the pattern run grep RENAME output [ "$status" -eq 0 ] dolt diff --sql newbranch firstbranch > query dolt checkout firstbranch dolt sql < query rm query dolt add . dolt commit -m "Reconciled with newbranch" # confirm that both branches have the same content run dolt diff --sql newbranch firstbranch [ "$status" -eq 0 ] [ "$output" = "" ] } @test "diff sql reconciles RENAME TABLE with DROP+ADD if data is changed" { dolt checkout -b firstbranch dolt sql < query dolt checkout firstbranch skip "add + drop doesn't work, we have to track renames" dolt sql < query rm query dolt add . dolt commit -m "Reconciled with newbranch" # confirm that both branches have the same content run dolt diff --sql newbranch firstbranch [ "$status" -eq 0 ] [ "$output" = "" ] } @test "diff sql recreates tables with all types" { skip "This test fails due to type incompatibility between SQL and Noms" dolt checkout -b firstbranch dolt checkout -b newbranch dolt sql < query dolt checkout firstbranch dolt sql < query rm query dolt add test dolt commit -m "Reconciled with newbranch" # confirm that both branches have the same content dolt diff --sql newbranch firstbranch run dolt diff --sql newbranch firstbranch [ "$status" -eq 0 ] ["$output" = "" ] } @test "sql diff supports all types" { dolt checkout -b firstbranch dolt sql < patch.sql dolt checkout firstbranch dolt sql < patch.sql rm patch.sql dolt add . dolt commit -m "Reconciled with newbranch" # confirm that both branches have the same content run dolt diff --sql newbranch firstbranch [ "$status" -eq 0 ] [ "$output" = "" ] done } @test "sql diff supports multiple primary keys" { dolt checkout -b firstbranch dolt sql < patch.sql dolt checkout firstbranch dolt sql < patch.sql rm patch.sql dolt add . dolt commit -m "Reconciled with newbranch" # confirm that both branches have the same content run dolt diff --sql newbranch firstbranch [ "$status" -eq 0 ] [ "$output" = "" ] done } @test "sql diff escapes values that end in backslash correctly" { dolt sql < $BATS_TMPDIR/input-$$.sql run dolt sql < $BATS_TMPDIR/input-$$.sql skip "backslashes at the end of strings not supported correctly by sql diff" [ "$status" -eq 0 ] } @test "sql diff ignores dolt docs" { echo "This is a README" > README.md run dolt diff --sql [ "$status" -eq 0 ] skip "Have to decide how to treat dolty_docs in diff --sql" [[ ! "$output" =~ "dolt_docs" ]] || false; } @test "sql diff handles NULL cells" { dolt sql <