mirror of
https://github.com/dolthub/dolt.git
synced 2026-04-24 03:16:12 -05:00
fix dolt diff schema primary key changes
This commit is contained in:
Executable
+58
@@ -0,0 +1,58 @@
|
||||
{
|
||||
"columns": [
|
||||
{
|
||||
"tag": 0,
|
||||
"name": "pk",
|
||||
"kind": "int",
|
||||
"is_part_of_pk": true,
|
||||
"col_constraints": [
|
||||
{
|
||||
"constraint_type": "not_null",
|
||||
"params": null
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"tag": 1,
|
||||
"name": "c1",
|
||||
"kind": "int",
|
||||
"is_part_of_pk": false,
|
||||
"col_constraints": []
|
||||
},
|
||||
{
|
||||
"tag": 2,
|
||||
"name": "c2",
|
||||
"kind": "int",
|
||||
"is_part_of_pk": false,
|
||||
"col_constraints": []
|
||||
},
|
||||
{
|
||||
"tag": 3,
|
||||
"name": "c3",
|
||||
"kind": "int",
|
||||
"is_part_of_pk": false,
|
||||
"col_constraints": []
|
||||
},
|
||||
{
|
||||
"tag": 4,
|
||||
"name": "c4",
|
||||
"kind": "int",
|
||||
"is_part_of_pk": false,
|
||||
"col_constraints": []
|
||||
},
|
||||
{
|
||||
"tag": 5,
|
||||
"name": "c5",
|
||||
"kind": "int",
|
||||
"is_part_of_pk": false,
|
||||
"col_constraints": []
|
||||
},
|
||||
{
|
||||
"tag": 6,
|
||||
"name": "c6",
|
||||
"kind": "int",
|
||||
"is_part_of_pk": true,
|
||||
"col_constraints": []
|
||||
}
|
||||
]
|
||||
}
|
||||
+51
@@ -0,0 +1,51 @@
|
||||
{
|
||||
"columns": [
|
||||
{
|
||||
"tag": 0,
|
||||
"name": "pk",
|
||||
"kind": "int",
|
||||
"is_part_of_pk": true,
|
||||
"col_constraints": [
|
||||
{
|
||||
"constraint_type": "not_null",
|
||||
"params": null
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"tag": 1,
|
||||
"name": "c1",
|
||||
"kind": "int",
|
||||
"is_part_of_pk": false,
|
||||
"col_constraints": []
|
||||
},
|
||||
{
|
||||
"tag": 2,
|
||||
"name": "column2",
|
||||
"kind": "int",
|
||||
"is_part_of_pk": false,
|
||||
"col_constraints": []
|
||||
},
|
||||
{
|
||||
"tag": 3,
|
||||
"name": "c3",
|
||||
"kind": "int",
|
||||
"is_part_of_pk": false,
|
||||
"col_constraints": []
|
||||
},
|
||||
{
|
||||
"tag": 4,
|
||||
"name": "c4",
|
||||
"kind": "int",
|
||||
"is_part_of_pk": false,
|
||||
"col_constraints": []
|
||||
},
|
||||
{
|
||||
"tag": 5,
|
||||
"name": "c5",
|
||||
"kind": "int",
|
||||
"is_part_of_pk": false,
|
||||
"col_constraints": []
|
||||
}
|
||||
]
|
||||
}
|
||||
Executable
+39
@@ -0,0 +1,39 @@
|
||||
{
|
||||
"columns": [
|
||||
{
|
||||
"tag": 1,
|
||||
"name": "c1",
|
||||
"kind": "int",
|
||||
"is_part_of_pk": false,
|
||||
"col_constraints": []
|
||||
},
|
||||
{
|
||||
"tag": 2,
|
||||
"name": "c2",
|
||||
"kind": "int",
|
||||
"is_part_of_pk": false,
|
||||
"col_constraints": []
|
||||
},
|
||||
{
|
||||
"tag": 3,
|
||||
"name": "c3",
|
||||
"kind": "int",
|
||||
"is_part_of_pk": true,
|
||||
"col_constraints": []
|
||||
},
|
||||
{
|
||||
"tag": 4,
|
||||
"name": "c4",
|
||||
"kind": "int",
|
||||
"is_part_of_pk": false,
|
||||
"col_constraints": []
|
||||
},
|
||||
{
|
||||
"tag": 5,
|
||||
"name": "c5",
|
||||
"kind": "int",
|
||||
"is_part_of_pk": false,
|
||||
"col_constraints": []
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -100,8 +100,9 @@ teardown() {
|
||||
dolt table create -f -s=`batshelper 1pk5col-ints-diff-pk.schema` test
|
||||
run dolt diff --schema
|
||||
[ "$status" -eq 0 ]
|
||||
skip "Schema diff output does not handle changing primary keys"
|
||||
[[ "$output" =~ "PRIMARY KEY" ]] || false
|
||||
[[ "$output" =~ "< PRIMARY KEY (\`pk\`)" ]] || false
|
||||
[[ "$output" =~ "> PRIMARY KEY (\`c1\`)" ]] || false
|
||||
}
|
||||
|
||||
@test "add another primary key. view the schema diff" {
|
||||
@@ -111,8 +112,9 @@ teardown() {
|
||||
dolt table create -f -s=`batshelper 1pk5col-ints-add-pk.schema` test
|
||||
run dolt diff --schema
|
||||
[ "$status" -eq 0 ]
|
||||
skip "Schema diff output does not handle adding primary keys. Additionally, rows that should not be in the diff show up."
|
||||
[[ "$output" =~ "PRIMARY KEY" ]] || false
|
||||
[[ "$output" =~ "< PRIMARY KEY (\`pk\`)" ]] || false
|
||||
[[ "$output" =~ "> PRIMARY KEY (\`c1\`, \`c5\`)" ]] || false
|
||||
}
|
||||
|
||||
@test "adding and dropping column should produce no diff" {
|
||||
@@ -122,7 +124,41 @@ teardown() {
|
||||
dolt schema add-column test c0 int
|
||||
dolt schema drop-column test c0
|
||||
run dolt diff
|
||||
skip "This produces a diff when it should not"
|
||||
[ "$status" -eq 0 ]
|
||||
[ "$output" = "" ]
|
||||
}
|
||||
}
|
||||
|
||||
@test "schema diff should show primary keys in output" {
|
||||
dolt table create -s=`batshelper 1pk5col-ints.schema` test
|
||||
dolt add test
|
||||
dolt commit -m "committed table so we can see diffs"
|
||||
dolt table create -f -s=`batshelper 1pk5col-ints-change-col-name.schema` test
|
||||
echo dolt diff --schema
|
||||
run dolt diff --schema
|
||||
[ "$status" -eq 0 ]
|
||||
[[ "$output" =~ "PRIMARY KEY" ]] || false
|
||||
}
|
||||
|
||||
@test "add another new primary key column. view the schema diff" {
|
||||
dolt table create -s=`batshelper 1pk5col-ints.schema` test
|
||||
dolt add test
|
||||
dolt commit -m "committed table so we can see diffs"
|
||||
dolt table create -f -s=`batshelper 1pk5col-ints-add-col-pk.schema` test
|
||||
run dolt diff --schema
|
||||
[ "$status" -eq 0 ]
|
||||
[[ "$output" =~ "PRIMARY KEY" ]] || false
|
||||
[[ "$output" =~ "< PRIMARY KEY (\`pk\`)" ]] || false
|
||||
[[ "$output" =~ "> PRIMARY KEY (\`pk\`, \`c6\`)" ]] || false
|
||||
}
|
||||
|
||||
@test "remove a primary key column. view the schema diff" {
|
||||
dolt table create -s=`batshelper 1pk5col-ints.schema` test
|
||||
dolt add test
|
||||
dolt commit -m "committed table so we can see diffs"
|
||||
dolt table create -f -s=`batshelper 1pk5col-ints-rm-pk-col.schema` test
|
||||
run dolt diff --schema
|
||||
[ "$status" -eq 0 ]
|
||||
[[ "$output" =~ "PRIMARY KEY" ]] || false
|
||||
[[ "$output" =~ "< PRIMARY KEY (\`pk\`)" ]] || false
|
||||
[[ "$output" =~ "> PRIMARY KEY (\`c3\`)" ]] || false
|
||||
}
|
||||
|
||||
@@ -488,21 +488,14 @@ func tabularSchemaDiff(tableName string, tags []uint64, diffs map[uint64]diff.Sc
|
||||
}
|
||||
}
|
||||
|
||||
if len(oldPks) > 0 && len(newPks) == 0 {
|
||||
oldPKStr := strings.Join(oldPks, ", ")
|
||||
cli.Print(sql.FmtColPrimaryKey(4, oldPKStr))
|
||||
} else if len(oldPks) == 0 && len(newPks) > 0 {
|
||||
newPKStr := strings.Join(newPks, ", ")
|
||||
cli.Print(sql.FmtColPrimaryKey(4, newPKStr))
|
||||
oldPKStr := strings.Join(oldPks, ", ")
|
||||
newPKStr := strings.Join(newPks, ", ")
|
||||
|
||||
if oldPKStr != newPKStr {
|
||||
cli.Print("< " + color.YellowString(sql.FmtColPrimaryKey(2, oldPKStr)))
|
||||
cli.Print("> " + color.YellowString(sql.FmtColPrimaryKey(2, newPKStr)))
|
||||
} else {
|
||||
oldPKStr := strings.Join(oldPks, ", ")
|
||||
newPKStr := strings.Join(newPks, ", ")
|
||||
if oldPKStr != newPKStr {
|
||||
cli.Print("< " + color.YellowString(sql.FmtColPrimaryKey(2, oldPKStr)))
|
||||
cli.Print("> " + color.YellowString(sql.FmtColPrimaryKey(2, newPKStr)))
|
||||
} else {
|
||||
cli.Print(sql.FmtColPrimaryKey(4, newPKStr))
|
||||
}
|
||||
cli.Print(sql.FmtColPrimaryKey(4, oldPKStr))
|
||||
}
|
||||
|
||||
cli.Println(" );")
|
||||
|
||||
Reference in New Issue
Block a user