From 4e0254923608ac222f96045771dbde3aacaae1d1 Mon Sep 17 00:00:00 2001 From: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com> Date: Mon, 2 Sep 2024 11:06:52 +0300 Subject: [PATCH] schemadiff: reject 'uuid_short' and 'random_bytes' in new column expression Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com> --- go/vt/schemadiff/table.go | 4 +++- go/vt/schemadiff/table_test.go | 12 ++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/go/vt/schemadiff/table.go b/go/vt/schemadiff/table.go index d73259523b5..d3df04c018d 100644 --- a/go/vt/schemadiff/table.go +++ b/go/vt/schemadiff/table.go @@ -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) { @@ -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 } diff --git a/go/vt/schemadiff/table_test.go b/go/vt/schemadiff/table_test.go index c511343b1d6..fe64acb4a13 100644 --- a/go/vt/schemadiff/table_test.go +++ b/go/vt/schemadiff/table_test.go @@ -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)", @@ -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)",