From ab18801da651c3c9fcc0e46a88e6c1de8bb8d76c Mon Sep 17 00:00:00 2001 From: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com> Date: Tue, 6 Dec 2022 19:16:20 +0200 Subject: [PATCH] Online DDL: fix 'vtctlclient OnlineDDL' template queries (#11889) Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com> Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com> --- go/vt/vttablet/onlineddl/executor.go | 8 ++++---- go/vt/vttablet/onlineddl/executor_test.go | 20 ++++++++++++++++++++ 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/go/vt/vttablet/onlineddl/executor.go b/go/vt/vttablet/onlineddl/executor.go index 4c0a90ce6a9..d9421009b37 100644 --- a/go/vt/vttablet/onlineddl/executor.go +++ b/go/vt/vttablet/onlineddl/executor.go @@ -78,9 +78,9 @@ var ( ) var vexecUpdateTemplates = []string{ - `update _vt.schema_migrations set migration_status='val' where mysql_schema='val'`, - `update _vt.schema_migrations set migration_status='val' where migration_uuid='val' and mysql_schema='val'`, - `update _vt.schema_migrations set migration_status='val' where migration_uuid='val' and mysql_schema='val' and shard='val'`, + `update _vt.schema_migrations set migration_status='val1' where mysql_schema='val2'`, + `update _vt.schema_migrations set migration_status='val1' where migration_uuid='val2' and mysql_schema='val3'`, + `update _vt.schema_migrations set migration_status='val1' where migration_uuid='val2' and mysql_schema='val3' and shard='val4'`, } var vexecInsertTemplates = []string{ @@ -98,7 +98,7 @@ var vexecInsertTemplates = []string{ migration_context, migration_status ) VALUES ( - 'val', 'val', 'val', 'val', 'val', 'val', 'val', 'val', 'val', FROM_UNIXTIME(0), 'val', 'val' + 'val1', 'val2', 'val3', 'val4', 'val5', 'val6', 'val7', 'val8', 'val9', FROM_UNIXTIME(0), 'vala', 'valb' )`, } diff --git a/go/vt/vttablet/onlineddl/executor_test.go b/go/vt/vttablet/onlineddl/executor_test.go index 2d9be7630f6..8b30f6651cb 100644 --- a/go/vt/vttablet/onlineddl/executor_test.go +++ b/go/vt/vttablet/onlineddl/executor_test.go @@ -31,6 +31,26 @@ import ( "vitess.io/vitess/go/vt/sqlparser" ) +func TestVexecUpdateTemplates(t *testing.T) { + { + match, err := sqlparser.QueryMatchesTemplates("select 1 from dual", vexecUpdateTemplates) + assert.NoError(t, err) + assert.False(t, match) + } + queries := []string{ + `update _vt.schema_migrations set migration_status='cancel-all' where mysql_schema='vt_commerce'`, + `update _vt.schema_migrations set migration_status = 'cancel-all' where migration_uuid='a5a563da_dc1a_11ec_a416_0a43f95f28a3' and mysql_schema = 'vt_commerce'`, + `update _vt.schema_migrations set migration_status = 'cancel-all' where migration_uuid='a5a563da_dc1a_11ec_a416_0a43f95f28a3' and mysql_schema = 'vt_commerce' and shard='0'`, + } + for _, query := range queries { + t.Run(query, func(t *testing.T) { + match, err := sqlparser.QueryMatchesTemplates(query, vexecUpdateTemplates) + assert.NoError(t, err) + assert.True(t, match) + }) + } +} + func TestValidateAndEditCreateTableStatement(t *testing.T) { e := Executor{} tt := []struct {