mirror of
https://github.com/OpenXE-org/OpenXE.git
synced 2024-12-25 06:00:28 +01:00
bugfix mustal use correct syntax for BTREE and HASH key types
This commit is contained in:
parent
6242024451
commit
623b041a5f
@ -365,6 +365,9 @@ function upgrade_main(string $directory,bool $verbose, bool $check_git, bool $do
|
||||
foreach ($compare_differences as $compare_difference) {
|
||||
$comma = "";
|
||||
foreach ($compare_difference as $key => $value) {
|
||||
if (is_array($value)) {
|
||||
$value = implode(',',$value);
|
||||
}
|
||||
echo_out($comma."$key => [$value]");
|
||||
$comma = ", ";
|
||||
}
|
||||
|
36
vendor/mustal/mustal_mysql_upgrade_tool.php
vendored
36
vendor/mustal/mustal_mysql_upgrade_tool.php
vendored
@ -67,6 +67,7 @@ $mustal_replacers = [
|
||||
['on update current_timestamp','on update current_timestamp()']
|
||||
];
|
||||
|
||||
|
||||
// Load all db_def from a DB connection into a db_def array
|
||||
function mustal_load_tables_from_db(string $host, string $schema, string $user, string $passwd, array $replacers) : array {
|
||||
|
||||
@ -358,8 +359,6 @@ function mustal_compare_table_array(array $nominal, string $nominal_name, array
|
||||
$compare_difference['table'] = $database_table['name'];
|
||||
$compare_difference['key'] = $sql_index['Key_name'];
|
||||
$compare_difference['property'] = $key;
|
||||
/* $compare_difference[$nominal_name] = implode(',',$value);
|
||||
$compare_difference[$actual_name] = implode(',',$found_sql_index[$key]);*/
|
||||
$compare_difference[$nominal_name] = $value;
|
||||
$compare_difference[$actual_name] = $found_sql_index[$key];
|
||||
$compare_differences[] = $compare_difference;
|
||||
@ -585,14 +584,7 @@ function mustal_calculate_db_upgrade(array $compare_def, array $db_def, array &$
|
||||
if ($key['Key_name'] == 'PRIMARY') {
|
||||
$keystring = "PRIMARY KEY ";
|
||||
} else {
|
||||
|
||||
// if(array_key_exists('Index_type', $key)) {
|
||||
// $index_type = $key['Index_type'];
|
||||
// } else {
|
||||
$index_type = "";
|
||||
// }
|
||||
|
||||
$keystring = $index_type." ".$key['Non_unique']." KEY `".$key['Key_name']."` ";
|
||||
$keystring = mustal_key_type(" ".$key['Non_unique']." KEY `".$key['Key_name']."` ",$key['Index_type']);
|
||||
}
|
||||
$sql .= $comma.$keystring."(`".implode("`,`",$key['columns'])."`) ";
|
||||
}
|
||||
@ -675,10 +667,7 @@ function mustal_calculate_db_upgrade(array $compare_def, array $db_def, array &$
|
||||
|
||||
if ($key_key !== false) {
|
||||
$key = $table['keys'][$key_key];
|
||||
|
||||
$sql = "ALTER TABLE `$table_name` ADD ".$key['Non_unique']." KEY `".$key_name."` ";
|
||||
$sql .= "(`".implode("`,`",$key['columns'])."`)";
|
||||
$sql .= ";";
|
||||
$sql = "ALTER TABLE `$table_name` ADD ".mustal_key_type(" ".$key['Non_unique']." KEY `".$key['Key_name']."` "."(`".implode("`,`",$key['columns'])."`)",$key['Index_type']).";";
|
||||
$upgrade_sql[] = $sql;
|
||||
}
|
||||
else {
|
||||
@ -706,7 +695,7 @@ function mustal_calculate_db_upgrade(array $compare_def, array $db_def, array &$
|
||||
$sql = "ALTER TABLE `$table_name` DROP KEY `".$key_name."`;";
|
||||
$upgrade_sql[] = $sql;
|
||||
|
||||
$sql = "ALTER TABLE `$table_name` ADD ".$key['Non_unique']." KEY `".$key_name."` ";
|
||||
$sql = "ALTER TABLE `$table_name` ADD ".mustal_key_type(" ".$key['Non_unique']." KEY `".$key['Key_name']."` ",$key['Index_type']);
|
||||
$sql .= "(`".implode("`,`",$key['columns'])."`)";
|
||||
$sql .= ";";
|
||||
$upgrade_sql[] = $sql;
|
||||
@ -781,3 +770,20 @@ function mustal_is_string_type(string $type) {
|
||||
return(false);
|
||||
}
|
||||
|
||||
// create correct index type syntax
|
||||
function mustal_key_type(string $key_definition_string, string $key_type) {
|
||||
|
||||
// Key types with using syntax
|
||||
$mustal_key_types_using_mapping = [
|
||||
'BTREE',
|
||||
'HASH'
|
||||
];
|
||||
|
||||
if (in_array($key_type,$mustal_key_types_using_mapping)) {
|
||||
return ($key_definition_string." USING ".$key_type);
|
||||
} else {
|
||||
return ($key_type." ".$key_definition_string);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user