Skip to content

Commit 3b7aa87

Browse files
committed
add MariaDB support
1 parent 5f40fec commit 3b7aa87

4 files changed

Lines changed: 47 additions & 18 deletions

File tree

.github/workflows/ci.yml

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,21 @@ jobs:
2020
fail-fast: false
2121
matrix:
2222
php-version: [ '8.1', '8.2', '8.3', '8.4' ]
23-
db-type: [ sqlite, mysql, pgsql ]
23+
db-type: [ sqlite, mysql, mariadb, pgsql ]
2424

2525
services:
26+
mariadb:
27+
image: mariadb:11
28+
env:
29+
MARIADB_ROOT_PASSWORD: root
30+
MARIADB_DATABASE: cakephp
31+
ports:
32+
- 3307:3306
33+
options: >-
34+
--health-cmd "mariadb-admin ping -h localhost -proot"
35+
--health-interval 10s
36+
--health-timeout 5s
37+
--health-retries 5
2638
postgres:
2739
image: postgres:14
2840
env:
@@ -44,6 +56,10 @@ jobs:
4456
sudo service mysql start
4557
mysql -h 127.0.0.1 -u root -proot -e 'CREATE DATABASE cakephp;'
4658
59+
- name: Install MariaDB dump tools
60+
if: matrix.db-type == 'mariadb'
61+
run: sudo apt-get install mariadb-client
62+
4763
- name: Setup Postgres
4864
if: matrix.db-type == 'pgsql'
4965
run: |
@@ -57,7 +73,7 @@ jobs:
5773
uses: shivammathur/setup-php@v2
5874
with:
5975
php-version: ${{ matrix.php-version }}
60-
extensions: mbstring, intl, pdo_${{ matrix.db-type }}
76+
extensions: mbstring, intl, ${{ matrix.db-type == 'sqlite' && 'pdo_sqlite' || matrix.db-type == 'pgsql' && 'pdo_pgsql' || 'pdo_mysql' }}
6177
ini-values: zend.assertions=1
6278
coverage: pcov
6379

@@ -75,6 +91,9 @@ jobs:
7591
if [[ ${{ matrix.db-type }} == 'mysql' ]]; then
7692
export DB_URL=mysql://root:root@127.0.0.1/cakephp
7793
fi
94+
if [[ ${{ matrix.db-type }} == 'mariadb' ]]; then
95+
export DB_URL=mysql://root:root@127.0.0.1:3307/cakephp
96+
fi
7897
if [[ ${{ matrix.db-type }} == 'pgsql' ]]; then
7998
export DB_URL=postgres://postgres:postgres@127.0.0.1/postgres
8099
fi
@@ -107,7 +126,7 @@ jobs:
107126
uses: ramsey/composer-install@v3
108127

109128
- name: Install PHP tools with phive.
110-
run: "phive install --trust-gpg-keys 'CF1A108D0E7AE720,51C67305FFC2E5C0,12CE0F1D262429A5'"
129+
run: "phive install --trust-gpg-keys '51C67305FFC2E5C0,12CE0F1D262429A5'"
111130

112131
- name: Run phpcs
113132
if: always()
@@ -120,4 +139,3 @@ jobs:
120139
- name: Run phpstan
121140
if: always()
122141
run: tools/phpstan analyse --error-format=github
123-

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@ public function bootstrap(): void
4747

4848
For each DBMS you need to have its respective dump tool installed.
4949

50-
- MySQL/MariaDB => `mysqldump`
50+
- MySQL => `mysqldump`
51+
- MariaDB => `mariadb-dump`
5152
- SQLite => `sqlite3`
5253
- PostgreSQL => `pg_dump`
5354

src/Command/DumpSqlCommand.php

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -67,19 +67,15 @@ public function execute(Arguments $args, ConsoleIo $io): int
6767
}
6868

6969
$driver = $connection->getDriver();
70-
switch (get_class($driver)) {
71-
case Mysql::class:
72-
$object = new CakeDumpMySQL($connection->config());
73-
break;
74-
case Sqlite::class:
75-
$object = new CakeDumpSqlite($connection->config());
76-
break;
77-
case Postgres::class:
78-
$object = new CakeDumpPostgres($connection->config());
79-
break;
80-
default:
81-
$message = sprintf('Unknown driver "%s" given.', get_class($driver));
82-
throw new UnknownDriverException($message);
70+
if ($driver instanceof Mysql) {
71+
$object = new CakeDumpMySQL($connection->config(), $driver);
72+
} elseif ($driver instanceof Sqlite) {
73+
$object = new CakeDumpSqlite($connection->config());
74+
} elseif ($driver instanceof Postgres) {
75+
$object = new CakeDumpPostgres($connection->config());
76+
} else {
77+
$message = sprintf('Unknown driver "%s" given.', get_class($driver));
78+
throw new UnknownDriverException($message);
8379
}
8480

8581
$object->setIo($io);

src/Sql/MySQL.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,27 @@
33

44
namespace CakeDumpSql\Sql;
55

6+
use Cake\Database\Driver\Mysql as MysqlDriver;
67
use CakeDumpSql\Error\BinaryNotFoundException;
78
use Symfony\Component\Process\Process;
89

910
class MySQL extends SqlBase
1011
{
1112
protected string $command = 'mysqldump';
1213

14+
/**
15+
* @param array<string, mixed> $config The config array from the connection object
16+
* @param \Cake\Database\Driver\Mysql $driver The current mysql driver instance
17+
*/
18+
public function __construct(array $config, MysqlDriver $driver)
19+
{
20+
parent::__construct($config);
21+
22+
if ($driver->isMariadb()) {
23+
$this->command = 'mariadb-dump';
24+
}
25+
}
26+
1327
/**
1428
* @return string
1529
* @throws \CakeDumpSql\Error\BinaryNotFoundException

0 commit comments

Comments
 (0)