Skip to content

Commit 2186754

Browse files
Address review comments
Signed-off-by: Rohit Nayak <[email protected]>
1 parent 98743c6 commit 2186754

File tree

4 files changed

+11
-32
lines changed

4 files changed

+11
-32
lines changed

go/cmd/dbinfo.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ func dbinfoCmd() *cobra.Command {
4444
cmd.Flags().IntVarP(&vtParams.Port, "port", "", 3306, "Database port")
4545
cmd.Flags().StringVarP(&vtParams.Uname, "user", "", "root", "Database user")
4646
cmd.Flags().StringVarP(&vtParams.Pass, "password", "", "", "Database password")
47-
cmd.Flags().StringVarP(&vtParams.DbName, "database", "", "sakila", "Database name")
47+
cmd.Flags().StringVarP(&vtParams.DbName, "database", "", "", "Database name")
4848

4949
return cmd
5050
}

go/dbinfo/dbinfo.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ type TableColumn struct {
4949
Name string `json:"name"`
5050
Type string `json:"type"`
5151
KeyType string `json:"keyType,omitempty"`
52-
IsNullable bool `json:"isNullable"`
52+
IsNullable bool `json:"isNullable,omitempty"`
5353
Extra string `json:"extra,omitempty"`
5454
}
5555

@@ -60,9 +60,9 @@ type TableInfo struct {
6060
}
6161

6262
type Info struct {
63-
FileType string `json:"fileType"`
64-
Tables []*TableInfo `json:"tables"`
65-
GlobalVariables *map[string]string `json:"globalVariables"`
63+
FileType string `json:"fileType"`
64+
Tables []*TableInfo `json:"tables"`
65+
GlobalVariables map[string]string `json:"globalVariables"`
6666
}
6767

6868
func Get(cfg Config) (*Info, error) {

go/dbinfo/dbinfo_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,13 @@ func TestDBInfoLoad(t *testing.T) {
5454

5555
t.Run("validateGlobalVariables", func(t *testing.T) {
5656
require.NotEmpty(t, si.GlobalVariables)
57-
require.Len(t, *si.GlobalVariables, 3)
57+
require.Len(t, si.GlobalVariables, 3)
5858
expected := map[string]string{
5959
"binlog_format": "ROW",
6060
"binlog_row_image": "FULL",
6161
"log_bin": "ON",
6262
}
63-
require.EqualValues(t, expected, *si.GlobalVariables)
63+
require.EqualValues(t, expected, si.GlobalVariables)
6464
})
6565
}
6666

go/dbinfo/utils.go

+4-25
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ package dbinfo
1919
import (
2020
"context"
2121
"fmt"
22-
"regexp"
2322
"strings"
2423

2524
"vitess.io/vitess/go/mysql"
@@ -99,13 +98,14 @@ func (dbh *DBHelper) getColumnInfo() (tableColumns, error) {
9998
return tc, nil
10099
}
101100

102-
func (dbh *DBHelper) getGlobalVariables() (*map[string]string, error) {
101+
func (dbh *DBHelper) getGlobalVariables() (map[string]string, error) {
103102
// Currently only use simple regex to match the variable names
104103
// If the variable name contains ".*" then it is treated as a regex, else exact match
105104
globalVariablesToFetch := []string{
106105
"binlog_format",
107106
"binlog_row_image",
108107
"log_bin",
108+
"gtid_mode",
109109
}
110110

111111
vtConn, cancel, err := dbh.GetConnection()
@@ -123,31 +123,10 @@ func (dbh *DBHelper) getGlobalVariables() (*map[string]string, error) {
123123
variable := row[0].ToString()
124124
value := row[1].ToString()
125125
for _, gvName := range globalVariablesToFetch {
126-
if strings.Contains(gvName, ".*") {
127-
matched, _ := regexp.MatchString(gvName, variable)
128-
if matched {
129-
gv[variable] = value
130-
}
131-
} else if variable == gvName {
126+
if variable == gvName {
132127
gv[variable] = value
133128
}
134129
}
135130
}
136-
return &gv, nil
131+
return gv, nil
137132
}
138-
139-
// For future enhancements
140-
// Primary key info
141-
// SELECT TABLE_SCHEMA, TABLE_NAME, COLUMN_NAME, CONSTRAINT_NAME
142-
// FROM INFORMATION_SCHEMA.KEY_COLUMN_USAGE
143-
// WHERE CONSTRAINT_NAME = 'PRIMARY' AND TABLE_SCHEMA = 'your_database_name';
144-
145-
// Indexes
146-
// SELECT TABLE_SCHEMA, TABLE_NAME, INDEX_NAME, COLUMN_NAME, NON_UNIQUE
147-
// FROM INFORMATION_SCHEMA.STATISTICS
148-
// WHERE TABLE_SCHEMA = 'your_database_name'
149-
150-
// Foreign Keys with Dependency Information
151-
// SELECT TABLE_SCHEMA, TABLE_NAME, COLUMN_NAME, CONSTRAINT_NAME, REFERENCED_TABLE_SCHEMA, REFERENCED_TABLE_NAME, REFERENCED_COLUMN_NAME
152-
// FROM INFORMATION_SCHEMA.KEY_COLUMN_USAGE
153-
// WHERE TABLE_SCHEMA = 'your_database_name' AND REFERENCED_TABLE_NAME IS NOT NULL;

0 commit comments

Comments
 (0)