Skip to content

Commit ac8bbc6

Browse files
authored
schemadiff: more index expression validations (tests only) (vitessio#17483)
Signed-off-by: Shlomi Noach <[email protected]>
1 parent f3cafe8 commit ac8bbc6

File tree

3 files changed

+28
-0
lines changed

3 files changed

+28
-0
lines changed

go/test/endtoend/onlineddl/revert/onlineddl_revert_test.go

+5
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,11 @@ func testRevertible(t *testing.T) {
259259
toSchema: `id int primary key, i2 int default null`,
260260
removedUniqueKeyNames: `i1_uidx`,
261261
},
262+
{
263+
name: "removed expression unique key, skipped",
264+
fromSchema: `id int primary key, i1 int default null, unique key idx1 ((id + 1))`,
265+
toSchema: `id int primary key, i2 int default null`,
266+
},
262267
{
263268
name: "expanding unique key removes unique constraint",
264269
fromSchema: `id int primary key, i1 int default null, unique key i1_uidx(i1)`,

go/vt/schemadiff/onlineddl_test.go

+5
Original file line numberDiff line numberDiff line change
@@ -937,6 +937,11 @@ func TestRevertible(t *testing.T) {
937937
fromSchema: "id int, primary key (id), key idx1 ((id + 1))",
938938
toSchema: "id int, primary key (id), key idx2 ((id + 2))",
939939
},
940+
{
941+
name: "remove unique index with expression, add another, skip both",
942+
fromSchema: "id int, i int, primary key (id), unique key idx1 ((id + 1))",
943+
toSchema: "id int, i int, primary key (id), unique key idx2 ((i + 2))",
944+
},
940945
}
941946

942947
var (

go/vt/schemadiff/table_test.go

+18
Original file line numberDiff line numberDiff line change
@@ -2582,6 +2582,24 @@ func TestValidate(t *testing.T) {
25822582
alter: "alter table t add key idx2 ((id + 2))",
25832583
to: "create table t (id int, primary key (id), key idx1 ((id + 1)), key idx2 ((id + 2)))",
25842584
},
2585+
{
2586+
name: "key with multicolumn expression",
2587+
from: "create table t (id int, i int, primary key (id), key idx1 ((id + 1), (i + 2)))",
2588+
alter: "alter table t add key idx2 ((id + 2))",
2589+
to: "create table t (id int, i int, primary key (id), key idx1 ((id + 1), (i + 2)), key idx2 ((id + 2)))",
2590+
},
2591+
{
2592+
name: "key with expression and unknown columns",
2593+
from: "create table t (id int, i int, primary key (id), key idx1 ((id + 1), (i + 2)))",
2594+
alter: "alter table t add key idx2 ((i2 + 2))",
2595+
expectErr: &InvalidColumnInKeyError{Table: "t", Column: "i2", Key: "idx2"},
2596+
},
2597+
{
2598+
name: "drop column used in expression",
2599+
from: "create table t (id int, i int, primary key (id), key idx1 ((id + 1), (i + 2)))",
2600+
alter: "alter table t drop column i",
2601+
expectErr: &InvalidColumnInKeyError{Table: "t", Column: "i", Key: "idx1"},
2602+
},
25852603
// partitions
25862604
{
25872605
name: "drop column used by partitions",

0 commit comments

Comments
 (0)