Skip to content

[1.x] Add mariadb driver support plus Laravel 11 CI tests #330

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Mar 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 26 additions & 15 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@ jobs:
mysql:
image: mysql:5.7
env:
MYSQL_ALLOW_EMPTY_PASSWORD: yes
MYSQL_DATABASE: forge
MYSQL_RANDOM_ROOT_PASSWORD: yes
MYSQL_DATABASE: pulse
MYSQL_USER: pulse
MYSQL_PASSWORD: password
ports:
- 3306:3306
options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3
Expand All @@ -32,7 +34,7 @@ jobs:
fail-fast: true
matrix:
php: [8.1, 8.2, 8.3]
laravel: [10]
laravel: [10, 11]
stability: [prefer-lowest, prefer-stable]

name: PHP ${{ matrix.php }} - Laravel ${{ matrix.laravel }} - Stability ${{ matrix.stability }} - MySQL 5.7
Expand Down Expand Up @@ -61,17 +63,22 @@ jobs:
run: vendor/bin/pest
env:
DB_CONNECTION: mysql
DB_USERNAME: root
DB_DATABASE: pulse
DB_USERNAME: pulse
DB_PASSWORD: password
DB_COLLATION: utf8mb4_unicode_ci
Comment on lines +66 to +69
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Setting the credentials explicitly instead of relying on the defaults which recently changed.

The collation needs to be explicitly included here because the default collation is not supported on MySQL 5.7 where these tests are running.


mariadb:
runs-on: ubuntu-22.04

services:
mysql:
image: mariadb:10.5
image: mariadb:10
Comment on lines -71 to +76
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems MariaDB 10.5 doesn't support the new default collation. Rather than customize the collation here, I've opted to match the framework's CI tests and specify 10, which would give us MariaDB 10.6.

env:
MYSQL_ALLOW_EMPTY_PASSWORD: yes
MYSQL_DATABASE: forge
MYSQL_RANDOM_ROOT_PASSWORD: yes
MYSQL_DATABASE: pulse
MYSQL_USER: pulse
MYSQL_PASSWORD: password
ports:
- 3306:3306
options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3
Expand All @@ -85,10 +92,10 @@ jobs:
fail-fast: true
matrix:
php: [8.3]
laravel: [10]
laravel: [11]
stability: [prefer-stable]

name: PHP ${{ matrix.php }} - Laravel ${{ matrix.laravel }} - Stability ${{ matrix.stability }} - MariaDB 10.5
name: PHP ${{ matrix.php }} - Laravel ${{ matrix.laravel }} - Stability ${{ matrix.stability }} - MariaDB 10

steps:
- name: Checkout code
Expand All @@ -113,8 +120,10 @@ jobs:
- name: Execute tests
run: vendor/bin/pest
env:
DB_CONNECTION: mysql
DB_USERNAME: root
DB_CONNECTION: mariadb
DB_DATABASE: pulse
DB_USERNAME: pulse
DB_PASSWORD: password

pgsql:
runs-on: ubuntu-22.04
Expand All @@ -123,8 +132,8 @@ jobs:
postgresql:
image: postgres:14
env:
POSTGRES_DB: forge
POSTGRES_USER: forge
POSTGRES_DB: pulse
POSTGRES_USER: pulse
POSTGRES_PASSWORD: password
ports:
- 5432:5432
Expand All @@ -139,7 +148,7 @@ jobs:
fail-fast: true
matrix:
php: [8.3]
laravel: [10]
laravel: [11]
stability: [prefer-stable]

name: PHP ${{ matrix.php }} - Laravel ${{ matrix.laravel }} - Stability ${{ matrix.stability }} - PostgreSQL 14
Expand Down Expand Up @@ -169,6 +178,8 @@ jobs:
run: vendor/bin/pest
env:
DB_CONNECTION: pgsql
DB_DATABASE: pulse
DB_USERNAME: pulse
DB_PASSWORD: password

sqlite:
Expand All @@ -185,7 +196,7 @@ jobs:
fail-fast: true
matrix:
php: [8.3]
laravel: [10]
laravel: [11]
stability: [prefer-stable]

name: PHP ${{ matrix.php }} - Laravel ${{ matrix.laravel }} - Stability ${{ matrix.stability }} - SQLite
Expand Down
6 changes: 3 additions & 3 deletions database/migrations/2023_06_07_000001_create_pulse_tables.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public function up(): void
$table->string('type');
$table->mediumText('key');
match ($this->driver()) {
'mysql' => $table->char('key_hash', 16)->charset('binary')->virtualAs('unhex(md5(`key`))'),
'mariadb', 'mysql' => $table->char('key_hash', 16)->charset('binary')->virtualAs('unhex(md5(`key`))'),
'pgsql' => $table->uuid('key_hash')->storedAs('md5("key")::uuid'),
'sqlite' => $table->string('key_hash'),
};
Expand All @@ -38,7 +38,7 @@ public function up(): void
$table->string('type');
$table->mediumText('key');
match ($this->driver()) {
'mysql' => $table->char('key_hash', 16)->charset('binary')->virtualAs('unhex(md5(`key`))'),
'mariadb', 'mysql' => $table->char('key_hash', 16)->charset('binary')->virtualAs('unhex(md5(`key`))'),
'pgsql' => $table->uuid('key_hash')->storedAs('md5("key")::uuid'),
'sqlite' => $table->string('key_hash'),
};
Expand All @@ -57,7 +57,7 @@ public function up(): void
$table->string('type');
$table->mediumText('key');
match ($this->driver()) {
'mysql' => $table->char('key_hash', 16)->charset('binary')->virtualAs('unhex(md5(`key`))'),
'mariadb', 'mysql' => $table->char('key_hash', 16)->charset('binary')->virtualAs('unhex(md5(`key`))'),
'pgsql' => $table->uuid('key_hash')->storedAs('md5("key")::uuid'),
'sqlite' => $table->string('key_hash'),
};
Expand Down
10 changes: 5 additions & 5 deletions src/Storage/DatabaseStorage.php
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ protected function upsertCount(array $values): int
['bucket', 'period', 'type', 'aggregate', 'key_hash'],
[
'value' => match ($driver = $this->connection()->getDriverName()) {
'mysql' => new Expression('`value` + values(`value`)'),
'mariadb', 'mysql' => new Expression('`value` + values(`value`)'),
'pgsql', 'sqlite' => new Expression('"pulse_aggregates"."value" + "excluded"."value"'),
default => throw new RuntimeException("Unsupported database driver [{$driver}]"),
},
Expand All @@ -202,7 +202,7 @@ protected function upsertMin(array $values): int
['bucket', 'period', 'type', 'aggregate', 'key_hash'],
[
'value' => match ($driver = $this->connection()->getDriverName()) {
'mysql' => new Expression('least(`value`, values(`value`))'),
'mariadb', 'mysql' => new Expression('least(`value`, values(`value`))'),
'pgsql' => new Expression('least("pulse_aggregates"."value", "excluded"."value")'),
'sqlite' => new Expression('min("pulse_aggregates"."value", "excluded"."value")'),
default => throw new RuntimeException("Unsupported database driver [{$driver}]"),
Expand All @@ -223,7 +223,7 @@ protected function upsertMax(array $values): int
['bucket', 'period', 'type', 'aggregate', 'key_hash'],
[
'value' => match ($driver = $this->connection()->getDriverName()) {
'mysql' => new Expression('greatest(`value`, values(`value`))'),
'mariadb', 'mysql' => new Expression('greatest(`value`, values(`value`))'),
'pgsql' => new Expression('greatest("pulse_aggregates"."value", "excluded"."value")'),
'sqlite' => new Expression('max("pulse_aggregates"."value", "excluded"."value")'),
default => throw new RuntimeException("Unsupported database driver [{$driver}]"),
Expand All @@ -244,7 +244,7 @@ protected function upsertSum(array $values): int
['bucket', 'period', 'type', 'aggregate', 'key_hash'],
[
'value' => match ($driver = $this->connection()->getDriverName()) {
'mysql' => new Expression('`value` + values(`value`)'),
'mariadb', 'mysql' => new Expression('`value` + values(`value`)'),
'pgsql', 'sqlite' => new Expression('"pulse_aggregates"."value" + "excluded"."value"'),
default => throw new RuntimeException("Unsupported database driver [{$driver}]"),
},
Expand All @@ -263,7 +263,7 @@ protected function upsertAvg(array $values): int
$values,
['bucket', 'period', 'type', 'aggregate', 'key_hash'],
match ($driver = $this->connection()->getDriverName()) {
'mysql' => [
'mariadb', 'mysql' => [
'value' => new Expression('(`value` * `count` + (values(`value`) * values(`count`))) / (`count` + values(`count`))'),
'count' => new Expression('`count` + values(`count`)'),
],
Expand Down
2 changes: 1 addition & 1 deletion src/Support/PulseMigration.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public function getConnection(): ?string
*/
protected function shouldRun(): bool
{
if (in_array($this->driver(), ['mysql', 'pgsql', 'sqlite'])) {
if (in_array($this->driver(), ['mariadb', 'mysql', 'pgsql', 'sqlite'])) {
return true;
}

Expand Down
2 changes: 1 addition & 1 deletion tests/Pest.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@
function keyHash(string $string): string
{
return match (DB::connection()->getDriverName()) {
'mysql' => hex2bin(md5($string)),
'mariadb', 'mysql' => hex2bin(md5($string)),
'pgsql' => Uuid::fromString(md5($string)),
'sqlite' => md5($string),
};
Expand Down