More work on the sqlite upgrade schema bug.
This commit is contained in:
parent
0c1b89a716
commit
f1e9029cdf
|
|
@ -232,15 +232,23 @@ function db_insert_into ($apps, $db_type, $table) {
|
||||||
if (is_array($field['name'])) {
|
if (is_array($field['name'])) {
|
||||||
if ($field['exists'] == "false") {
|
if ($field['exists'] == "false") {
|
||||||
if (is_array($field['name']['deprecated'])) {
|
if (is_array($field['name']['deprecated'])) {
|
||||||
|
$found = false;
|
||||||
foreach ($field['name']['deprecated'] as $row) {
|
foreach ($field['name']['deprecated'] as $row) {
|
||||||
if (db_column_exists ($db, $db_type, $db_name, $table, $row)) {
|
if (db_column_exists ($db, $db_type, $db_name, 'tmp_'.$table, $row)) {
|
||||||
$sql .= $row;
|
$sql .= $row;
|
||||||
|
$found = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (!$found) { $sql .= "''"; }
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
$sql .= $field['name']['deprecated'];
|
if (db_column_exists ($db, $db_type, $db_name, 'tmp_'.$table, $field['name']['deprecated'])) {
|
||||||
|
$sql .= $field['name']['deprecated'];
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$sql .= "''";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
@ -375,12 +383,7 @@ function db_upgrade_schema ($db, $db_type, $db_name, $display_results) {
|
||||||
//skip this row
|
//skip this row
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if (is_array($field['name'])) {
|
if (!is_array($field['name'])) {
|
||||||
if ($field['exists'] == "false" && !db_column_exists ($db, $db_type, $db_name, $table_name, $field['name']['deprecated'])) {
|
|
||||||
$sql_update .= "ALTER TABLE ".$table_name." ADD ".$field['name']['text']." ".$field_type.";\n";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
if ($field['exists'] == "false") {
|
if ($field['exists'] == "false") {
|
||||||
$sql_update .= "ALTER TABLE ".$table_name." ADD ".$field['name']." ".$field_type.";\n";
|
$sql_update .= "ALTER TABLE ".$table_name." ADD ".$field['name']." ".$field_type.";\n";
|
||||||
}
|
}
|
||||||
|
|
@ -461,6 +464,8 @@ function db_upgrade_schema ($db, $db_type, $db_name, $display_results) {
|
||||||
$table_name = $row['table'];
|
$table_name = $row['table'];
|
||||||
if ($row['rebuild'] == "true") {
|
if ($row['rebuild'] == "true") {
|
||||||
if ($db_type == "sqlite") {
|
if ($db_type == "sqlite") {
|
||||||
|
//start the transaction
|
||||||
|
$sql_update .= "BEGIN TRANSACTION;\n";
|
||||||
//rename the table
|
//rename the table
|
||||||
$sql_update .= "ALTER TABLE ".$table_name." RENAME TO tmp_".$table_name.";\n";
|
$sql_update .= "ALTER TABLE ".$table_name." RENAME TO tmp_".$table_name.";\n";
|
||||||
//create the table
|
//create the table
|
||||||
|
|
@ -469,6 +474,8 @@ function db_upgrade_schema ($db, $db_type, $db_name, $display_results) {
|
||||||
$sql_update .= db_insert_into($apps, $db_type, $table_name);
|
$sql_update .= db_insert_into($apps, $db_type, $table_name);
|
||||||
//drop the old table
|
//drop the old table
|
||||||
$sql_update .= "DROP TABLE tmp_".$table_name.";\n";
|
$sql_update .= "DROP TABLE tmp_".$table_name.";\n";
|
||||||
|
//commit the transaction
|
||||||
|
$sql_update .= "COMMIT;\n";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue