Skip to content
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

feat: separate mariadb driver #4132

Merged
merged 5 commits into from
Dec 2, 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
52 changes: 28 additions & 24 deletions .github/workflows/REUSABLE_backend.yml
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ env:
FLARUM_TEST_TMP_DIR_LOCAL: tests/integration/tmp
COMPOSER_AUTH: ${{ secrets.composer_auth }}
DB_DATABASE: flarum_test
DB_USERNAME: root
DB_PASSWORD: root
DB_USERNAME: flarum
DB_PASSWORD: password

jobs:
test:
Expand All @@ -94,7 +94,7 @@ jobs:
driver: mysql
- service: mariadb
db: MariaDB
driver: mysql
driver: mariadb
- service: 'mysql:8.1.0'
db: MySQL 8.1
driver: mysql
Expand All @@ -115,7 +115,7 @@ jobs:
- php: ${{ fromJSON(inputs.php_versions)[0] }}
service: mariadb
db: MariaDB
driver: mysql
driver: mariadb
prefix: flarum_
prefixStr: (prefix)
- php: ${{ fromJSON(inputs.php_versions)[0] }}
Expand Down Expand Up @@ -159,17 +159,28 @@ jobs:
MYSQL_DATABASE: ${{ env.DB_DATABASE }}
MYSQL_USER: ${{ env.DB_USERNAME }}
MYSQL_PASSWORD: ${{ env.DB_PASSWORD }}
MYSQL_ROOT_PASSWORD: ${{ env.DB_PASSWORD }}
MYSQL_ROOT_PASSWORD: root
ports:
- 3306
options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=10
mariadb:
image: ${{ matrix.driver == 'mariadb' && matrix.service || '' }}
env:
MARIADB_DATABASE: ${{ env.DB_DATABASE }}
MARIADB_USER: ${{ env.DB_USERNAME }}
MARIADB_PASSWORD: ${{ env.DB_PASSWORD }}
MARIADB_ROOT_PASSWORD: root
ports:
- 13306:3306
- 3306
options: --health-cmd="healthcheck.sh --connect --innodb_initialized" --health-interval=10s --health-timeout=5s --health-retries=3
postgres:
image: ${{ matrix.driver == 'pgsql' && matrix.service || '' }}
env:
POSTGRES_DB: ${{ env.DB_DATABASE }}
POSTGRES_USER: ${{ env.DB_USERNAME }}
POSTGRES_PASSWORD: ${{ env.DB_PASSWORD }}
ports:
- 15432:5432
- 5432
options: >-
--health-cmd pg_isready
--health-interval 10s
Expand All @@ -183,7 +194,10 @@ jobs:
((github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name != github.repository) || github.event_name != 'pull_request')

steps:
- uses: actions/checkout@master
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 1

- name: Setup PHP
uses: shivammathur/setup-php@v2
Expand All @@ -194,12 +208,6 @@ jobs:
tools: phpunit, composer:v2
ini-values: ${{ matrix.php_ini_values }}

- name: Create MySQL Database
if: ${{ matrix.driver == 'mysql' }}
run: |
sudo systemctl start mysql
mysql -uroot -proot -e 'CREATE DATABASE flarum_test;' --port 13306

- name: Install Composer dependencies
run: composer install
working-directory: ${{ inputs.backend_directory }}
Expand All @@ -222,7 +230,8 @@ jobs:
fi
working-directory: ${{ inputs.backend_directory }}
env:
DB_PORT: ${{ matrix.driver == 'mysql' && 13306 || 15432 }}
DB_HOST: 127.0.0.1
DB_PORT: ${{ (matrix.driver == 'mysql' && job.services.mysql.ports['3306']) || (matrix.driver == 'mariadb' && job.services.mariadb.ports['3306']) || (matrix.driver == 'pgsql' && job.services.postgres.ports['5432']) }}
DB_PREFIX: ${{ matrix.prefix }}
DB_DRIVER: ${{ matrix.driver }}
COMPOSER_PROCESS_TIMEOUT: 600
Expand All @@ -232,13 +241,7 @@ jobs:

strategy:
matrix:
php: ${{ fromJSON(inputs.php_versions) }}

services:
mysql:
image: mysql:8.0.30
ports:
- 33306:3306
php: ${{ fromJson(inputs.php_versions) }}

name: 'PHPStan PHP ${{ matrix.php }}'

Expand All @@ -265,12 +268,13 @@ jobs:
- name: Create MySQL Database
run: |
sudo systemctl start mysql
mysql -uroot -proot -e 'CREATE DATABASE flarum_test;' --port 33306
mysql -uroot -proot -e 'CREATE DATABASE flarum_test;' --port 3306

- name: Run PHPStan
run: composer analyse:phpstan
env:
DB_PORT: 33306
DB_USERNAME: root
DB_PORT: 3306
DB_PASSWORD: root
COMPOSER_PROCESS_TIMEOUT: 600
FLARUM_TEST_TMP_DIR_LOCAL: ./tmp
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ private function getTimedCounts(Builder $query, string $column, ?DateTime $start
$dbFormattedDatetime = match ($query->getConnection()->getDriverName()) {
'sqlite' => "strftime($format, $column)",
'pgsql' => "TO_CHAR($column, $format)",
'mysql' => "DATE_FORMAT($column, $format)",
'mysql', 'mariadb' => "DATE_FORMAT($column, $format)",
default => throw new Exception('Unsupported database driver'),
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,14 @@
* LICENSE file that was distributed with this source code.
*/

use Illuminate\Database\MySqlConnection;
use Illuminate\Database\Schema\Builder;

return [
'up' => function (Builder $schema) {
$connection = $schema->getConnection();

if ($connection->getDriverName() === 'mysql') {
if ($connection->getDriverName() instanceof MySqlConnection) {
$prefix = $connection->getTablePrefix();
$connection->statement('ALTER TABLE '.$prefix.'posts ENGINE = InnoDB');
}
Expand All @@ -22,7 +23,7 @@
'down' => function (Builder $schema) {
$connection = $schema->getConnection();

if ($connection->getDriverName() === 'mysql') {
if ($connection->getDriverName() instanceof MySqlConnection) {
$prefix = $connection->getTablePrefix();
$connection->statement('ALTER TABLE '.$prefix.'posts ENGINE = MyISAM');
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* LICENSE file that was distributed with this source code.
*/

use Illuminate\Database\MariaDbConnection;
use Illuminate\Database\MySqlConnection;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Schema\Builder;

Expand All @@ -26,14 +26,16 @@
$table->json('preferences_json')->nullable();
});

if ($connection instanceof MariaDbConnection) {
$connection->table('users')->update([
'preferences_json' => $connection->raw("IF(JSON_VALID(CONVERT($preferences USING utf8mb4)), CONVERT($preferences USING utf8mb4), NULL)"),
]);
} elseif ($driver === 'mysql') {
$connection->table('users')->update([
'preferences_json' => $connection->raw("CAST(CONVERT($preferences USING utf8mb4) AS JSON)"),
]);
if ($connection instanceof MySqlConnection) {
if ($connection->isMaria()) {
$connection->table('users')->update([
'preferences_json' => $connection->raw("IF(JSON_VALID(CONVERT($preferences USING utf8mb4)), CONVERT($preferences USING utf8mb4), NULL)"),
]);
} else {
$connection->table('users')->update([
'preferences_json' => $connection->raw("CAST(CONVERT($preferences USING utf8mb4) AS JSON)"),
]);
}
}

$schema->table('users', function (Blueprint $table) {
Expand All @@ -60,7 +62,7 @@
$table->binary('preferences_binary')->nullable();
});

if ($driver === 'mysql') {
if ($connection instanceof MySqlConnection) {
$connection->table('users')->update([
'preferences_binary' => $connection->raw($preferences),
]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* LICENSE file that was distributed with this source code.
*/

use Illuminate\Database\MariaDbConnection;
use Illuminate\Database\MySqlConnection;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Schema\Builder;

Expand All @@ -25,14 +25,16 @@
$table->json('data_json')->nullable();
});

if ($connection instanceof MariaDbConnection) {
$connection->table('notifications')->update([
'data_json' => $connection->raw('IF(JSON_VALID(CONVERT(data USING utf8mb4)), CONVERT(data USING utf8mb4), NULL)'),
]);
} elseif ($driver === 'mysql') {
$connection->table('notifications')->update([
'data_json' => $connection->raw('CAST(CONVERT(data USING utf8mb4) AS JSON)'),
]);
if ($connection instanceof MySqlConnection) {
if ($connection->isMaria()) {
$connection->table('notifications')->update([
'data_json' => $connection->raw('IF(JSON_VALID(CONVERT(data USING utf8mb4)), CONVERT(data USING utf8mb4), NULL)'),
]);
} else {
$connection->table('notifications')->update([
'data_json' => $connection->raw('CAST(CONVERT(data USING utf8mb4) AS JSON)'),
]);
}
}

$schema->table('notifications', function (Blueprint $table) {
Expand All @@ -58,7 +60,7 @@
$table->binary('data_binary')->nullable();
});

if ($driver === 'mysql') {
if ($connection instanceof MySqlConnection) {
$connection->table('notifications')->update([
'data_binary' => $connection->raw('data'),
]);
Expand Down
Loading
Loading