#!/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" { 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" { 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" { 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 for MySQL string literals" { # https://dev.mysql.com/doc/refman/8.0/en/string-literals.html dolt sql < patch.sql run dolt sql < patch.sql [ "$status" -eq 0 ] run dolt diff --sql master [ "$status" -eq 0 ] [ "$output" = "" ] } @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 <