Skip to content

Commit

Permalink
schemadiff: more index expression validations (tests only) (#17483)
Browse files Browse the repository at this point in the history
Signed-off-by: Shlomi Noach <[email protected]>
  • Loading branch information
shlomi-noach authored Jan 13, 2025
1 parent f3cafe8 commit ac8bbc6
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 0 deletions.
5 changes: 5 additions & 0 deletions go/test/endtoend/onlineddl/revert/onlineddl_revert_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,11 @@ func testRevertible(t *testing.T) {
toSchema: `id int primary key, i2 int default null`,
removedUniqueKeyNames: `i1_uidx`,
},
{
name: "removed expression unique key, skipped",
fromSchema: `id int primary key, i1 int default null, unique key idx1 ((id + 1))`,
toSchema: `id int primary key, i2 int default null`,
},
{
name: "expanding unique key removes unique constraint",
fromSchema: `id int primary key, i1 int default null, unique key i1_uidx(i1)`,
Expand Down
5 changes: 5 additions & 0 deletions go/vt/schemadiff/onlineddl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -937,6 +937,11 @@ func TestRevertible(t *testing.T) {
fromSchema: "id int, primary key (id), key idx1 ((id + 1))",
toSchema: "id int, primary key (id), key idx2 ((id + 2))",
},
{
name: "remove unique index with expression, add another, skip both",
fromSchema: "id int, i int, primary key (id), unique key idx1 ((id + 1))",
toSchema: "id int, i int, primary key (id), unique key idx2 ((i + 2))",
},
}

var (
Expand Down
18 changes: 18 additions & 0 deletions go/vt/schemadiff/table_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2582,6 +2582,24 @@ func TestValidate(t *testing.T) {
alter: "alter table t add key idx2 ((id + 2))",
to: "create table t (id int, primary key (id), key idx1 ((id + 1)), key idx2 ((id + 2)))",
},
{
name: "key with multicolumn expression",
from: "create table t (id int, i int, primary key (id), key idx1 ((id + 1), (i + 2)))",
alter: "alter table t add key idx2 ((id + 2))",
to: "create table t (id int, i int, primary key (id), key idx1 ((id + 1), (i + 2)), key idx2 ((id + 2)))",
},
{
name: "key with expression and unknown columns",
from: "create table t (id int, i int, primary key (id), key idx1 ((id + 1), (i + 2)))",
alter: "alter table t add key idx2 ((i2 + 2))",
expectErr: &InvalidColumnInKeyError{Table: "t", Column: "i2", Key: "idx2"},
},
{
name: "drop column used in expression",
from: "create table t (id int, i int, primary key (id), key idx1 ((id + 1), (i + 2)))",
alter: "alter table t drop column i",
expectErr: &InvalidColumnInKeyError{Table: "t", Column: "i", Key: "idx1"},
},
// partitions
{
name: "drop column used by partitions",
Expand Down

0 comments on commit ac8bbc6

Please sign in to comment.