Problem/Motivation

The list of tables provided by Drupal\Core\Database\Query\PlaceholderInterface\Schema::findTables() is not guaranteed to be in a specific order. This makes manipulating database dumps created by the db-tools.php command problematic.

Steps to reproduce

Import a database dump created on Drupal 8.9.
Export the database using db-tools.php on an 9.3 site.

Expected behavior:
There are minimal differences in the output with the database tables in the same order.

Actual behavior:
The tables are not in the same order, resulting in a huge git diff when comparing the database dump against an existing file.

Proposed resolution

Use asort() in Drupal\Core\Command\DbDumpCommand::getTables() to sort the tables.

Remaining tasks

Provide a patch.

User interface changes

n/a

API changes

n/a

Data model changes

n/a

Release notes snippet

The output of the db-tools.php command will now always sort the output based upon the alphabetical sorting of the table names.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

DamienMcKenna created an issue. See original summary.

DamienMcKenna’s picture

Issue summary: View changes
Status: Active » Needs review
FileSize
447 bytes

This adds the asort() function as suggested.

quietone’s picture

Status: Needs review » Reviewed & tested by the community

I mentioned the sorting problem in #838992-52: Change the uid field from integer to serial by leveraging NO_AUTO_VALUE_ON_ZERO on MySQL but failed to take it any further. Thanks @DamienMcKenna for doing so.

I am all for sorting these tables, anything to make it easier to work with a dump file is worth the extra bit of code. Anyone that has a dump that is not sorted adding sorting can just import/export and have a sorted dump file. The reverse isn't true.

I'd like to have this.

  • catch committed 2eebc00 on 9.3.x
    Issue #3228237 by DamienMcKenna, quietone: Always sort tables in db-...
catch’s picture

Version: 9.3.x-dev » 9.2.x-dev
Status: Reviewed & tested by the community » Fixed

Committed/pushed to 9.3.x and cherry-picked to 9.2.x, thanks!

  • catch committed 2bf4121 on 9.2.x
    Issue #3228237 by DamienMcKenna, quietone: Always sort tables in db-...
DamienMcKenna’s picture

Thanks for the quick commit, catch!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.