sanity checks for resurrection

This commit is contained in:
Shlomi Noach 2016-12-21 09:23:00 +02:00
parent c72851e1f6
commit 171cad2a98
2 changed files with 19 additions and 4 deletions

View File

@ -180,11 +180,13 @@ func main() {
if *cliMasterPassword != "" && migrationContext.AssumeMasterHostname == "" {
log.Fatalf("--master-password requires --assume-master-host")
}
if migrationContext.InitiallyDropGhostTable && migrationContext.Resurrect {
log.Fatalf("--initially-drop-ghost-table and --resurrect are mutually exclusive")
if migrationContext.Resurrect && migrationContext.InitiallyDropGhostTable {
migrationContext.InitiallyDropGhostTable = false
log.Warningf("--resurrect given, implicitly disabling --initially-drop-ghost-table")
}
if migrationContext.InitiallyDropOldTable && migrationContext.Resurrect {
log.Fatalf("--initially-drop-old-table and --resurrect are mutually exclusive")
if migrationContext.Resurrect && migrationContext.InitiallyDropOldTable {
migrationContext.InitiallyDropOldTable = false
log.Warningf("--resurrect given, implicitly disabling --initially-drop-old-table")
}
switch *cutOver {

View File

@ -128,6 +128,19 @@ func (this *Applier) tableExists(tableName string) (tableFound bool) {
// ValidateOrDropExistingTables verifies ghost and changelog tables do not exist,
// or attempts to drop them if instructed to.
func (this *Applier) ValidateOrDropExistingTables() error {
if this.migrationContext.Resurrect {
ghostTableExists := this.tableExists(this.migrationContext.GetGhostTableName())
if !ghostTableExists {
return fmt.Errorf("--ressurect requested, but ghost table %s doesn't exist. Panicking.", this.migrationContext.GetGhostTableName())
}
changelogTableExists := this.tableExists(this.migrationContext.GetChangelogTableName())
if !changelogTableExists {
return fmt.Errorf("--ressurect requested, but changelog table %s doesn't exist. Panicking.", this.migrationContext.GetChangelogTableName())
}
return nil
}
// Normal mode (no resurrection)
if this.migrationContext.InitiallyDropGhostTable {
if err := this.DropGhostTable(); err != nil {
return err