From 19cc157091444b03f28a73f4446c3305da2af53f Mon Sep 17 00:00:00 2001 From: Jess Archer Date: Wed, 13 Mar 2024 12:03:47 +1000 Subject: [PATCH 1/3] Add Laravel 11 CI tests --- .github/workflows/tests.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 7ab7f290..8e447470 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -32,7 +32,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 @@ -85,7 +85,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 }} - MariaDB 10.5 @@ -139,7 +139,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 @@ -185,7 +185,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 From a64162496efd2ed4f9b2189a142afef1ef56d157 Mon Sep 17 00:00:00 2001 From: Jess Archer Date: Wed, 13 Mar 2024 12:15:40 +1000 Subject: [PATCH 2/3] Fix CI database authentication --- .github/workflows/tests.yml | 33 ++++++++++++++++++++++----------- 1 file changed, 22 insertions(+), 11 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 8e447470..ba6cf92f 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -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 @@ -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 mariadb: runs-on: ubuntu-22.04 services: mysql: - image: mariadb:10.5 + image: mariadb:10 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 @@ -88,7 +95,7 @@ jobs: 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 @@ -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 @@ -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 @@ -169,6 +178,8 @@ jobs: run: vendor/bin/pest env: DB_CONNECTION: pgsql + DB_DATABASE: pulse + DB_USERNAME: pulse DB_PASSWORD: password sqlite: From 180c42c37a546b9aa9edde57db9387577f83e7b7 Mon Sep 17 00:00:00 2001 From: Jess Archer Date: Wed, 13 Mar 2024 12:33:18 +1000 Subject: [PATCH 3/3] Add mariadb driver support --- .../2023_06_07_000001_create_pulse_tables.php | 6 +++--- src/Storage/DatabaseStorage.php | 10 +++++----- src/Support/PulseMigration.php | 2 +- tests/Pest.php | 2 +- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/database/migrations/2023_06_07_000001_create_pulse_tables.php b/database/migrations/2023_06_07_000001_create_pulse_tables.php index f75b51e4..5d194e2c 100644 --- a/database/migrations/2023_06_07_000001_create_pulse_tables.php +++ b/database/migrations/2023_06_07_000001_create_pulse_tables.php @@ -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'), }; @@ -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'), }; @@ -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'), }; diff --git a/src/Storage/DatabaseStorage.php b/src/Storage/DatabaseStorage.php index 966e141f..995c6d08 100644 --- a/src/Storage/DatabaseStorage.php +++ b/src/Storage/DatabaseStorage.php @@ -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}]"), }, @@ -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}]"), @@ -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}]"), @@ -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}]"), }, @@ -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`)'), ], diff --git a/src/Support/PulseMigration.php b/src/Support/PulseMigration.php index fcdf6279..c517088e 100644 --- a/src/Support/PulseMigration.php +++ b/src/Support/PulseMigration.php @@ -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; } diff --git a/tests/Pest.php b/tests/Pest.php index 38144a35..3e6cd13b 100644 --- a/tests/Pest.php +++ b/tests/Pest.php @@ -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), };