Database dump for Automated Update Tests compatible with PostgreSQL

Created on 5 July 2021, over 3 years ago
Updated 13 June 2024, 7 months ago

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.

📌 Task
Status

Active

Version

11.0 🔥

Component
Database update 

Last updated 8 days ago

No maintainer
Created by

🇫🇷France guignonv

Live updates comments and jobs are added and updated live.
  • PostgreSQL

    Particularly affects sites running on the PostgreSQL database.

Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024