Skip to content

Commit

Permalink
schemadiff: reject 'uuid_short' and 'random_bytes' in new column expr…
Browse files Browse the repository at this point in the history
…ession

Signed-off-by: Shlomi Noach <[email protected]>
  • Loading branch information
shlomi-noach committed Sep 2, 2024
1 parent 37e0707 commit 4e02549
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
4 changes: 3 additions & 1 deletion go/vt/schemadiff/table.go
Original file line number Diff line number Diff line change
Expand Up @@ -1735,7 +1735,9 @@ func evaluateColumnReordering(t1SharedColumns, t2SharedColumns []*sqlparser.Colu
// If recurses into all function arguments.
// The known non-deterministic function we handle are:
// - UUID()
// - UUID_SHORT()
// - RAND()
// - RANDOM_BYTES()
// - SYSDATE()
func findNoNondeterministicFunction(expr sqlparser.Expr) (foundFunction string) {
_ = sqlparser.Walk(func(node sqlparser.SQLNode) (kontinue bool, err error) {
Expand All @@ -1748,7 +1750,7 @@ func findNoNondeterministicFunction(expr sqlparser.Expr) (foundFunction string)
}
case *sqlparser.FuncExpr:
switch node.Name.Lowered() {
case "uuid", "rand":
case "uuid", "uuid_short", "rand", "random_bytes":
foundFunction = node.Name.String()
return false, nil
}
Expand Down
12 changes: 12 additions & 0 deletions go/vt/schemadiff/table_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -457,6 +457,12 @@ func TestCreateTableDiff(t *testing.T) {
to: "create table t2 (id int primary key, a int, v varchar(36) not null default (uuid()))",
errorMsg: (&NonDeterministicDefaultError{Table: "t1", Column: "v", Function: "uuid"}).Error(),
},
{
name: "added column with non deterministic expression, uuid, reject",
from: "create table t1 (id int primary key, a int)",
to: "create table t2 (id int primary key, a int, v varchar(36) not null default (uuid_short()))",
errorMsg: (&NonDeterministicDefaultError{Table: "t1", Column: "v", Function: "uuid_short"}).Error(),
},
{
name: "added column with non deterministic expression, UUID, reject",
from: "create table t1 (id int primary key, a int)",
Expand All @@ -481,6 +487,12 @@ func TestCreateTableDiff(t *testing.T) {
to: "create table t2 (id int primary key, a int, v varchar(36) not null default (2.0 + rand()))",
errorMsg: (&NonDeterministicDefaultError{Table: "t1", Column: "v", Function: "rand"}).Error(),
},
{
name: "added column with non deterministic expression, random_bytes, reject",
from: "create table t1 (id int primary key, a int)",
to: "create table t2 (id int primary key, a int, v varchar(36) not null default (random_bytes(3)))",
errorMsg: (&NonDeterministicDefaultError{Table: "t1", Column: "v", Function: "random_bytes"}).Error(),
},
{
name: "added column with non deterministic expression, sysdate, reject",
from: "create table t1 (id int primary key, a int)",
Expand Down

0 comments on commit 4e02549

Please sign in to comment.