Skip to content

Commit

Permalink
Fix mysql via mariadb warns about being deprecated (#6183)
Browse files Browse the repository at this point in the history
"mysql: Deprecated program name. It will be removed in a future release, use '/usr/bin/mariadb' instead"
  • Loading branch information
TBiesenbeek committed Jan 3, 2025
1 parent ec15d5d commit f474a64
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 17 deletions.
13 changes: 2 additions & 11 deletions src/Sql/SqlMariaDB.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,16 @@

namespace Drush\Sql;

use Drush\Exec\ExecTrait;

class SqlMariaDB extends SqlMysql
{
use ExecTrait;

public function command(): string
{
if (self::programExists('mariadb')) {
return 'mariadb';
}
return parent::command();
return 'mariadb';
}

public function dumpProgram(): string
{
if (self::programExists('mariadb-dump')) {
return 'mariadb-dump';
}
return parent::dumpProgram();
return 'mariadb-dump';
}
}
20 changes: 14 additions & 6 deletions src/Sql/SqlMysql.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,14 @@

namespace Drush\Sql;

use Drush\Drush;
use Drush\Exec\ExecTrait;
use PDO;

class SqlMysql extends SqlBase
{
use ExecTrait;

protected string $version;

public string $queryExtra = '-A';
Expand All @@ -17,15 +21,19 @@ class SqlMysql extends SqlBase
*/
public static function make(array $dbSpec, array $options)
{
// First get a MySQL instance
$instance = new self($dbSpec, $options);
// If the mysql version reports that it is MariaDB, use MariaDB as client.
$process = Drush::shell('mysql --version');
$process->setSimulated(false);
$process->run();
if ((!$process->isSuccessful() || strpos($process->getOutput(), 'MariaDB') !== false) && self::programExists('mariadb')) {
$instance = new SqlMariaDB($dbSpec, $options);
} else {
$instance = new self($dbSpec, $options);
}

$sql = 'SELECT VERSION();"';
$instance->alwaysQuery($sql);
$out = trim($instance->getProcess()->getOutput());
if (str_contains($out, 'MariaDB')) {
// Replace with a MariaDB driver.
$instance = new SqlMariaDB($dbSpec, $options);
}
$instance->setVersion($out);
return $instance;
}
Expand Down

0 comments on commit f474a64

Please sign in to comment.