vitess.io/vitess@v0.16.2/go/vt/vtctl/schematools/diff.go (about) 1 /* 2 Copyright 2021 The Vitess Authors. 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 package schematools 18 19 import ( 20 "context" 21 "fmt" 22 23 "vitess.io/vitess/go/vt/mysqlctl/tmutils" 24 "vitess.io/vitess/go/vt/topo" 25 "vitess.io/vitess/go/vt/vttablet/tmclient" 26 27 tabletmanagerdatapb "vitess.io/vitess/go/vt/proto/tabletmanagerdata" 28 topodatapb "vitess.io/vitess/go/vt/proto/topodata" 29 ) 30 31 // CompareSchemas returns (nil, nil) if the schema of the two tablets match. If 32 // there are diffs, they are returned as (diffs []string, nil). 33 // 34 // If fetching the schema for either tablet fails, a non-nil error is returned. 35 func CompareSchemas( 36 ctx context.Context, 37 ts *topo.Server, 38 tmc tmclient.TabletManagerClient, 39 source *topodatapb.TabletAlias, 40 dest *topodatapb.TabletAlias, 41 tables []string, 42 excludeTables []string, 43 includeViews bool, 44 ) (diffs []string, err error) { 45 req := &tabletmanagerdatapb.GetSchemaRequest{Tables: tables, ExcludeTables: excludeTables, IncludeViews: includeViews} 46 sourceSchema, err := GetSchema(ctx, ts, tmc, source, req) 47 if err != nil { 48 return nil, fmt.Errorf("failed to get schema from tablet %v. err: %v", source, err) 49 } 50 51 destSchema, err := GetSchema(ctx, ts, tmc, dest, req) 52 if err != nil { 53 return nil, fmt.Errorf("failed to get schema from tablet %v. err: %v", dest, err) 54 } 55 56 return tmutils.DiffSchemaToArray("source", sourceSchema, "dest", destSchema), nil 57 }