#!/usr/bin/php EOF ) { $fields=$ret->fields; if ( $first === true ) { $first = false; if ( ($fields["Key_name"] == "PRIMARY") && ($fields["Column_name"] == "service_id") ) { $already_converted = true; break; } } $ret->MoveNext(); } $ret->Close(); /* remove unsued fields that maybe still exists */ $sql = "ALTER TABLE $db.$table DROP COLUMN hw_a;"; $ret = do_query($sql, $db); $sql = "ALTER TABLE $db.$table DROP COLUMN hw_t;"; $ret = do_query($sql, $db); $sql = "ALTER TABLE $db.$table DROP COLUMN hw;"; $ret = do_query($sql, $db); $sql = "ALTER TABLE $db.$table DROP COLUMN hw_dev;"; $ret = do_query($sql, $db); $sql = "ALTER TABLE $db.$table DROP COLUMN last_hw;"; $ret = do_query($sql, $db); $sql = "ALTER TABLE $db.$table DROP COLUMN last_hw_dev;"; $ret = do_query($sql, $db); if ($already_converted === true) { print "Skipping $db.$table, already converted\n"; continue; } $sql = "alter table $db.$table drop index service_perf_1_idx;"; $ret = do_query($sql, $db); $sql = "alter table $db.$table drop primary key;"; $ret = do_query($sql, $db); } $sql = "ALTER TABLE $db.$table ENGINE = TokuDB compression='tokudb_snappy';"; } print "$sql ..."; $ret = do_query($sql, $db); $ret->Close(); /* Add new primary key */ if ($db == "opperf") { /* create new primary key */ $sql = "alter table $db.$table add primary key (service_id, metric_id, entry_time);"; $ret = do_query($sql, $db); } $timeelapsed = time() - $timeelapsed; print $timeelapsed."s done\n"; } } print "Migration Done\n"; exit(0); /* returns the size of the table in MB */ function check_table_engine($table_name, $dbname) { $ret = false; $tables_exists=check_table_exists($table_name, $dbname); if ($tables_exists===FALSE) return $ret; $query="SELECT ENGINE as engine FROM information_schema.TABLES WHERE table_schema = '$dbname' and table_name = '$table_name';"; $result = do_query($query,$dbname,OPDB_FETCH_OBJ); if ($result->RecordCount() > 0) { $obj=$result->fields; $ret = $obj->engine; } return($ret); } function check_table_exists($table_name, $dbname) { $query="show tables;"; $result = do_query($query,$dbname); $tables = array(); while( !$result->EOF ) { $tables[]=array_shift($result->fields); $result->MoveNext(); } $result->Close(); $found=array_search($table_name, $tables); return($found); } /* Get all tables from a DB */ function get_all_table_names_db($dbname) { $query="show tables;"; $result = do_query($query,$dbname); $tables = array(); while( !$result->EOF ) { $tables[]=array_shift($result->fields); $result->MoveNext(); } $result->Close(); return($tables); } /* Get all tables from a DB */ function get_all_databases() { $query="show databases;"; $result = do_query($query,"mysql"); $tables = array(); while( !$result->EOF ) { $tables[]=array_shift($result->fields); $result->MoveNext(); } $result->Close(); return($tables); } ?>