Skip to content

Commit

Permalink
Create indexes with table creation if "IF NOT EXISTS" is on
Browse files Browse the repository at this point in the history
- change default of IF NOT EXISTS option in export
- Add warning for efficiency with IF NOT EXISTS option

Signed-off-by: Nisarg Jhaveri <nisargjhaveri@gmail.com>
  • Loading branch information
nisargjhaveri committed Aug 21, 2015
1 parent 932471e commit b2e8e46
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 11 deletions.
4 changes: 1 addition & 3 deletions libraries/config.default.php
Expand Up @@ -1965,7 +1965,7 @@
* of VIEWs and the stand-in table
* @global boolean $cfg['Export']['sql_if_not_exists']
*/
$cfg['Export']['sql_if_not_exists'] = true;
$cfg['Export']['sql_if_not_exists'] = false;

/**
*
Expand Down Expand Up @@ -3142,5 +3142,3 @@
'internal' => 50500,
'human' => '5.5.0'
);


3 changes: 1 addition & 2 deletions libraries/config/messages.inc.php
Expand Up @@ -203,7 +203,7 @@
$strConfigExport_sql_create_trigger_name
= sprintf(__('Add %s'), 'CREATE TRIGGER');
$strConfigExport_sql_hex_for_binary_name = __('Use hexadecimal for BINARY & BLOB');
$strConfigExport_sql_if_not_exists_name = sprintf(__('Add %s'), 'IF NOT EXISTS');
$strConfigExport_sql_if_not_exists_name = __('Add IF NOT EXISTS (less efficient)');
$strConfigExport_sql_ignore_name = __('Use ignore inserts');
$strConfigExport_sql_include_comments_name = __('Comments');
$strConfigExport_sql_insert_syntax_name = __('Syntax to use when inserting data');
Expand Down Expand Up @@ -998,4 +998,3 @@
. 'configuration storage tables automatically.'
);
$strConfigZeroConf_name = __('Enable Zero Configuration mode');

18 changes: 12 additions & 6 deletions libraries/plugins/export/ExportSql.class.php
Expand Up @@ -274,7 +274,7 @@ protected function setProperties()

$leaf = new BoolPropertyItem();
$leaf->setName('if_not_exists');
$leaf->setText('<code>IF NOT EXISTS</code>');
$leaf->setText('<code>IF NOT EXISTS</code> ' . __('(less efficient)'));
$subgroup_create_table->addProperty($leaf);

$leaf = new BoolPropertyItem();
Expand Down Expand Up @@ -1607,23 +1607,27 @@ public function getTableDef(
// constraints).
if ($field->key->type === 'FULLTEXT KEY') {
$indexes_fulltext[] = $field->build($field);
} else {
unset($statement->fields[$key]);
} else if (empty($GLOBALS['sql_if_not_exists'])) {
$indexes[] = $field->build($field);
unset($statement->fields[$key]);
}
unset($statement->fields[$key]);
}

// Creating the parts that drop foreign keys.
if (!empty($field->key)) {
if ($field->key->type === 'FOREIGN KEY') {
$dropped[] = 'FOREIGN KEY ' . SqlParser\Context::escape($field->name);
unset($statement->fields[$key]);
}
unset($statement->fields[$key]);
}

// Dropping AUTO_INCREMENT.
if (!empty($field->options)) {
if ($field->options->has('AUTO_INCREMENT')) {
if ($field->options->has('AUTO_INCREMENT')
&& empty($GLOBALS['sql_if_not_exists'])
) {

$auto_increment[] = $field::build($field);
$field->options->remove('AUTO_INCREMENT');
}
Expand Down Expand Up @@ -1712,7 +1716,9 @@ public function getTableDef(

// Removing the `AUTO_INCREMENT` attribute from the `CREATE TABLE`
// too.
if (!empty($statement->entityOptions)) {
if (!empty($statement->entityOptions)
&& empty($GLOBALS['sql_if_not_exists'])
) {
$statement->entityOptions->remove('AUTO_INCREMENT');
}

Expand Down

0 comments on commit b2e8e46

Please sign in to comment.