Skip to content

Commit 7d2af2d

Browse files
committed
support changing amount of pk cols
1 parent a3cf090 commit 7d2af2d

File tree

5 files changed

+104
-112
lines changed

5 files changed

+104
-112
lines changed

columns.go

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package main
33
import (
44
"strings"
55

6-
cool "github.com/StirlingMarketingGroup/cool-mysql"
6+
mysql "github.com/StirlingMarketingGroup/cool-mysql"
77
)
88

99
// the mysql lib we're using, cool mysql, lets us define a
@@ -18,8 +18,8 @@ type column struct {
1818
PrimaryKey bool
1919
}
2020

21-
func getTableColumns(db *cool.Database, tableName string) ([]*column, error) {
22-
var columns []*column
21+
func getTableColumns(db *mysql.Database, tableName string) ([]column, error) {
22+
var columns []column
2323

2424
// we need to check to see if the db supports generated columns
2525
// if it doesn't, our query to get column info will fail
@@ -47,7 +47,7 @@ func getTableColumns(db *cool.Database, tableName string) ([]*column, error) {
4747
return nil, err
4848
}
4949

50-
var primaryKeys []*struct {
50+
var primaryKeys []struct {
5151
ColumnName string `mysql:"Column_name"`
5252
}
5353
err = db.Select(&primaryKeys, "show index from`"+tableName+"`where`Key_name`='PRIMARY'", 0)
@@ -60,7 +60,8 @@ func getTableColumns(db *cool.Database, tableName string) ([]*column, error) {
6060
primaryKeysSet[pk.ColumnName] = struct{}{}
6161
}
6262

63-
for _, c := range columns {
63+
for i := range columns {
64+
c := &columns[i]
6465
if _, ok := primaryKeysSet[c.ColumnName]; ok {
6566
c.PrimaryKey = true
6667
}
@@ -69,11 +70,11 @@ func getTableColumns(db *cool.Database, tableName string) ([]*column, error) {
6970
return columns, nil
7071
}
7172

72-
func quoteColumns(columns []*column) string {
73+
func quoteColumns(columns []column) string {
7374
return quoteColumnsPrefix(columns, "")
7475
}
7576

76-
func quoteColumnsPrefix(columns []*column, prefix string) string {
77+
func quoteColumnsPrefix(columns []column, prefix string) string {
7778
// this is our string builder for quoted column names,
7879
// which will be used in our select statement
7980
columnsQuotedBld := new(strings.Builder)
@@ -92,10 +93,18 @@ func quoteColumnsPrefix(columns []*column, prefix string) string {
9293
return columnsQuotedBld.String()
9394
}
9495

95-
func columnsSet(columns []*column) map[string]struct{} {
96+
func columnsSet(columns []column) map[string]struct{} {
9697
set := make(map[string]struct{}, len(columns))
9798
for _, c := range columns {
9899
set[c.ColumnName] = struct{}{}
99100
}
100101
return set
101102
}
103+
104+
func columnNames(columns []column) []string {
105+
names := make([]string, len(columns))
106+
for i, c := range columns {
107+
names[i] = c.ColumnName
108+
}
109+
return names
110+
}

go.mod

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
module github.com/StirlingMarketingGroup/smg-live-alter/v2
22

3-
go 1.19
3+
go 1.21
44

55
require (
66
github.com/Ompluscator/dynamic-struct v1.3.0
7-
github.com/StirlingMarketingGroup/cool-mysql v0.0.0-20221123151840-d6d3d1f1e306
7+
github.com/StirlingMarketingGroup/cool-mysql v0.0.0-20230825201905-be1f02aab9f2
88
github.com/fatih/color v1.13.0
9-
github.com/go-sql-driver/mysql v1.6.0
9+
github.com/go-sql-driver/mysql v1.7.1
10+
github.com/juliangruber/go-intersect/v2 v2.0.1
1011
github.com/posener/cmd v1.3.4
1112
github.com/vbauerster/mpb/v8 v8.0.2
1213
gopkg.in/yaml.v2 v2.4.0
@@ -15,30 +16,25 @@ require (
1516
require (
1617
github.com/VividCortex/ewma v1.2.0 // indirect
1718
github.com/acarl005/stripansi v0.0.0-20180116102854-5a71ef0e047d // indirect
18-
github.com/cenkalti/backoff/v4 v4.2.0 // indirect
19-
github.com/cespare/xxhash/v2 v2.1.2 // indirect
20-
github.com/davecgh/go-spew v1.1.1 // indirect
19+
github.com/cenkalti/backoff/v4 v4.2.1 // indirect
20+
github.com/cespare/xxhash/v2 v2.2.0 // indirect
2121
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect
22-
github.com/fatih/structs v1.1.0 // indirect
2322
github.com/fatih/structtag v1.2.0 // indirect
24-
github.com/go-redis/redis/v8 v8.11.5 // indirect
25-
github.com/go-redsync/redsync/v4 v4.6.0 // indirect
26-
github.com/google/uuid v1.3.0 // indirect
23+
github.com/go-redsync/redsync/v4 v4.8.1 // indirect
2724
github.com/hashicorp/errwrap v1.1.0 // indirect
2825
github.com/hashicorp/go-multierror v1.1.1 // indirect
29-
github.com/jinzhu/copier v0.3.5 // indirect
3026
github.com/mattn/go-colorable v0.1.13 // indirect
3127
github.com/mattn/go-isatty v0.0.16 // indirect
3228
github.com/mattn/go-runewidth v0.0.13 // indirect
3329
github.com/posener/complete/v2 v2.0.1-alpha.13 // indirect
3430
github.com/posener/formatter v1.0.0 // indirect
3531
github.com/posener/script v1.1.5 // indirect
32+
github.com/redis/go-redis/v9 v9.1.0 // indirect
3633
github.com/rivo/uniseg v0.4.2 // indirect
37-
github.com/shopspring/decimal v1.3.1 // indirect
3834
github.com/vmihailenco/msgpack/v5 v5.3.5 // indirect
3935
github.com/vmihailenco/tagparser/v2 v2.0.0 // indirect
40-
go.uber.org/atomic v1.10.0 // indirect
41-
go.uber.org/multierr v1.8.0 // indirect
42-
go.uber.org/zap v1.23.0 // indirect
36+
go.uber.org/multierr v1.11.0 // indirect
37+
go.uber.org/zap v1.25.0 // indirect
38+
golang.org/x/sync v0.3.0 // indirect
4339
golang.org/x/sys v0.0.0-20220909162455-aba9fc2a8ff2 // indirect
4440
)

0 commit comments

Comments
 (0)