From e0de69b0289678743fcc4428267fde2dcc481e64 Mon Sep 17 00:00:00 2001 From: Shlomi Noach Date: Wed, 22 Jun 2016 12:39:13 +0200 Subject: [PATCH] a noop operation dumps SHOW CREATE TABLE --- go/logic/inspect.go | 8 ++++++++ go/logic/migrator.go | 10 ++++++++++ 2 files changed, 18 insertions(+) diff --git a/go/logic/inspect.go b/go/logic/inspect.go index 4edafcc..81ee528 100644 --- a/go/logic/inspect.go +++ b/go/logic/inspect.go @@ -516,6 +516,14 @@ func (this *Inspector) getSharedColumns(originalColumns, ghostColumns *sql.Colum return sql.NewColumnList(sharedColumnNames), sql.NewColumnList(mappedSharedColumnNames) } +// showCreateTable returns the `show create table` statement for given table +func (this *Inspector) showCreateTable(tableName string) (createTableStatement string, err error) { + var dummy string + query := fmt.Sprintf(`show /* gh-ost */ create table %s.%s`, sql.EscapeName(this.migrationContext.DatabaseName), sql.EscapeName(tableName)) + err = this.db.QueryRow(query).Scan(&dummy, &createTableStatement) + return createTableStatement, err +} + // readChangelogState reads changelog hints func (this *Inspector) readChangelogState() (map[string]string, error) { query := fmt.Sprintf(` diff --git a/go/logic/migrator.go b/go/logic/migrator.go index 1c103f0..dbfdbea 100644 --- a/go/logic/migrator.go +++ b/go/logic/migrator.go @@ -1173,6 +1173,16 @@ func (this *Migrator) executeWriteFuncs() error { // finalCleanup takes actions at very end of migration, dropping tables etc. func (this *Migrator) finalCleanup() error { atomic.StoreInt64(&this.cleanupImminentFlag, 1) + + if this.migrationContext.Noop { + if createTableStatement, err := this.inspector.showCreateTable(this.migrationContext.GetGhostTableName()); err == nil { + log.Infof("New table structure follows") + fmt.Println(createTableStatement) + } else { + log.Errore(err) + } + } + if err := this.retryOperation(this.applier.DropChangelogTable); err != nil { return err }