Skip to content

Commit c9249f2

Browse files
committed
Updating and using AlterTableOptions
1 parent f482356 commit c9249f2

File tree

4 files changed

+18
-10
lines changed

4 files changed

+18
-10
lines changed

go/base/context.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,10 @@ func NewThrottleCheckResult(throttle bool, reason string, reasonHint ThrottleRea
7777
type MigrationContext struct {
7878
Uuid string
7979

80-
DatabaseName string
81-
OriginalTableName string
82-
AlterStatement string
80+
DatabaseName string
81+
OriginalTableName string
82+
AlterStatement string
83+
AlterStatementOptions string // anything following the 'ALTER TABLE [schema.]table' from AlterStatement
8384

8485
CountTableRows bool
8586
ConcurrentCountTableRows bool

go/cmd/gh-ost/main.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,7 @@ func main() {
177177
log.Fatalf("--alter must be provided and statement must not be empty")
178178
}
179179
parser := sql.NewParserFromAlterStatement(migrationContext.AlterStatement)
180+
migrationContext.AlterStatementOptions = parser.GetAlterStatementOptions()
180181

181182
if migrationContext.DatabaseName == "" {
182183
if parser.HasExplicitSchema() {

go/logic/applier.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ func (this *Applier) AlterGhost() error {
190190
query := fmt.Sprintf(`alter /* gh-ost */ table %s.%s %s`,
191191
sql.EscapeName(this.migrationContext.DatabaseName),
192192
sql.EscapeName(this.migrationContext.GetGhostTableName()),
193-
this.migrationContext.AlterStatement,
193+
this.migrationContext.AlterStatementOptions,
194194
)
195195
this.migrationContext.Log.Infof("Altering ghost table %s.%s",
196196
sql.EscapeName(this.migrationContext.DatabaseName),

go/sql/parser.go

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ type AlterTableParser struct {
3333
droppedColumns map[string]bool
3434
isRenameTable bool
3535

36-
alterTokens []string
36+
alterStatementOptions string
37+
alterTokens []string
3738

3839
explicitSchema string
3940
explicitTable string
@@ -120,22 +121,23 @@ func (this *AlterTableParser) parseAlterToken(alterToken string) (err error) {
120121

121122
func (this *AlterTableParser) ParseAlterStatement(alterStatement string) (err error) {
122123

124+
this.alterStatementOptions = alterStatement
123125
for _, alterTableRegexp := range alterTableExplicitSchemaTableRegexps {
124-
if submatch := alterTableRegexp.FindStringSubmatch(alterStatement); len(submatch) > 0 {
126+
if submatch := alterTableRegexp.FindStringSubmatch(this.alterStatementOptions); len(submatch) > 0 {
125127
this.explicitSchema = submatch[1]
126128
this.explicitTable = submatch[2]
127-
alterStatement = submatch[3]
129+
this.alterStatementOptions = submatch[3]
128130
break
129131
}
130132
}
131133
for _, alterTableRegexp := range alterTableExplicitTableRegexps {
132-
if submatch := alterTableRegexp.FindStringSubmatch(alterStatement); len(submatch) > 0 {
134+
if submatch := alterTableRegexp.FindStringSubmatch(this.alterStatementOptions); len(submatch) > 0 {
133135
this.explicitTable = submatch[1]
134-
alterStatement = submatch[2]
136+
this.alterStatementOptions = submatch[2]
135137
break
136138
}
137139
}
138-
alterTokens, _ := this.tokenizeAlterStatement(alterStatement)
140+
alterTokens, _ := this.tokenizeAlterStatement(this.alterStatementOptions)
139141
for _, alterToken := range alterTokens {
140142
alterToken = this.sanitizeQuotesFromAlterStatement(alterToken)
141143
this.parseAlterToken(alterToken)
@@ -180,3 +182,7 @@ func (this *AlterTableParser) GetExplicitTable() string {
180182
func (this *AlterTableParser) HasExplicitTable() bool {
181183
return this.GetExplicitTable() != ""
182184
}
185+
186+
func (this *AlterTableParser) GetAlterStatementOptions() string {
187+
return this.alterStatementOptions
188+
}

0 commit comments

Comments
 (0)