Skip to content

Commit

Permalink
Merge pull request #256 from alexislefebvre/fix-unknown-variable-colu…
Browse files Browse the repository at this point in the history
…mn-statistics-0

fix: unknown variable column-statistics=0 with MariaDB 10
  • Loading branch information
alexislefebvre authored Jan 15, 2024
2 parents 0ae684e + 02ec63a commit a5bf949
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
12 changes: 11 additions & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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
Expand All @@ -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"
Expand Down Expand Up @@ -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

Expand Down
17 changes: 16 additions & 1 deletion src/Services/DatabaseBackup/MysqlDatabaseBackup.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit a5bf949

Please sign in to comment.