mirror of
https://github.com/dolthub/dolt.git
synced 2026-02-11 02:59:34 -06:00
Fix bug with working and staged
This commit is contained in:
@@ -334,14 +334,10 @@ func (db Database) getTableInsensitive(ctx *sql.Context, head *doltdb.Commit, ds
|
||||
switch {
|
||||
case lwrName == doltdb.DoltDiffTablePrefix+doltdb.SchemasTableName:
|
||||
// Special handling for dolt_diff_dolt_schemas
|
||||
// For schema diff tables, we want to show all schema objects going from the initial commit
|
||||
// to their current defined state, similar to how regular diff tables work
|
||||
// For schema diff tables, we want to show differences between HEAD and WORKING
|
||||
// (or HEAD and STAGED), similar to how regular diff tables work
|
||||
|
||||
// Get the initial commit (first commit in the database)
|
||||
var initialCommit *doltdb.Commit
|
||||
var initialCommitHash string
|
||||
|
||||
// Get the initial commit by walking back to the beginning
|
||||
// Get the HEAD commit
|
||||
if head == nil {
|
||||
var err error
|
||||
head, err = ds.GetHeadCommit(ctx, db.RevisionQualifiedName())
|
||||
@@ -350,43 +346,20 @@ func (db Database) getTableInsensitive(ctx *sql.Context, head *doltdb.Commit, ds
|
||||
}
|
||||
}
|
||||
|
||||
// Walk back to find the initial commit
|
||||
initialCommit = head
|
||||
for {
|
||||
parents, err := initialCommit.ParentHashes(ctx)
|
||||
if err != nil {
|
||||
return nil, false, err
|
||||
}
|
||||
if len(parents) == 0 {
|
||||
// This is the initial commit
|
||||
break
|
||||
}
|
||||
// Get the first parent (main line)
|
||||
parentOptCommit, err := db.ddb.ReadCommit(ctx, parents[0])
|
||||
if err != nil {
|
||||
return nil, false, err
|
||||
}
|
||||
parentCommit, ok := parentOptCommit.ToCommit()
|
||||
if !ok {
|
||||
return nil, false, fmt.Errorf("expected commit, got ghost commit")
|
||||
}
|
||||
initialCommit = parentCommit
|
||||
}
|
||||
|
||||
// Get the hash and root of the initial commit
|
||||
initialHash, err := initialCommit.HashOf()
|
||||
// Get the HEAD commit hash and root
|
||||
headHash, err := head.HashOf()
|
||||
if err != nil {
|
||||
return nil, false, err
|
||||
}
|
||||
initialCommitHash = initialHash.String()
|
||||
headCommitHash := headHash.String()
|
||||
|
||||
initialRoot, err := initialCommit.GetRootValue(ctx)
|
||||
headRoot, err := head.GetRootValue(ctx)
|
||||
if err != nil {
|
||||
return nil, false, err
|
||||
}
|
||||
|
||||
// Compare initial commit state vs current working state to show all changes since inception
|
||||
return NewDoltSchemasDiffTable(ctx, db.ddb, initialRoot, root, initialCommitHash, "WORKING", db), true, nil
|
||||
// Compare HEAD vs current working state to show recent changes
|
||||
return NewDoltSchemasDiffTable(ctx, db.ddb, headRoot, root, headCommitHash, "WORKING", db), true, nil
|
||||
|
||||
case strings.HasPrefix(lwrName, doltdb.DoltDiffTablePrefix):
|
||||
if head == nil {
|
||||
|
||||
@@ -350,10 +350,12 @@ func (dsdri *doltSchemasDiffRowIter) createDiffRow(toRow, fromRow sql.Row, diffT
|
||||
row[5] = dsdri.toRef // to_commit
|
||||
row[6] = nil // to_commit_date (null for WORKING state)
|
||||
} else {
|
||||
// All to_* columns are null for removed rows
|
||||
for i := 0; i < 7; i++ {
|
||||
// to_* schema columns are null for removed rows, but commit info should be populated
|
||||
for i := 0; i < 5; i++ {
|
||||
row[i] = nil
|
||||
}
|
||||
row[5] = dsdri.toRef // to_commit should always be populated (will be "WORKING")
|
||||
row[6] = nil // to_commit_date is null for WORKING state
|
||||
}
|
||||
|
||||
// FROM columns (indices 7-13)
|
||||
|
||||
@@ -196,7 +196,8 @@ func doltSchemasDiffTableTests() []doltSchemasTableTest {
|
||||
rows: []sql.Row{
|
||||
{"event", "new_event", "added"},
|
||||
{"view", "new_view", "added"},
|
||||
{"view", "original_view", "added"}, // all current objects show as "added" from empty state
|
||||
{"view", "original_view", "modified"}, // HEAD vs WORKING: shows proper diff types
|
||||
{nil, nil, "removed"}, // removed trigger has NULL to_ values
|
||||
},
|
||||
},
|
||||
{
|
||||
@@ -204,22 +205,21 @@ func doltSchemasDiffTableTests() []doltSchemasTableTest {
|
||||
query: "SELECT to_type, to_name FROM dolt_diff_dolt_schemas WHERE diff_type = 'added' ORDER BY to_type, to_name",
|
||||
rows: []sql.Row{
|
||||
{"event", "new_event"},
|
||||
{"view", "new_view"},
|
||||
{"view", "original_view"}, // original_view also shows as "added" from empty state
|
||||
{"view", "new_view"}, // Only truly added objects
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "filter for modified schemas only",
|
||||
query: "SELECT to_type, to_name FROM dolt_diff_dolt_schemas WHERE diff_type = 'modified' ORDER BY to_type, to_name",
|
||||
rows: []sql.Row{
|
||||
// No modified entries with EMPTY vs WORKING comparison
|
||||
{"view", "original_view"}, // View was modified between HEAD and WORKING
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "filter for removed schemas only",
|
||||
query: "SELECT from_type, from_name FROM dolt_diff_dolt_schemas WHERE diff_type = 'removed' ORDER BY from_type, from_name",
|
||||
rows: []sql.Row{
|
||||
// No removed entries with EMPTY vs WORKING comparison
|
||||
{"trigger", "original_trigger"}, // Trigger was removed between HEAD and WORKING
|
||||
},
|
||||
},
|
||||
{
|
||||
@@ -227,35 +227,37 @@ func doltSchemasDiffTableTests() []doltSchemasTableTest {
|
||||
query: "SELECT COALESCE(to_name, from_name) as name, diff_type FROM dolt_diff_dolt_schemas WHERE COALESCE(to_type, from_type) = 'view' ORDER BY name",
|
||||
rows: []sql.Row{
|
||||
{"new_view", "added"},
|
||||
{"original_view", "added"}, // original_view shows as "added" from empty state
|
||||
{"original_view", "modified"}, // original_view shows as "modified" in HEAD vs WORKING
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "count changes by type",
|
||||
query: "SELECT diff_type, COUNT(*) as count FROM dolt_diff_dolt_schemas GROUP BY diff_type ORDER BY diff_type",
|
||||
rows: []sql.Row{
|
||||
{"added", int64(3)}, // All 3 current objects show as "added" from empty state
|
||||
{"added", int64(2)}, // new_event, new_view
|
||||
{"modified", int64(1)}, // original_view
|
||||
{"removed", int64(1)}, // original_trigger
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "check all columns exist",
|
||||
query: "SELECT COUNT(*) FROM dolt_diff_dolt_schemas WHERE (to_type IS NOT NULL OR from_type IS NOT NULL) AND (to_name IS NOT NULL OR from_name IS NOT NULL) AND diff_type IS NOT NULL",
|
||||
rows: []sql.Row{
|
||||
{int64(3)}, // Total number of changes (all current objects as "added")
|
||||
{int64(4)}, // Total number of changes (2 added + 1 modified + 1 removed)
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "verify commit columns are populated",
|
||||
query: "SELECT COUNT(*) FROM dolt_diff_dolt_schemas WHERE to_commit IS NOT NULL AND from_commit IS NOT NULL",
|
||||
rows: []sql.Row{
|
||||
{int64(3)}, // All rows should have both commit fields populated
|
||||
{int64(4)}, // All rows should have both commit fields populated
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "verify to_commit is WORKING and from_commit is a valid hash",
|
||||
query: "SELECT DISTINCT to_commit, LENGTH(from_commit) as from_commit_len FROM dolt_diff_dolt_schemas",
|
||||
rows: []sql.Row{
|
||||
{"WORKING", int32(32)}, // to_commit should be WORKING, from_commit should be 32-char hash
|
||||
{"WORKING", int32(32)}, // All entries: to_commit should be WORKING, from_commit should be 32-char hash
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
@@ -548,11 +548,10 @@ SQL
|
||||
dolt add .
|
||||
dolt commit -m "base commit with original schemas"
|
||||
|
||||
run dolt sql -q "select * from dolt_diff_dolt_schemas"
|
||||
# Initially, after commit, there should be no differences (HEAD == WORKING)
|
||||
run dolt sql -q 'SELECT COUNT(*) FROM dolt_diff_dolt_schemas'
|
||||
[ "$status" -eq 0 ]
|
||||
# Should show the view and trigger as "added" from NULL (empty state)
|
||||
[[ "$output" =~ "original_view" ]] || false
|
||||
[[ "$output" =~ "original_trigger" ]] || false
|
||||
[[ "$output" =~ "0" ]] || false
|
||||
|
||||
# Make changes for diff (working directory changes)
|
||||
dolt sql -q "DROP VIEW original_view"
|
||||
@@ -580,43 +579,50 @@ SQL
|
||||
[[ "$output" =~ "from_commit_date,datetime(6)" ]] || false
|
||||
[[ "$output" =~ "diff_type,varchar(1023)" ]] || false
|
||||
|
||||
# Test actual diff functionality - should show 3 changes (all current objects as "added" from empty state)
|
||||
# With EMPTY vs WORKING comparison: original_view (modified), new_view (added), new_event (added)
|
||||
# The removed trigger doesn't appear because it doesn't exist in WORKING
|
||||
# Test actual diff functionality - should show 4 changes (HEAD vs WORKING)
|
||||
# original_view (modified), new_view (added), new_event (added), original_trigger (removed)
|
||||
run dolt sql -q 'SELECT COUNT(*) FROM dolt_diff_dolt_schemas'
|
||||
[ "$status" -eq 0 ]
|
||||
[[ "$output" =~ "3" ]] || false
|
||||
[[ "$output" =~ "4" ]] || false
|
||||
|
||||
# Test that all schemas show as "added" from empty state
|
||||
# Test that we have changes of different types
|
||||
run dolt sql -q 'SELECT COUNT(*) FROM dolt_diff_dolt_schemas WHERE diff_type = "added"'
|
||||
[ "$status" -eq 0 ]
|
||||
[[ "$output" =~ "3" ]] || false
|
||||
|
||||
# With EMPTY vs WORKING, there should be no "removed" or "modified" entries
|
||||
run dolt sql -q 'SELECT COUNT(*) FROM dolt_diff_dolt_schemas WHERE diff_type = "removed"'
|
||||
[ "$status" -eq 0 ]
|
||||
[[ "$output" =~ "0" ]] || false
|
||||
[[ "$output" =~ "2" ]] || false # new_view and new_event
|
||||
|
||||
run dolt sql -q 'SELECT COUNT(*) FROM dolt_diff_dolt_schemas WHERE diff_type = "modified"'
|
||||
[ "$status" -eq 0 ]
|
||||
[[ "$output" =~ "0" ]] || false
|
||||
[[ "$output" =~ "1" ]] || false # original_view
|
||||
|
||||
# Test that we can identify specific added objects
|
||||
run dolt sql -q 'SELECT COUNT(*) FROM dolt_diff_dolt_schemas WHERE diff_type = "removed"'
|
||||
[ "$status" -eq 0 ]
|
||||
[[ "$output" =~ "1" ]] || false # original_trigger
|
||||
|
||||
# Test that we can identify specific changes
|
||||
run dolt sql -q 'SELECT to_name FROM dolt_diff_dolt_schemas WHERE diff_type = "added" ORDER BY to_name'
|
||||
[ "$status" -eq 0 ]
|
||||
[[ "$output" =~ "new_event" ]] || false
|
||||
[[ "$output" =~ "new_view" ]] || false
|
||||
|
||||
run dolt sql -q 'SELECT to_name FROM dolt_diff_dolt_schemas WHERE diff_type = "modified"'
|
||||
[ "$status" -eq 0 ]
|
||||
[[ "$output" =~ "original_view" ]] || false
|
||||
|
||||
# Test that diff_type values are correct (only "added" with EMPTY vs WORKING)
|
||||
run dolt sql -q 'SELECT from_name FROM dolt_diff_dolt_schemas WHERE diff_type = "removed"'
|
||||
[ "$status" -eq 0 ]
|
||||
[[ "$output" =~ "original_trigger" ]] || false
|
||||
|
||||
# Test that diff_type values are correct
|
||||
run dolt sql -q 'SELECT DISTINCT diff_type FROM dolt_diff_dolt_schemas ORDER BY diff_type'
|
||||
[ "$status" -eq 0 ]
|
||||
[[ "$output" =~ "added" ]] || false
|
||||
[[ "$output" =~ "modified" ]] || false
|
||||
[[ "$output" =~ "removed" ]] || false
|
||||
|
||||
# Test that from_commit is always populated (should be the initial commit hash)
|
||||
# Test that from_commit is always populated (should be HEAD commit hash)
|
||||
run dolt sql -q 'SELECT COUNT(*) FROM dolt_diff_dolt_schemas WHERE from_commit IS NOT NULL'
|
||||
[ "$status" -eq 0 ]
|
||||
[[ "$output" =~ "3" ]] || false
|
||||
[[ "$output" =~ "4" ]] || false
|
||||
|
||||
# Test that from_commit is a valid commit hash (not "EMPTY" or "WORKING")
|
||||
run dolt sql -q 'SELECT DISTINCT from_commit FROM dolt_diff_dolt_schemas'
|
||||
|
||||
Reference in New Issue
Block a user