Skip to content

Commit

Permalink
Fix mysql via mariadb warns about being deprecated (#6183) (#6189)
Browse files Browse the repository at this point in the history
* Fix mysql via mariadb warns about being deprecated (#6183)

"mysql: Deprecated program name. It will be removed in a future release, use '/usr/bin/mariadb' instead"

* Adjust SqlConnectTest

---------

Co-authored-by: TBiesenbeek <[email protected]>
Co-authored-by: Moshe Weitzman <[email protected]>
  • Loading branch information
3 people authored Jan 20, 2025
1 parent 305d991 commit b0ee286
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 19 deletions.
14 changes: 2 additions & 12 deletions src/Sql/SqlMariaDB.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,15 @@

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() || str_contains($process->getOutput(), 'MariaDB')) && 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
2 changes: 1 addition & 1 deletion tests/functional/SqlConnectTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public function testSqlConnect()
$shell_options = "-e";
$db_driver = $this->dbDriver();
if ($db_driver == 'mysql') {
$this->assertMatchesRegularExpression('/^mysql --user=[^\s]+ --password=.* --database=[^\s]+ --host=[^\s]+/', $connectionString);
$this->assertMatchesRegularExpression('/^mysql|mariadb --user=[^\s]+ --password=.* --database=[^\s]+ --host=[^\s]+/', $connectionString);
} elseif ($db_driver == 'sqlite') {
$this->assertStringContainsString('sqlite3', $connectionString);
$shell_options = '';
Expand Down

0 comments on commit b0ee286

Please sign in to comment.