Skip to content

Commit 87a36d0

Browse files
committed
--alter is unneccessary
1 parent 0e7de97 commit 87a36d0

File tree

3 files changed

+38
-16
lines changed

3 files changed

+38
-16
lines changed

go/cmd/gh-ost/main.go

Lines changed: 32 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -208,12 +208,35 @@ func main() {
208208

209209
migrationContext.SetConnectionCharset(*charset)
210210

211-
if migrationContext.AlterStatement == "" {
211+
if migrationContext.AlterStatement == "" && !migrationContext.Revert {
212212
log.Fatal("--alter must be provided and statement must not be empty")
213213
}
214214
parser := sql.NewParserFromAlterStatement(migrationContext.AlterStatement)
215215
migrationContext.AlterStatementOptions = parser.GetAlterStatementOptions()
216216

217+
if migrationContext.Revert {
218+
if migrationContext.Resume {
219+
log.Fatal("--revert cannot be used with --resume")
220+
}
221+
if migrationContext.OldTableName == "" {
222+
migrationContext.Log.Fatalf("--revert must be called with --old-table")
223+
}
224+
225+
// options irrelevant to revert mode
226+
if migrationContext.AlterStatement != "" {
227+
log.Warning("--alter was provided with --revert, it will be ignored")
228+
}
229+
if migrationContext.AttemptInstantDDL {
230+
log.Warning("--attempt-instant-ddl was provided with --revert, it will be ignored")
231+
}
232+
if migrationContext.IncludeTriggers {
233+
log.Warning("--include-triggers was provided with --revert, it will be ignored")
234+
}
235+
if migrationContext.DiscardForeignKeys {
236+
log.Warning("--discard-foreign-keys was provided with --revert, it will be ignored")
237+
}
238+
}
239+
217240
if migrationContext.DatabaseName == "" {
218241
if parser.HasExplicitSchema() {
219242
migrationContext.DatabaseName = parser.GetExplicitSchema()
@@ -293,10 +316,6 @@ func main() {
293316
migrationContext.Log.Fatalf("--checkpoint-seconds should be >=10")
294317
}
295318

296-
if migrationContext.Revert && migrationContext.OldTableName == "" {
297-
migrationContext.Log.Fatalf("--revert must be called with --old-table")
298-
}
299-
300319
switch *cutOver {
301320
case "atomic", "default", "":
302321
migrationContext.CutOverType = base.CutOverAtomic
@@ -353,15 +372,16 @@ func main() {
353372
acceptSignals(migrationContext)
354373

355374
migrator := logic.NewMigrator(migrationContext, AppVersion)
375+
var err error
356376
if migrationContext.Revert {
357-
if err := migrator.Revert(); err != nil {
358-
migrationContext.Log.Fatale(err)
359-
}
377+
err = migrator.Revert()
360378
} else {
361-
if err := migrator.Migrate(); err != nil {
362-
migrator.ExecOnFailureHook()
363-
migrationContext.Log.Fatale(err)
364-
}
379+
err = migrator.Migrate()
380+
}
381+
382+
if err != nil {
383+
migrator.ExecOnFailureHook()
384+
migrationContext.Log.Fatale(err)
365385
}
366386
fmt.Fprintln(os.Stdout, "# Done")
367387
}

go/logic/migrator.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -541,9 +541,6 @@ func (this *Migrator) Revert() error {
541541
if err := this.hooksExecutor.onStartup(); err != nil {
542542
return err
543543
}
544-
if err := this.parser.ParseAlterStatement(this.migrationContext.AlterStatement); err != nil {
545-
return err
546-
}
547544
if err := this.validateAlterStatement(); err != nil {
548545
return err
549546
}
@@ -591,7 +588,10 @@ func (this *Migrator) Revert() error {
591588
}
592589

593590
this.initiateThrottler()
591+
go this.initiateStatus()
594592
go this.executeDMLWriteFuncs()
593+
594+
this.printStatus(ForcePrintStatusRule)
595595
var retrier func(func() error, ...bool) error
596596
if this.migrationContext.CutOverExponentialBackoff {
597597
retrier = this.retryOperationWithExponentialBackoff
@@ -605,6 +605,9 @@ func (this *Migrator) Revert() error {
605605
return err
606606
}
607607
atomic.StoreInt64(&this.migrationContext.CutOverCompleteFlag, 1)
608+
if err := this.finalCleanup(); err != nil {
609+
return nil
610+
}
608611
if err := this.hooksExecutor.onSuccess(); err != nil {
609612
return err
610613
}

go/logic/migrator_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -725,7 +725,6 @@ func (suite *MigratorTestSuite) TestRevert() {
725725
migrationContext.ApplierConnectionConfig = connectionConfig
726726
migrationContext.InspectorConnectionConfig = connectionConfig
727727
migrationContext.SetConnectionConfig("innodb")
728-
migrationContext.AlterStatement = "DROP INDEX idx1"
729728
migrationContext.DropServeSocket = true
730729
migrationContext.UseGTIDs = true
731730
migrationContext.Revert = true

0 commit comments

Comments
 (0)