Problem/Motivation

The option on db-tools.php for importing a database is "import" but the option for exporting a database is "dump-database-d8-mysql". This is a little silly.

Proposed resolution

Deprecate 'dump*' command.
Rename the option for exporting a database "export".

Remaining tasks

Provide a patch.

User interface changes

The command for exporting a database would be "php db-tools.php export" instead of "php db-tools.php dump-database-d8-mysql".

API changes

n/a

Data model changes

n/a

Release notes snippet

The command for exporting a database would be "php db-tools.php export" instead of "php db-tools.php dump-database-d8-mysql", which matches the shortness of the "import" command.

Comments

DamienMcKenna created an issue. See original summary.

damienmckenna’s picture

Assigned: damienmckenna » Unassigned
Status: Active » Needs review
StatusFileSize
new5.37 KB

This provides a new "export" command and (attempts to) deprecate the old command.

mitthukumawat’s picture

I have tested the patch and now I can export the database using "Export" . Thanks for the patch.

damienmckenna’s picture

StatusFileSize
new5.54 KB
new1014 bytes

Thank you for the review.

This will hopefully fix the errors in the last patch.

paulocs’s picture

I'll work on it.

paulocs’s picture

StatusFileSize
new19.9 KB
new19.81 KB

Status: Needs review » Needs work

The last submitted patch, 6: 3213151-6.patch, failed testing. View results

neslee canil pinto’s picture

Status: Needs work » Needs review
StatusFileSize
new19.86 KB
new631 bytes

Status: Needs review » Needs work

The last submitted patch, 8: 3213151-8.patch, failed testing. View results

imalabya’s picture

Status: Needs work » Needs review
StatusFileSize
new20.69 KB
new852 bytes

Fixed failing tests.

longwave’s picture

+++ b/core/lib/Drupal/Core/Command/DbDumpCommand.php
@@ -39,8 +44,8 @@ class DbDumpCommand extends DbCommandBase {
+    $this->setName('export')

I don't think we should be renaming this command here, just adding the description?

paulocs’s picture

StatusFileSize
new1.42 KB
new19.62 KB

Addressing #11.

quietone’s picture

Status: Needs review » Needs work
+++ b/core/lib/Drupal/Core/Command/DbExportApplication.php
@@ -0,0 +1,43 @@
+    $default_commands[] = new DbDumpCommand();

DbDumpCommand is deprecated. Should be DbExportCommand.

+++ b/core/modules/system/tests/src/Kernel/Scripts/DbToolsApplicationTest.php
@@ -20,8 +20,8 @@ class DbToolsApplicationTest extends KernelTestBase {
-    $command = $application->find('dump');

The 'dump' option is undocumented but referred to on https://www.drupal.org/docs/drupal-apis/migrate-api/generating-database-.... Should the test of it be removed?

Also, DbExportCommand looks like a copy of DbdumpCommand, but it is missing this if block.

dhirendra.mishra’s picture

StatusFileSize
new559 bytes
new20 KB

I have solved the first point by comment in #12.

paulocs’s picture

Category: Feature request » Task
Status: Needs work » Needs review
StatusFileSize
new2.57 KB
new20.1 KB

Patch #14 changes the wrong file so fixing it.

Should the test of it be removed?

Should we only update the tests and the documentation and ensure that the export command exists?

I added the if block that was missing in the DbExportCommand (This was added after this issue was created. Good catch @quietone).

marcusvsouza’s picture

Status: Needs review » Reviewed & tested by the community

The patch in comment #15 works fine and correctly changes the command for export database.

The last submitted patch, 14: 3213151-14.patch, failed testing. View results

The last submitted patch, 14: 3213151-14.patch, failed testing. View results

quietone’s picture

Issue summary: View changes
Status: Reviewed & tested by the community » Needs work

I applied that patch and then used 'export' and 'dump' with a drupal 7 database. The output from the commands do not match which I expect them too. I don't think there is any reason that the legacy version needs to be maintained.

There have been changes to DbDumpCommand.php that need to be moved to DbExportCommand, #838992: Change the uid field from integer to serial by leveraging NO_AUTO_VALUE_ON_ZERO on MySQL. There are perhaps ways to change the patch to avoid the disruption here by changes to HEAD but I couldn't find any open issues related to db-tools. It is just unfortunate that there have been recent changes.

I still don't like that tests are being removed. How about we change DbDumpCommand to extend from DbExportCommand and similar for DbDumpApplication. This will simplify the code. Here is an idea for DbDumpCommand.

/**
 * Provides a command to dump the current database to a script.
 *
 * @deprecated in drupal:9.3.0 and is removed from drupal:10.0.0. Use
 *   \Drupal\Core\Command\DbExportCommand
 *
 * @see https://www.drupal.org/project/drupal/issues/3213151
 */
class DbDumpCommand extends DbExportCommand {

  /**
   * {@inheritdoc}
   */
  protected function configure() {
    $this->setName('dump-database-d8-mysql')
      ->setDescription('Deprecated, use "export" instead.')
      ->addOption('schema-only', NULL, InputOption::VALUE_OPTIONAL, 'A comma separated list of tables to only export the schema without data.', 'cache.*,sessions,watchdog');
    DbCommandBase::configure();
  }
  1. +++ b/core/lib/Drupal/Core/Command/DbDumpCommand.php
    @@ -23,6 +23,11 @@
    + * @deprecated in drupal:9.3.0 and is removed from drupal:10.0.0. Use
    + *   \Drupal\Core\Command\DbExportCommand
    
    @@ -40,7 +45,7 @@ class DbDumpCommand extends DbCommandBase {
    +      ->setDescription('Deprecated, use "export" instead.')
    

    This is nice, but when I ran the command I expected to be informed of when it will be deprecated. Can this be "Deprecated in Drupal:9.3.0 and is removed from Drupal:10.0.0. Use 'export' instead."

  2. +++ b/core/lib/Drupal/Core/Command/DbExportCommand.php
    @@ -0,0 +1,452 @@
    +      ->setDescription('Export the current database to a generation script.')
    

    I realize this is from the Dump command but it isn't correct. This will export other databases, not just the current one. How about something like, "Export a database to a generation script."?

paulocs’s picture

Assigned: Unassigned » paulocs

Working on it.

paulocs’s picture

Assigned: paulocs » Unassigned
Status: Needs work » Needs review
StatusFileSize
new17.72 KB
new35.77 KB

The changes that I made are:

1 - Added #3228237: Always sort tables in db-tools.php dump and #838992: Change the uid field from integer to serial by leveraging NO_AUTO_VALUE_ON_ZERO on MySQL to the DbExportCommand.php file.
2 - Changed DbDumpCommand.php to extend DbExportCommand.php
3 - Changed DbDumpApplication.php to extend DbExportApplication.php
4 - Updated deprecation message.
5 - Updated DbExportCommand message description.

Status: Needs review » Needs work

The last submitted patch, 21: 3213151-21.patch, failed testing. View results

paulocs’s picture

Status: Needs work » Needs review
StatusFileSize
new1.52 KB
new35.51 KB

New patch.

Status: Needs review » Needs work

The last submitted patch, 23: 3213151-23.patch, failed testing. View results

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.5.x-dev » 10.1.x-dev

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 10.1.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 11.x-dev » main

Drupal core is now using the main branch as the primary development branch. New developments and disruptive changes should now be targeted to the main branch.

Read more in the announcement.