Skip to content

Commit 23ce6d4

Browse files
authored
[1.x] Postgres support (#64)
* wip * wip * wip * wip * wip * wip * wip * wip * wip * wip * Fix code styling * wip * wip * wip * wip --------- Co-authored-by: jessarcher <[email protected]>
1 parent 1f58a95 commit 23ce6d4

File tree

8 files changed

+389
-125
lines changed

8 files changed

+389
-125
lines changed

.github/workflows/tests.yml

+57-3
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,15 @@ on:
1010
- cron: '0 0 * * *'
1111

1212
jobs:
13-
tests:
13+
mysql:
1414
runs-on: ubuntu-22.04
1515

1616
services:
1717
mysql:
1818
image: mysql:5.7
1919
env:
2020
MYSQL_ALLOW_EMPTY_PASSWORD: yes
21-
MYSQL_DATABASE: testing
21+
MYSQL_DATABASE: forge
2222
ports:
2323
- 3306:3306
2424
options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3
@@ -35,7 +35,7 @@ jobs:
3535
laravel: [10]
3636
stability: [prefer-lowest, prefer-stable]
3737

38-
name: PHP ${{ matrix.php }} - Laravel ${{ matrix.laravel }} - Stability ${{ matrix.stability }}
38+
name: PHP ${{ matrix.php }} - Laravel ${{ matrix.laravel }} - Stability ${{ matrix.stability }} - MySQL 5.7
3939

4040
steps:
4141
- name: Checkout code
@@ -62,3 +62,57 @@ jobs:
6262
env:
6363
DB_CONNECTION: mysql
6464
DB_USERNAME: root
65+
66+
pgsql:
67+
runs-on: ubuntu-22.04
68+
69+
services:
70+
postgresql:
71+
image: postgres:14
72+
env:
73+
POSTGRES_DB: forge
74+
POSTGRES_USER: forge
75+
POSTGRES_PASSWORD: password
76+
ports:
77+
- 5432:5432
78+
options: --health-cmd=pg_isready --health-interval=10s --health-timeout=5s --health-retries=3
79+
redis:
80+
image: redis
81+
ports:
82+
- 6379:6379
83+
options: --entrypoint redis-server
84+
85+
strategy:
86+
fail-fast: true
87+
matrix:
88+
php: [8.2, 8.3]
89+
laravel: [10]
90+
91+
name: PHP ${{ matrix.php }} - Laravel ${{ matrix.laravel }} - Stability ${{ matrix.stability }} - PostgreSQL 14
92+
93+
steps:
94+
- name: Checkout code
95+
uses: actions/checkout@v4
96+
97+
- name: Setup PHP
98+
uses: shivammathur/setup-php@v2
99+
with:
100+
php-version: ${{ matrix.php }}
101+
extensions: dom, curl, libxml, mbstring, redis, pcntl, zip
102+
ini-values: error_reporting=E_ALL
103+
tools: composer:v2
104+
coverage: none
105+
106+
- name: Install redis-cli
107+
run: sudo apt-get install -qq redis-tools
108+
109+
- name: Install dependencies
110+
run: |
111+
composer require "illuminate/contracts=^${{ matrix.laravel }}" --dev --no-update
112+
composer update --prefer-dist --no-interaction --no-progress
113+
114+
- name: Execute tests
115+
run: vendor/bin/pest
116+
env:
117+
DB_CONNECTION: pgsql
118+
DB_PASSWORD: password

database/migrations/2023_06_07_000001_create_pulse_tables.php

+22-7
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
use Illuminate\Database\Migrations\Migration;
44
use Illuminate\Database\Schema\Blueprint;
55
use Illuminate\Support\Facades\Config;
6+
use Illuminate\Support\Facades\DB;
67
use Illuminate\Support\Facades\Schema;
78

89
return new class extends Migration
@@ -20,27 +21,37 @@ public function getConnection(): ?string
2021
*/
2122
public function up(): void
2223
{
23-
Schema::create('pulse_values', function (Blueprint $table) {
24+
$connection = $this->getConnection() ?? DB::connection();
25+
26+
Schema::create('pulse_values', function (Blueprint $table) use ($connection) {
2427
$table->engine = 'InnoDB';
2528
$table->id();
2629
$table->unsignedInteger('timestamp');
2730
$table->string('type');
2831
$table->text('key');
29-
$table->char('key_hash', 16)->charset('binary')->virtualAs('unhex(md5(`key`))');
32+
match ($driver = $connection->getDriverName()) {
33+
'mysql' => $table->char('key_hash', 16)->charset('binary')->virtualAs('unhex(md5(`key`))'),
34+
'pgsql' => $table->uuid('key_hash')->storedAs('md5("key")::uuid'),
35+
default => throw new RuntimeException("Unsupported database driver [{$driver}]."),
36+
};
3037
$table->text('value');
3138

3239
$table->index('timestamp'); // For trimming...
3340
$table->index('type'); // For fast lookups and purging...
34-
$table->unique(['type', 'key_hash']); // For data integrity...
41+
$table->unique(['type', 'key_hash']); // For data integrity and upserts...
3542
});
3643

37-
Schema::create('pulse_entries', function (Blueprint $table) {
44+
Schema::create('pulse_entries', function (Blueprint $table) use ($connection) {
3845
$table->engine = 'InnoDB';
3946
$table->id();
4047
$table->unsignedInteger('timestamp');
4148
$table->string('type');
4249
$table->text('key');
43-
$table->char('key_hash', 16)->charset('binary')->virtualAs('unhex(md5(`key`))');
50+
match ($driver = $connection->getDriverName()) {
51+
'mysql' => $table->char('key_hash', 16)->charset('binary')->virtualAs('unhex(md5(`key`))'),
52+
'pgsql' => $table->uuid('key_hash')->storedAs('md5("key")::uuid'),
53+
default => throw new RuntimeException("Unsupported database driver [{$driver}]."),
54+
};
4455
$table->bigInteger('value')->nullable();
4556

4657
$table->index('timestamp'); // For trimming...
@@ -49,14 +60,18 @@ public function up(): void
4960
$table->index(['timestamp', 'type', 'key_hash', 'value']); // For aggregate queries...
5061
});
5162

52-
Schema::create('pulse_aggregates', function (Blueprint $table) {
63+
Schema::create('pulse_aggregates', function (Blueprint $table) use ($connection) {
5364
$table->engine = 'InnoDB';
5465
$table->id();
5566
$table->unsignedInteger('bucket');
5667
$table->unsignedMediumInteger('period');
5768
$table->string('type');
5869
$table->text('key');
59-
$table->char('key_hash', 16)->charset('binary')->virtualAs('unhex(md5(`key`))');
70+
match ($driver = $connection->getDriverName()) {
71+
'mysql' => $table->char('key_hash', 16)->charset('binary')->virtualAs('unhex(md5(`key`))'),
72+
'pgsql' => $table->uuid('key_hash')->storedAs('md5("key")::uuid'),
73+
default => throw new RuntimeException("Unsupported database driver [{$driver}]."),
74+
};
6075
$table->string('aggregate');
6176
$table->decimal('value', 20, 2);
6277
$table->unsignedInteger('count')->nullable();

phpunit.xml.dist

-3
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,5 @@
1010
</testsuites>
1111
<php>
1212
<env name="APP_KEY" value="base64:uz4B1RtFO57QGzbZX1kRYX9hIRB50+QzqFeg9zbFJlY="/>
13-
<env name="DB_CONNECTION" value="mysql"/>
14-
<env name="DB_DATABASE" value="testing"/>
15-
<env name="DB_USERNAME" value="root"/>
1613
</php>
1714
</phpunit>

0 commit comments

Comments
 (0)