Problem/Motivation
To write automated update tests for Drupal 8 & 9, one often needs to use a fixture with a database dump as explained in the doc
Writing Automated Update Tests for Drupal 8. The tool used to generate such a dump is only compatible with MySQL as explained in a comment in "DbDumpCommand.php":
* @todo This command is currently only compatible with MySQL. Making it
* backend-agnostic will require \Drupal\Core\Database\Schema support the
* ability to retrieve table schema information. Note that using a raw
* SQL dump file here (eg, generated from mysqldump or pg_dump) is not an
* option since these tend to still be database-backend specific.
* @see https://www.drupal.org/node/301038
I'm participating to the development of a module that only works with PostgreSQL and I can't use the following command line to generate a dump:
php ./core/scripts/db-tools.php dump-database-d8-mysql --database-url='pgsql://login:password@127.0.0.1:5432/drupal_database'
Steps to reproduce
- Install Drupal on a PostgreSQL database
- On your shell, try
php ./core/scripts/db-tools.php dump-database-d8-mysql --database-url='pgsql://login:password@127.0.0.1:5432/drupal_database'
You will get the exception This script can only be used with MySQL database backends..
Proposed resolution
I'm not sure having \Drupal\Core\Database\Schema support the ability to retrieve table schema information is a requirement. Maybe it is? However, I succeeded in generating a dump using the attached patch. This patch is only based on DB queries that use SQL information_schema and should be generic enough.
Remaining tasks
Test this patch against MySQL database to make sure the dumps are not altered compared with the original version of the scripts. Try on different environments (PostgreSQL versions) than mine.
API changes
A new protected member function "getDrupalSchemaName()" has been added to Drupal\Core\Command\DbDumpCommand.
| Comment | File | Size | Author |
|---|---|---|---|
| #5 | dump_db_postgresql-3222157-5.patch | 11.42 KB | guignonv |
Comments
Comment #2
guignonvI forgot to mention the patch changes the command line from:
php ./core/scripts/db-tools.php dump-database-d8-mysql --database-url='pgsql://login:password@127.0.0.1:5432/drupal_database'
to
php ./core/scripts/db-tools.php dump-database-d8-sql --database-url='pgsql://login:password@127.0.0.1:5432/drupal_database'
("my" removed).
Comment #3
guignonvComment #4
cilefen commentedCan you alias the original command name for backwards compatibility?
Comment #5
guignonvSure, you're right. I didn't think about it. My bad.
Comment #6
mradcliffeThanks for the patch.
I was going to confirm on my local PostgreSQL 11.6 environment a diff of dumps specifically to confirm if there were any long key names by default that get hashed by pgsql driver and not mysql driver. But the script isn't generating any schema.
Additionally, even with --schema-only, the data is dumped, and whether or not I provide values to --schema-only, it generates a dump for all tables. I get the same result without the --schema-only option.
Example
./core/scripts/db-tools.php dump-database-d8-sql --schema-only --database-url=pgsql://drupal:drupal@postgresql/drupal.Comment #11
quietone commented