diff --git a/scripts/zmupdate.pl.in b/scripts/zmupdate.pl.in index cbf071994..75a0a83f3 100644 --- a/scripts/zmupdate.pl.in +++ b/scripts/zmupdate.pl.in @@ -454,6 +454,35 @@ if ( $version ) } } + sub toInnoDB + { + my $dbh = shift; + my $sql = "SELECT table_name FROM INFORMATION_SCHEMA.TABLES WHERE table_schema='zm' AND engine = 'MyISAM'"; + my $sth = $dbh->prepare_cached( $sql ) or die( "Can't prepare '$sql': ".$dbh->errstr() ); + my $res = $sth->execute() or die( "Can't execute: ".$sth->errstr() ); + + my @dbTables; + while( my $dbTable = $sth->fetchrow() ) + { + push( @dbTables, $dbTable ); + } + $sth->finish(); + + if (@dbTables) + { + print "\nConverting MyISAM tables to InnoDB. Please wait.\n"; + foreach (@dbTables) + { + my $sql = "ALTER TABLE $_ ENGINE = InnoDB"; + my $sth = $dbh->prepare_cached( $sql ) or die( "Can't prepare '$sql': ".$dbh->errstr() ); + my $res = $sth->execute() or die( "Can't execute: ".$sth->errstr() ); + } + $sth->finish(); + } else { + print "\nNo MyISAM tables found. Skipping...\n"; + } + } + print( "\nUpgrading database to version ".ZM_VERSION."\n" ); # Update config first of all @@ -984,6 +1013,16 @@ if ( $version ) $dbh->do(q{alter table Monitors add column `Deinterlacing` INT unsigned NOT NULL default '0' after `Orientation`;}); } # end if $sth->finish(); + + print( "\nPrevious versions of ZoneMinder used the MyISAM database engine.\nHowever, the recommended database engine is InnoDB.\n"); + print( "\nHint: InnoDB tables are much less likely to be corrupted during an unclean shutdown.\n\nPress 'y' to convert your tables to InnoDB or 'n' to skip : "); + my $response = ; + chomp( $response ); + if ( $response =~ /^[yY]$/ ) + { + toInnoDB($dbh); + } + $cascade = !undef; } if ( $cascade )