diff --git a/go/cmd/dolt/commands/status.go b/go/cmd/dolt/commands/status.go index 68e31757a0..822bd081d4 100644 --- a/go/cmd/dolt/commands/status.go +++ b/go/cmd/dolt/commands/status.go @@ -259,6 +259,10 @@ func createPrintData(err error, queryist cli.Queryist, sqlCtx *sql.Context, show case "schema conflict": conflictsPresent = true schemaConflictTables[tableName] = true + + case "constraint violation": + constraintViolationTables[tableName] = true + default: panic(fmt.Sprintf("table %s, unexpected merge status: %s", tableName, status)) } diff --git a/go/libraries/doltcore/sqle/dtables/status_table.go b/go/libraries/doltcore/sqle/dtables/status_table.go index c3e0f80ffc..370e371be7 100644 --- a/go/libraries/doltcore/sqle/dtables/status_table.go +++ b/go/libraries/doltcore/sqle/dtables/status_table.go @@ -100,6 +100,15 @@ type statusTableRow struct { status string } +func contains(str string, strs []string) bool { + for _, s := range strs { + if s == str { + return true + } + } + return false +} + func newStatusItr(ctx *sql.Context, st *StatusTable) (*StatusItr, error) { rp := st.rootsProvider @@ -114,26 +123,16 @@ func newStatusItr(ctx *sql.Context, st *StatusTable) (*StatusItr, error) { } rows := make([]statusTableRow, 0, len(stagedTables)+len(unstagedTables)) - for _, td := range stagedTables { - tblName := tableName(td) - if doltdb.IsFullTextTable(tblName) { - continue - } - rows = append(rows, statusTableRow{ - tableName: tblName, - isStaged: true, - status: statusString(td), - }) + + cvTables, err := doltdb.TablesWithConstraintViolations(ctx, roots.Working) + if err != nil { + return nil, err } - for _, td := range unstagedTables { - tblName := tableName(td) - if doltdb.IsFullTextTable(tblName) { - continue - } + + for _, tbl := range cvTables { rows = append(rows, statusTableRow{ - tableName: tblName, - isStaged: false, - status: statusString(td), + tableName: tbl, + status: "constraint violation", }) } @@ -167,6 +166,35 @@ func newStatusItr(ctx *sql.Context, st *StatusTable) (*StatusItr, error) { }) } + for _, td := range stagedTables { + tblName := tableName(td) + if doltdb.IsFullTextTable(tblName) { + continue + } + if contains(tblName, cvTables) { + continue + } + rows = append(rows, statusTableRow{ + tableName: tblName, + isStaged: true, + status: statusString(td), + }) + } + for _, td := range unstagedTables { + tblName := tableName(td) + if doltdb.IsFullTextTable(tblName) { + continue + } + if contains(tblName, cvTables) { + continue + } + rows = append(rows, statusTableRow{ + tableName: tblName, + isStaged: false, + status: statusString(td), + }) + } + return &StatusItr{rows: rows}, nil } diff --git a/go/libraries/doltcore/sqle/enginetest/dolt_queries_merge.go b/go/libraries/doltcore/sqle/enginetest/dolt_queries_merge.go index 6e1a5f7d81..bb15ca75ba 100644 --- a/go/libraries/doltcore/sqle/enginetest/dolt_queries_merge.go +++ b/go/libraries/doltcore/sqle/enginetest/dolt_queries_merge.go @@ -173,6 +173,12 @@ var MergeScripts = []queries.ScriptTest{ Query: "SELECT * FROM dolt_constraint_violations;", Expected: []sql.Row{{"aTable", uint64(1)}}, }, + { + Query: "select * from dolt_status;", + Expected: []sql.Row{ + {"aTable", false, "constraint violation"}, + }, + }, { Query: "SELECT from_root_ish, violation_type, hex(dolt_row_hash), aColumn, bColumn, CAST(violation_info as CHAR) FROM dolt_constraint_violations_aTable;", Expected: []sql.Row{ @@ -1269,6 +1275,12 @@ var MergeScripts = []queries.ScriptTest{ Query: "SELECT violation_type, pk, parent_fk from dolt_constraint_violations_child;", Expected: []sql.Row{{"foreign key", 1, 1}}, }, + { + Query: "select * from dolt_status;", + Expected: []sql.Row{ + {"child", false, "constraint violation"}, + }, + }, }, }, { @@ -1305,6 +1317,10 @@ var MergeScripts = []queries.ScriptTest{ Query: "SELECT * from dolt_constraint_violations_child", Expected: []sql.Row{}, }, + { + Query: "select * from dolt_status;", + Expected: []sql.Row{}, + }, { Query: "SELECT * from parent;", Expected: []sql.Row{{10, 1}, {30, 2}}, @@ -1349,6 +1365,12 @@ var MergeScripts = []queries.ScriptTest{ Query: "SELECT is_merging, source, target, unmerged_tables FROM DOLT_MERGE_STATUS;", Expected: []sql.Row{{true, "right", "refs/heads/main", "t"}}, }, + { + Query: "select * from dolt_status;", + Expected: []sql.Row{ + {"t", false, "constraint violation"}, + }, + }, }, }, { @@ -1381,6 +1403,12 @@ var MergeScripts = []queries.ScriptTest{ Query: "SELECT violation_type, pk, col1 from dolt_constraint_violations_t;", Expected: []sql.Row{{"unique index", 2, 3}, {"unique index", 3, 3}}, }, + { + Query: "select * from dolt_status;", + Expected: []sql.Row{ + {"t", false, "constraint violation"}, + }, + }, }, }, { @@ -1413,6 +1441,12 @@ var MergeScripts = []queries.ScriptTest{ Query: "SELECT violation_type, pk, col1 from dolt_constraint_violations_t;", Expected: []sql.Row{{"unique index", 2, 3}, {"unique index", 3, 3}}, }, + { + Query: "select * from dolt_status;", + Expected: []sql.Row{ + {"t", false, "constraint violation"}, + }, + }, }, }, { @@ -1445,6 +1479,12 @@ var MergeScripts = []queries.ScriptTest{ Query: "SELECT violation_type, pk, col1, col2 from dolt_constraint_violations_t;", Expected: []sql.Row{{"unique index", 1, 1, 1}, {"unique index", 2, 1, 1}}, }, + { + Query: "select * from dolt_status;", + Expected: []sql.Row{ + {"t", false, "constraint violation"}, + }, + }, }, }, // Behavior between new and old format diverges in the case where right adds diff --git a/integration-tests/bats/cherry-pick.bats b/integration-tests/bats/cherry-pick.bats index 23f7dea86f..79a3cba0c3 100644 --- a/integration-tests/bats/cherry-pick.bats +++ b/integration-tests/bats/cherry-pick.bats @@ -242,7 +242,7 @@ teardown() { # Assert that only 'test' is staged for commit ('other' has a constraint violation) run dolt sql -q "SELECT * from dolt_status;" [ $status -eq 0 ] - [[ $output =~ "| other | false | modified " ]] || false + [[ $output =~ "| other | false | constraint violation " ]] || false [[ $output =~ "| test | true | modified " ]] || false [[ $output =~ "| generated_foo | false | new table " ]] || false diff --git a/integration-tests/bats/constraint-violations.bats b/integration-tests/bats/constraint-violations.bats index 0bfcbbacb5..39d0193028 100644 --- a/integration-tests/bats/constraint-violations.bats +++ b/integration-tests/bats/constraint-violations.bats @@ -3006,6 +3006,12 @@ SQL [[ "$output" =~ "aTable,2" ]] || false [[ "${#lines[@]}" = "2" ]] || false + run dolt sql -q "SELECT * from dolt_status" -r=csv + log_status_eq "0" + [[ "$output" =~ "table_name,staged,status" ]] || false + [[ "$output" =~ "aTable,false,constraint violation" ]] || false + [[ "${#lines[@]}" = "2" ]] || false + run dolt sql -q "SELECT from_root_ish,violation_type,hex(dolt_row_hash) as dolt_row_hash,aColumn,bColumn,violation_info from dolt_constraint_violations_aTable" -r=csv log_status_eq "0" [[ "$output" =~ "from_root_ish,violation_type,dolt_row_hash,aColumn,bColumn,violation_info" ]] || false