From 25e09529b99d42707a65dd57e63eecc5829145a4 Mon Sep 17 00:00:00 2001 From: Sylvain Tissot Date: Mon, 9 Oct 2023 18:43:26 +0200 Subject: [PATCH] AbstractDatabase: replace Mysql by Mariadb & fix sed illegal byte sequence error on macOS --- src/Service/AbstractDatabase.php | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/Service/AbstractDatabase.php b/src/Service/AbstractDatabase.php index e0f8e5d..467b6d4 100644 --- a/src/Service/AbstractDatabase.php +++ b/src/Service/AbstractDatabase.php @@ -45,10 +45,10 @@ private static function dumpDataRemotely(string $remote, string $dumpFile): void */ final public static function dumpData(string $dumpFile): void { - $mysqlArgs = self::getMysqlArgs(); + $mariadbArgs = self::getMariadbArgs(); echo "dumping $dumpFile...\n"; - $dumpCmd = "mysqldump -v $mysqlArgs | sed 's/DEFINER=[^*]*\\*/\\*/g' | gzip > $dumpFile"; + $dumpCmd = "mariadb-dump -v $mariadbArgs | LC_CTYPE=C LANG=C sed 's/DEFINER=[^*]*\\*/\\*/g' | gzip > $dumpFile"; self::executeLocalCommand($dumpCmd); } @@ -70,7 +70,7 @@ private static function copyFile(string $remote, string $dumpFile): void */ final public static function loadData(string $dumpFile): void { - $mysqlArgs = self::getMysqlArgs(); + $mariadbArgs = self::getMariadbArgs(); $dumpFile = self::absolutePath($dumpFile); echo "loading dump $dumpFile...\n"; @@ -82,7 +82,7 @@ final public static function loadData(string $dumpFile): void _em()->getConnection()->close(); self::executeLocalCommand(PHP_BINARY . ' ./bin/doctrine orm:schema-tool:drop --ansi --full-database --force'); - self::executeLocalCommand("gunzip -c \"$dumpFile\" | sed 's/ALTER DATABASE `[^`]*`/ALTER DATABASE `$database`/g' | mysql $mysqlArgs"); + self::executeLocalCommand("gunzip -c \"$dumpFile\" | LC_CTYPE=C LANG=C sed 's/ALTER DATABASE `[^`]*`/ALTER DATABASE `$database`/g' | mariadb $mariadbArgs"); self::executeLocalCommand(PHP_BINARY . ' ./bin/doctrine migrations:migrate --ansi --no-interaction'); static::loadTriggers(); static::loadTestUsers(); @@ -96,7 +96,7 @@ private static function getDatabaseName(): string return $dbConfig['dbname']; } - private static function getMysqlArgs(): string + private static function getMariadbArgs(): string { /** @var array $dbConfig */ $dbConfig = _em()->getConnection()->getParams(); @@ -181,17 +181,17 @@ protected static function loadTestUsers(): void /** * Import a SQL file into DB. * - * This use mysql command, instead of DBAL methods, to allow to see errors if any, and + * This use mariadb command, instead of DBAL methods, to allow to see errors if any, and * also because it seems trigger creation do not work with DBAL for some unclear reasons. */ final public static function importFile(string $file): void { $file = self::absolutePath($file); - $mysqlArgs = self::getMysqlArgs(); + $mariadbArgs = self::getMariadbArgs(); echo 'importing ' . $file . "\n"; - $importCommand = "echo 'SET NAMES utf8mb4;' | cat - $file | mysql $mysqlArgs"; + $importCommand = "echo 'SET NAMES utf8mb4;' | cat - $file | mariadb $mariadbArgs"; self::executeLocalCommand($importCommand); }