File tree Expand file tree Collapse file tree 12 files changed +104
-24
lines changed
localtests/fail-rename-table Expand file tree Collapse file tree 12 files changed +104
-24
lines changed Original file line number Diff line number Diff line change @@ -94,7 +94,7 @@ Please see [Coding gh-ost](doc/coding-ghost.md) for a guide to getting started d
94
94
95
95
[ Download latest release here] ( https://github.com/github/gh-ost/releases/latest )
96
96
97
- ` gh-ost ` is a Go project; it is built with Go ` 1.8 ` (though ` 1.7 ` should work as well) . To build on your own, use either:
97
+ ` gh-ost ` is a Go project; it is built with Go ` 1.9 ` and above . To build on your own, use either:
98
98
- [ script/build] ( https://github.com/github/gh-ost/blob/master/script/build ) - this is the same build script used by CI hence the authoritative; artifact is ` ./bin/gh-ost ` binary.
99
99
- [ build.sh] ( https://github.com/github/gh-ost/blob/master/build.sh ) for building ` tar.gz ` artifacts in ` /tmp/gh-ost `
100
100
Original file line number Diff line number Diff line change @@ -10,7 +10,7 @@ function build {
10
10
GOOS=$3
11
11
GOARCH=$4
12
12
13
- if [[ $( go version | egrep " go1 [.][012345678] " ) ]] ; then
13
+ if ! go version | egrep -q ' go(1 [.]9|1[.]1[0-9]) ' ; then
14
14
echo " go version is too low. Must use 1.9 or above"
15
15
exit 1
16
16
fi
Original file line number Diff line number Diff line change @@ -28,23 +28,23 @@ type RowsEstimateMethod string
28
28
29
29
const (
30
30
TableStatusRowsEstimate RowsEstimateMethod = "TableStatusRowsEstimate"
31
- ExplainRowsEstimate = "ExplainRowsEstimate"
32
- CountRowsEstimate = "CountRowsEstimate"
31
+ ExplainRowsEstimate RowsEstimateMethod = "ExplainRowsEstimate"
32
+ CountRowsEstimate RowsEstimateMethod = "CountRowsEstimate"
33
33
)
34
34
35
35
type CutOver int
36
36
37
37
const (
38
- CutOverAtomic CutOver = iota
39
- CutOverTwoStep = iota
38
+ CutOverAtomic CutOver = iota
39
+ CutOverTwoStep
40
40
)
41
41
42
42
type ThrottleReasonHint string
43
43
44
44
const (
45
45
NoThrottleReasonHint ThrottleReasonHint = "NoThrottleReasonHint"
46
- UserCommandThrottleReasonHint = "UserCommandThrottleReasonHint"
47
- LeavingHibernationThrottleReasonHint = "LeavingHibernationThrottleReasonHint"
46
+ UserCommandThrottleReasonHint ThrottleReasonHint = "UserCommandThrottleReasonHint"
47
+ LeavingHibernationThrottleReasonHint ThrottleReasonHint = "LeavingHibernationThrottleReasonHint"
48
48
)
49
49
50
50
const (
Original file line number Diff line number Diff line change @@ -7,17 +7,18 @@ package binlog
7
7
8
8
import (
9
9
"fmt"
10
- "github.com/github/gh-ost/go/sql"
11
10
"strings"
11
+
12
+ "github.com/github/gh-ost/go/sql"
12
13
)
13
14
14
15
type EventDML string
15
16
16
17
const (
17
18
NotDML EventDML = "NoDML"
18
- InsertDML = "Insert"
19
- UpdateDML = "Update"
20
- DeleteDML = "Delete"
19
+ InsertDML EventDML = "Insert"
20
+ UpdateDML EventDML = "Update"
21
+ DeleteDML EventDML = "Delete"
21
22
)
22
23
23
24
func ToEventDML (description string ) EventDML {
Original file line number Diff line number Diff line change @@ -255,7 +255,11 @@ func (this *Migrator) listenOnPanicAbort() {
255
255
// validateStatement validates the `alter` statement meets criteria.
256
256
// At this time this means:
257
257
// - column renames are approved
258
+ // - no table rename allowed
258
259
func (this * Migrator ) validateStatement () (err error ) {
260
+ if this .parser .IsRenameTable () {
261
+ return fmt .Errorf ("ALTER statement seems to RENAME the table. This is not supported, and you should run your RENAME outside gh-ost." )
262
+ }
259
263
if this .parser .HasNonTrivialRenames () && ! this .migrationContext .SkipRenamedColumns {
260
264
this .migrationContext .ColumnRenameMap = this .parser .GetNonTrivialRenames ()
261
265
if ! this .migrationContext .ApproveRenamedColumns {
Original file line number Diff line number Diff line change @@ -15,11 +15,11 @@ type ValueComparisonSign string
15
15
16
16
const (
17
17
LessThanComparisonSign ValueComparisonSign = "<"
18
- LessThanOrEqualsComparisonSign = "<="
19
- EqualsComparisonSign = "="
20
- GreaterThanOrEqualsComparisonSign = ">="
21
- GreaterThanComparisonSign = ">"
22
- NotEqualsComparisonSign = "!="
18
+ LessThanOrEqualsComparisonSign ValueComparisonSign = "<="
19
+ EqualsComparisonSign ValueComparisonSign = "="
20
+ GreaterThanOrEqualsComparisonSign ValueComparisonSign = ">="
21
+ GreaterThanComparisonSign ValueComparisonSign = ">"
22
+ NotEqualsComparisonSign ValueComparisonSign = "!="
23
23
)
24
24
25
25
// EscapeName will escape a db/table/column/... name by wrapping with backticks.
Original file line number Diff line number Diff line change @@ -15,11 +15,13 @@ var (
15
15
sanitizeQuotesRegexp = regexp .MustCompile ("('[^']*')" )
16
16
renameColumnRegexp = regexp .MustCompile (`(?i)\bchange\s+(column\s+|)([\S]+)\s+([\S]+)\s+` )
17
17
dropColumnRegexp = regexp .MustCompile (`(?i)\bdrop\s+(column\s+|)([\S]+)$` )
18
+ renameTableRegexp = regexp .MustCompile (`(?i)\brename\s+(to|as)\s+` )
18
19
)
19
20
20
21
type Parser struct {
21
22
columnRenameMap map [string ]string
22
23
droppedColumns map [string ]bool
24
+ isRenameTable bool
23
25
}
24
26
25
27
func NewParser () * Parser {
@@ -86,6 +88,12 @@ func (this *Parser) parseAlterToken(alterToken string) (err error) {
86
88
this .droppedColumns [submatch [2 ]] = true
87
89
}
88
90
}
91
+ {
92
+ // rename table
93
+ if renameTableRegexp .MatchString (alterToken ) {
94
+ this .isRenameTable = true
95
+ }
96
+ }
89
97
return nil
90
98
}
91
99
@@ -115,3 +123,7 @@ func (this *Parser) HasNonTrivialRenames() bool {
115
123
func (this * Parser ) DroppedColumnsMap () map [string ]bool {
116
124
return this .droppedColumns
117
125
}
126
+
127
+ func (this * Parser ) IsRenameTable () bool {
128
+ return this .isRenameTable
129
+ }
Original file line number Diff line number Diff line change @@ -159,3 +159,42 @@ func TestParseAlterStatementDroppedColumns(t *testing.T) {
159
159
test .S (t ).ExpectTrue (parser .droppedColumns ["b" ])
160
160
}
161
161
}
162
+
163
+ func TestParseAlterStatementRenameTable (t * testing.T ) {
164
+
165
+ {
166
+ parser := NewParser ()
167
+ statement := "drop column b"
168
+ err := parser .ParseAlterStatement (statement )
169
+ test .S (t ).ExpectNil (err )
170
+ test .S (t ).ExpectFalse (parser .isRenameTable )
171
+ }
172
+ {
173
+ parser := NewParser ()
174
+ statement := "rename as something_else"
175
+ err := parser .ParseAlterStatement (statement )
176
+ test .S (t ).ExpectNil (err )
177
+ test .S (t ).ExpectTrue (parser .isRenameTable )
178
+ }
179
+ {
180
+ parser := NewParser ()
181
+ statement := "drop column b, rename as something_else"
182
+ err := parser .ParseAlterStatement (statement )
183
+ test .S (t ).ExpectNil (err )
184
+ test .S (t ).ExpectTrue (parser .isRenameTable )
185
+ }
186
+ {
187
+ parser := NewParser ()
188
+ statement := "engine=innodb rename as something_else"
189
+ err := parser .ParseAlterStatement (statement )
190
+ test .S (t ).ExpectNil (err )
191
+ test .S (t ).ExpectTrue (parser .isRenameTable )
192
+ }
193
+ {
194
+ parser := NewParser ()
195
+ statement := "rename as something_else, engine=innodb"
196
+ err := parser .ParseAlterStatement (statement )
197
+ test .S (t ).ExpectNil (err )
198
+ test .S (t ).ExpectTrue (parser .isRenameTable )
199
+ }
200
+ }
Original file line number Diff line number Diff line change @@ -15,13 +15,13 @@ import (
15
15
type ColumnType int
16
16
17
17
const (
18
- UnknownColumnType ColumnType = iota
19
- TimestampColumnType = iota
20
- DateTimeColumnType = iota
21
- EnumColumnType = iota
22
- MediumIntColumnType = iota
23
- JSONColumnType = iota
24
- FloatColumnType = iota
18
+ UnknownColumnType ColumnType = iota
19
+ TimestampColumnType
20
+ DateTimeColumnType
21
+ EnumColumnType
22
+ MediumIntColumnType
23
+ JSONColumnType
24
+ FloatColumnType
25
25
)
26
26
27
27
const maxMediumintUnsigned int32 = 16777215
Original file line number Diff line number Diff line change
1
+ drop table if exists gh_ost_test;
2
+ create table gh_ost_test (
3
+ id int auto_increment,
4
+ i int not null ,
5
+ ts timestamp ,
6
+ primary key (id)
7
+ ) auto_increment= 1 ;
8
+
9
+ drop event if exists gh_ost_test;
10
+ delimiter ;;
11
+ create event gh_ost_test
12
+ on schedule every 1 second
13
+ starts current_timestamp
14
+ ends current_timestamp + interval 60 second
15
+ on completion not preserve
16
+ enable
17
+ do
18
+ begin
19
+ insert into gh_ost_test values (null , 11 , now());
20
+ insert into gh_ost_test values (null , 13 , now());
21
+ insert into gh_ost_test values (null , 17 , now());
22
+ end ;;
You can’t perform that action at this time.
0 commit comments