From 1c774e895f7cae4f4b98eef5511daa25a0a00fab Mon Sep 17 00:00:00 2001 From: Alexis Lefebvre Date: Sun, 14 Jan 2024 18:54:14 +0100 Subject: [PATCH 1/2] fix: unknown variable column-statistics=0 with MariaDB 10 --- .../DatabaseBackup/MysqlDatabaseBackup.php | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/Services/DatabaseBackup/MysqlDatabaseBackup.php b/src/Services/DatabaseBackup/MysqlDatabaseBackup.php index b3fe6d6b..a8b19755 100644 --- a/src/Services/DatabaseBackup/MysqlDatabaseBackup.php +++ b/src/Services/DatabaseBackup/MysqlDatabaseBackup.php @@ -75,7 +75,22 @@ public function backup(AbstractExecutor $executor): void $executor->getReferenceRepository()->save($this->getBackupFilePath()); self::$metadata = $em->getMetadataFactory()->getLoadedMetadata(); - exec("{$dbPass} mysqldump --host {$dbHost} {$port} --user {$dbUser} --no-create-info --skip-triggers --no-create-db --no-tablespaces --compact --column-statistics=0 {$dbName} > {$this->getBackupFilePath()}"); + $mysqldumpOptions = '--no-create-info --skip-triggers --no-create-db --no-tablespaces --compact'; + $mysqldumpCommand = 'mysqldump --host '.$dbHost.' '.$port.' --user '.$dbUser.' '.$dbName.' '.$mysqldumpOptions; + + exec( + 'mysqldump --version', + $output, + ); + + if (false === stripos(implode('', $output), 'MariaDB')) { + // when mysqldump is provided by MySQL (and not MariaDB), “--column-statistics=0” is a valid option, add it + $mysqldumpCommand .= ' --column-statistics=0'; + } + + exec( + $dbPass.' '.$mysqldumpCommand.' > '.$this->getBackupFilePath() + ); } public function restore(AbstractExecutor $executor, array $excludedTables = []): void From 02ec63a70468ab47e81493d3a8ef7450047e92f1 Mon Sep 17 00:00:00 2001 From: Alexis Lefebvre Date: Sun, 14 Jan 2024 20:26:21 +0100 Subject: [PATCH 2/2] chore: add a job to test mysqldump from MySQL or MariaDB --- .github/workflows/tests.yml | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index f36f5d9b..5f188e66 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -4,7 +4,7 @@ on: [push, pull_request] jobs: tests: - name: Symfony ${{ matrix.symfony-version }} on PHP ${{ matrix.php-version }} flags ${{ matrix.composer-flags }} + name: Symfony ${{ matrix.symfony-version }} - PHP ${{ matrix.php-version }} - flags ${{ matrix.composer-flags }} - mysqldump ${{ matrix.mysql-client }} runs-on: ubuntu-latest strategy: @@ -15,6 +15,7 @@ jobs: php-version: ['8.2'] composer-flags: [''] symfony-version: [''] + mysql-client: [ "default-mysql-client" ] include: - php-version: 7.4 # Use "update" instead of "install" since it allows using the "--prefer-lowest" option @@ -25,6 +26,10 @@ jobs: - php-version: 8.1 # add a specific job to test ^5.4 for all Symfony packages symfony-version: "^5.4" + - php-version: 8.1 + symfony-version: "^5.4" + # add a specific job to test mysqldump from MariaDB + mysql-client: "mariadb-client" - php-version: 8.2 # add a specific job to test ^6.3 for all Symfony packages symfony-version: "^6.3" @@ -60,6 +65,11 @@ jobs: - 5432:5432 steps: + - name: Install mysqldump + run: | + sudo apt install -y -q ${{ matrix.mysql-client }} + mysqldump --version + - name: Checkout uses: actions/checkout@v4