Skip to content

db:import should not recreate/truncate all tables by default #42

@HenningerIBC

Description

@HenningerIBC

During the db:import task, all tables are dropped and recreated unless the commandline option importTaskDoNotDropAllTablesBeforeImport is set:

if (empty($optionUtility->getOption('importTaskDoNotDropAllTablesBeforeImport'))) {
runLocally(sprintf(
'%s --defaults-file=%s %s %s --add-drop-table --no-data | ' .
'grep -e \'^DROP \| FOREIGN_KEY_CHECKS\' | %s --defaults-file=%s %s -D%s',
get('local/bin/mysqldump'),
escapeshellarg($tmpMyCnfFile),
DatabaseUtility::getSslCliOptions($databaseConfig),
escapeshellarg($databaseConfig['dbname']),
get('local/bin/mysql'),
escapeshellarg($tmpMyCnfFile),
DatabaseUtility::getSslCliOptions($databaseConfig),
escapeshellarg($databaseConfig['dbname'])
));
}

I do not understand why this is done or necessary since the default configuration for both db_export_mysqldump_options_structure and db_export_mysqldump_options_data already do add a DROP TABLE IF EXISTS. So if both structure.sql and data.sql exists, a db:import call essentially does the following:

  1. Export all table structures and then import it, thus dropping and the creating the tables again.
  2. strucutre.sql drops each table and then recreates it
  3. data.sql drops each table, recreates it and imports its data

So overall, during an import the tables are destroyed and recreated three times. I suggest removing the first subtask (export, drop and recreate) entirely, including the importTaskDoNotDropAllTablesBeforeImport flag, as it also does not follow the ignore_tables_out option. This means all tables are essentially truncated, even those defined by ignore_tables_out.

Additionally, the defaults for for db_export_mysqldump_options_data should include --no-create-info, as it really should only contain the data and not the structure, thus not trigger another drop&create table.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions