Skip to content

Commit

Permalink
MariaDB 11 support (#698)
Browse files Browse the repository at this point in the history
* Add support for MariaDB 11

* Health check update

* Split up MariaDB 10/11 commands

* Simplify split

* Fix volume naming

* Update stubs/mariadb10.stub

Co-authored-by: Julius Kiekbusch <[email protected]>

* Update stubs/mariadb10.stub

Co-authored-by: Julius Kiekbusch <[email protected]>

* Update stubs/mariadb11.stub

Co-authored-by: Julius Kiekbusch <[email protected]>

* Update stubs/mariadb11.stub

Co-authored-by: Julius Kiekbusch <[email protected]>

---------

Co-authored-by: Taylor Otwell <[email protected]>
Co-authored-by: Julius Kiekbusch <[email protected]>
  • Loading branch information
3 people authored Jun 18, 2024
1 parent 3a2a002 commit e08b594
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 8 deletions.
6 changes: 6 additions & 0 deletions database/mariadb/create-testing-database.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/usr/bin/env bash

/usr/bin/mariadb --user=root --password="$MYSQL_ROOT_PASSWORD" <<-EOSQL
CREATE DATABASE IF NOT EXISTS testing;
GRANT ALL PRIVILEGES ON \`testing%\`.* TO '$MYSQL_USER'@'%';
EOSQL
12 changes: 7 additions & 5 deletions src/Console/Concerns/InteractsWithDockerComposeServices.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ trait InteractsWithDockerComposeServices
protected $services = [
'mysql',
'pgsql',
'mariadb',
'mariadb10',
'mariadb11',
'redis',
'memcached',
'meilisearch',
Expand Down Expand Up @@ -66,7 +67,7 @@ protected function buildDockerCompose(array $services)
: Yaml::parse(file_get_contents(__DIR__ . '/../../../stubs/docker-compose.stub'));

// Prepare the installation of the "mariadb-client" package if the MariaDB service is used...
if (in_array('mariadb', $services)) {
if (in_array('mariadb10', $services) || in_array('mariadb11', $services)) {
$compose['services']['laravel.test']['build']['args']['MYSQL_CLIENT'] = 'mariadb-client';
}

Expand All @@ -92,7 +93,7 @@ protected function buildDockerCompose(array $services)
// Merge volumes...
collect($services)
->filter(function ($service) {
return in_array($service, ['mysql', 'pgsql', 'mariadb', 'redis', 'meilisearch', 'typesense', 'minio']);
return in_array($service, ['mysql', 'pgsql', 'mariadb10', 'mariadb11', 'redis', 'meilisearch', 'typesense', 'minio']);
})->filter(function ($service) use ($compose) {
return ! array_key_exists($service, $compose['volumes'] ?? []);
})->each(function ($service) use (&$compose) {
Expand Down Expand Up @@ -123,7 +124,8 @@ protected function replaceEnvVariables(array $services)
$environment = file_get_contents($this->laravel->basePath('.env'));

if (in_array('mysql', $services) ||
in_array('mariadb', $services) ||
in_array('mariadb10', $services) ||
in_array('mariadb11', $services) ||
in_array('pgsql', $services)) {
$defaults = [
'# DB_HOST=127.0.0.1',
Expand All @@ -145,7 +147,7 @@ protected function replaceEnvVariables(array $services)
$environment = preg_replace('/DB_CONNECTION=.*/', 'DB_CONNECTION=pgsql', $environment);
$environment = str_replace('DB_HOST=127.0.0.1', "DB_HOST=pgsql", $environment);
$environment = str_replace('DB_PORT=3306', "DB_PORT=5432", $environment);
} elseif (in_array('mariadb', $services)) {
} elseif (in_array('mariadb10', $services) || in_array('mariadb11', $services)) {
if ($this->laravel->config->has('database.connections.mariadb')) {
$environment = preg_replace('/DB_CONNECTION=.*/', 'DB_CONNECTION=mariadb', $environment);
}
Expand Down
3 changes: 2 additions & 1 deletion src/Console/InstallCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ public function handle()
$this->output->writeln('<fg=gray>➜</> <options=bold>./vendor/bin/sail up</>');

if (in_array('mysql', $services) ||
in_array('mariadb', $services) ||
in_array('mariadb10', $services) ||
in_array('mariadb11', $services) ||
in_array('pgsql', $services)) {
$this->components->warn('A database service was installed. Run "artisan migrate" to prepare your database:');

Expand Down
4 changes: 2 additions & 2 deletions stubs/mariadb.stub → stubs/mariadb10.stub
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ mariadb:
MYSQL_ALLOW_EMPTY_PASSWORD: 'yes'
volumes:
- 'sail-mariadb:/var/lib/mysql'
- './vendor/laravel/sail/database/mysql/create-testing-database.sh:/docker-entrypoint-initdb.d/10-create-testing-database.sh'
- './vendor/laravel/sail/database/mariadb/create-testing-database.sh:/docker-entrypoint-initdb.d/10-create-testing-database.sh'
networks:
- sail
healthcheck:
test: ["CMD", "mysqladmin", "ping", "-p${DB_PASSWORD}"]
test: ["CMD", "mariadb-admin", "ping", "-p${DB_PASSWORD}"]
retries: 3
timeout: 5s
20 changes: 20 additions & 0 deletions stubs/mariadb11.stub
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
mariadb:
image: 'mariadb:11'
ports:
- '${FORWARD_DB_PORT:-3306}:3306'
environment:
MYSQL_ROOT_PASSWORD: '${DB_PASSWORD}'
MYSQL_ROOT_HOST: "%"
MYSQL_DATABASE: '${DB_DATABASE}'
MYSQL_USER: '${DB_USERNAME}'
MYSQL_PASSWORD: '${DB_PASSWORD}'
MYSQL_ALLOW_EMPTY_PASSWORD: 'yes'
volumes:
- 'sail-mariadb:/var/lib/mysql'
- './vendor/laravel/sail/database/mariadb/create-testing-database.sh:/docker-entrypoint-initdb.d/10-create-testing-database.sh'
networks:
- sail
healthcheck:
test: ["CMD", "mariadb-admin", "ping", "-p${DB_PASSWORD}"]
retries: 3
timeout: 5s

0 comments on commit e08b594

Please sign in to comment.