Update schema.php
This commit is contained in:
parent
8ea053e3e0
commit
3e92c7ce2b
|
|
@ -17,7 +17,7 @@
|
|||
|
||||
The Initial Developer of the Original Code is
|
||||
Mark J Crane <markjcrane@fusionpbx.com>
|
||||
Copyright (C) 2013 - 2016
|
||||
Copyright (C) 2013 - 2019
|
||||
All Rights Reserved.
|
||||
|
||||
Contributor(s):
|
||||
|
|
@ -634,30 +634,35 @@ if (!class_exists('schema')) {
|
|||
//get the field name
|
||||
if (is_array($field['name'])) {
|
||||
$field_name = $field['name']['text'];
|
||||
if (!$this->db_column_exists ($db_type, $db_name, $table_name, $field_name)) {
|
||||
$field['exists'] == "false";
|
||||
}
|
||||
}
|
||||
else {
|
||||
$field_name = $field['name'];
|
||||
}
|
||||
//find missing fields and add them
|
||||
if ($field['exists'] == "false") {
|
||||
$sql_update .= "ALTER TABLE ".$table_name." ADD ".$field_name." ".$field_type.";\n";
|
||||
}
|
||||
//rename fields where the name has changed
|
||||
if (is_array($field['name'])) {
|
||||
if ($this->db_column_exists ($db_type, $db_name, $table_name, $field['name']['deprecated'])) {
|
||||
if ($db_type == "pgsql") {
|
||||
$sql_update .= "ALTER TABLE ".$table_name." RENAME COLUMN ".$field['name']['deprecated']." to ".$field['name']['text'].";\n";
|
||||
}
|
||||
if ($db_type == "mysql") {
|
||||
$field_type = str_replace("AUTO_INCREMENT PRIMARY KEY", "", $field_type);
|
||||
$sql_update .= "ALTER TABLE ".$table_name." CHANGE ".$field['name']['deprecated']." ".$field['name']['text']." ".$field_type.";\n";
|
||||
}
|
||||
if ($db_type == "sqlite") {
|
||||
//a change has been made to the field name
|
||||
$apps[$x]['db'][$y]['rebuild'] = 'true';
|
||||
}
|
||||
|
||||
//add or rename fields
|
||||
if ($this->db_column_exists ($db_type, $db_name, $table_name, $field['name']['deprecated'])) {
|
||||
if ($db_type == "pgsql") {
|
||||
$sql_update .= "ALTER TABLE ".$table_name." RENAME COLUMN ".$field['name']['deprecated']." to ".$field['name']['text'].";\n";
|
||||
}
|
||||
if ($db_type == "mysql") {
|
||||
$field_type = str_replace("AUTO_INCREMENT PRIMARY KEY", "", $field_type);
|
||||
$sql_update .= "ALTER TABLE ".$table_name." CHANGE ".$field['name']['deprecated']." ".$field['name']['text']." ".$field_type.";\n";
|
||||
}
|
||||
if ($db_type == "sqlite") {
|
||||
//a change has been made to the field name
|
||||
$apps[$x]['db'][$y]['rebuild'] = 'true';
|
||||
}
|
||||
}
|
||||
else {
|
||||
//find missing fields and add them
|
||||
if ($field['exists'] == "false") {
|
||||
$sql_update .= "ALTER TABLE ".$table_name." ADD ".$field_name." ".$field_type.";\n";
|
||||
}
|
||||
}
|
||||
|
||||
//change the data type if it has been changed
|
||||
//if the data type in the app db array is different than the type in the database then change the data type
|
||||
if ($upgrade_data_types) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue