Merge pull request #81 from github/noop-show-create-table

a noop operation dumps SHOW CREATE TABLE
This commit is contained in:
Shlomi Noach 2016-06-22 12:39:38 +02:00 committed by GitHub
commit b4a2a3bfbe
2 changed files with 18 additions and 0 deletions

View File

@ -516,6 +516,14 @@ func (this *Inspector) getSharedColumns(originalColumns, ghostColumns *sql.Colum
return sql.NewColumnList(sharedColumnNames), sql.NewColumnList(mappedSharedColumnNames) 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 // readChangelogState reads changelog hints
func (this *Inspector) readChangelogState() (map[string]string, error) { func (this *Inspector) readChangelogState() (map[string]string, error) {
query := fmt.Sprintf(` query := fmt.Sprintf(`

View File

@ -1173,6 +1173,16 @@ func (this *Migrator) executeWriteFuncs() error {
// finalCleanup takes actions at very end of migration, dropping tables etc. // finalCleanup takes actions at very end of migration, dropping tables etc.
func (this *Migrator) finalCleanup() error { func (this *Migrator) finalCleanup() error {
atomic.StoreInt64(&this.cleanupImminentFlag, 1) 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 { if err := this.retryOperation(this.applier.DropChangelogTable); err != nil {
return err return err
} }