Skip to content

Commit

Permalink
properly escape sequence table names (#12597)
Browse files Browse the repository at this point in the history
Signed-off-by: Hormoz Kheradmand <hormoz.kheradmand@shopify.com>
Co-authored-by: Hormoz Kheradmand <hormoz.kheradmand@shopify.com>
  • Loading branch information
vitess-bot[bot] and hkdsun authored Mar 27, 2023
1 parent dcc517b commit 0369347
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 10 deletions.
9 changes: 1 addition & 8 deletions go/vt/topotools/vschema_ddl.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ limitations under the License.
package topotools

import (
"fmt"
"reflect"

"vitess.io/vitess/go/vt/sqlparser"
Expand Down Expand Up @@ -226,15 +225,9 @@ func ApplyVSchemaDDL(ksName string, ks *vschemapb.Keyspace, alterVschema *sqlpar
return nil, vterrors.Errorf(vtrpcpb.Code_INTERNAL, "vschema already contains auto inc %v on table %s in keyspace %s", table.AutoIncrement, name, ksName)
}

sequence := alterVschema.AutoIncSpec.Sequence
sequenceFqn := sequence.Name.String()
if sequence.Qualifier.String() != "" {
sequenceFqn = fmt.Sprintf("%s.%s", sequence.Qualifier.String(), sequenceFqn)
}

table.AutoIncrement = &vschemapb.AutoIncrement{
Column: alterVschema.AutoIncSpec.Column.String(),
Sequence: sequenceFqn,
Sequence: sqlparser.String(alterVschema.AutoIncSpec.Sequence),
}

return ks, nil
Expand Down
4 changes: 2 additions & 2 deletions go/vt/vtgate/executor_vschema_ddl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -373,13 +373,13 @@ func TestExecutorAddSequenceDDL(t *testing.T) {
}
time.Sleep(10 * time.Millisecond)

stmt = "alter vschema on test_table add auto_increment id using test_seq"
stmt = "alter vschema on test_table add auto_increment id using `db-name`.`test_seq`"
if _, err = executor.Execute(context.Background(), "TestExecute", session, stmt, nil); err != nil {
t.Error(err)
}
time.Sleep(10 * time.Millisecond)

wantAutoInc := &vschemapb.AutoIncrement{Column: "id", Sequence: "test_seq"}
wantAutoInc := &vschemapb.AutoIncrement{Column: "id", Sequence: "`db-name`.test_seq"}
gotAutoInc := executor.vm.GetCurrentSrvVschema().Keyspaces[ksSharded].Tables["test_table"].AutoIncrement

if !reflect.DeepEqual(wantAutoInc, gotAutoInc) {
Expand Down

0 comments on commit 0369347

Please sign in to comment.