Merge pull request #3818 from annando/structure-temp

DBStructure: Better handling of temp table
This commit is contained in:
Tobias Diekershoff 2017-10-23 11:47:46 +02:00 committed by GitHub
commit d39b0584f0

View file

@ -412,17 +412,18 @@ function update_structure($verbose, $action, $tables=null, $definition=null) {
if ($verbose) { if ($verbose) {
// Ensure index conversion to unique removes duplicates // Ensure index conversion to unique removes duplicates
if ($is_unique) { if ($is_unique && ($temp_name != $name)) {
if ($ignore != "") { if ($ignore != "") {
echo "SET session old_alter_table=1;\n"; echo "SET session old_alter_table=1;\n";
} else { } else {
echo "DROP TABLE IF EXISTS `".$temp_name."`;\n";
echo "CREATE TABLE `".$temp_name."` LIKE `".$name."`;\n"; echo "CREATE TABLE `".$temp_name."` LIKE `".$name."`;\n";
} }
} }
echo $sql3."\n"; echo $sql3."\n";
if ($is_unique) { if ($is_unique && ($temp_name != $name)) {
if ($ignore != "") { if ($ignore != "") {
echo "SET session old_alter_table=0;\n"; echo "SET session old_alter_table=0;\n";
} else { } else {
@ -437,10 +438,16 @@ function update_structure($verbose, $action, $tables=null, $definition=null) {
Config::set('system', 'maintenance_reason', sprintf(t('%s: updating %s table.'), dbm::date().' '.date('e'), $name)); Config::set('system', 'maintenance_reason', sprintf(t('%s: updating %s table.'), dbm::date().' '.date('e'), $name));
// Ensure index conversion to unique removes duplicates // Ensure index conversion to unique removes duplicates
if ($is_unique) { if ($is_unique && ($temp_name != $name)) {
if ($ignore != "") { if ($ignore != "") {
dba::e("SET session old_alter_table=1;"); dba::e("SET session old_alter_table=1;");
} else { } else {
dba::e("DROP TABLE IF EXISTS `".$temp_name."`;");
if (!dbm::is_result($r)) {
$errors .= print_update_error($sql3);
return $errors;
}
$r = dba::e("CREATE TABLE `".$temp_name."` LIKE `".$name."`;"); $r = dba::e("CREATE TABLE `".$temp_name."` LIKE `".$name."`;");
if (!dbm::is_result($r)) { if (!dbm::is_result($r)) {
$errors .= print_update_error($sql3); $errors .= print_update_error($sql3);
@ -453,7 +460,7 @@ function update_structure($verbose, $action, $tables=null, $definition=null) {
if (!dbm::is_result($r)) { if (!dbm::is_result($r)) {
$errors .= print_update_error($sql3); $errors .= print_update_error($sql3);
} }
if ($is_unique) { if ($is_unique && ($temp_name != $name)) {
if ($ignore != "") { if ($ignore != "") {
dba::e("SET session old_alter_table=0;"); dba::e("SET session old_alter_table=0;");
} else { } else {