mirror of
https://github.com/pelican-dev/panel.git
synced 2025-05-20 00:34:44 +02:00
Dedicated MariaDB driver (#365)
* dedicated tests for mariadb * fix migrations * update database config * update database setup command
This commit is contained in:
parent
1d66d4c320
commit
10796f8916
74
.github/workflows/ci.yaml
vendored
74
.github/workflows/ci.yaml
vendored
@ -16,7 +16,7 @@ jobs:
|
|||||||
fail-fast: false
|
fail-fast: false
|
||||||
matrix:
|
matrix:
|
||||||
php: [8.2, 8.3]
|
php: [8.2, 8.3]
|
||||||
database: ["mariadb:10.3", "mysql:8"]
|
database: ["mysql:8"]
|
||||||
services:
|
services:
|
||||||
database:
|
database:
|
||||||
image: ${{ matrix.database }}
|
image: ${{ matrix.database }}
|
||||||
@ -81,6 +81,78 @@ jobs:
|
|||||||
DB_PORT: ${{ job.services.database.ports[3306] }}
|
DB_PORT: ${{ job.services.database.ports[3306] }}
|
||||||
DB_USERNAME: root
|
DB_USERNAME: root
|
||||||
|
|
||||||
|
mariadb:
|
||||||
|
name: MariaDB
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
strategy:
|
||||||
|
fail-fast: false
|
||||||
|
matrix:
|
||||||
|
php: [8.2, 8.3]
|
||||||
|
database: ["mariadb:10.3", "mariadb:10.11", "mariadb:11.4"]
|
||||||
|
services:
|
||||||
|
database:
|
||||||
|
image: ${{ matrix.database }}
|
||||||
|
env:
|
||||||
|
MYSQL_ALLOW_EMPTY_PASSWORD: yes
|
||||||
|
MYSQL_DATABASE: testing
|
||||||
|
ports:
|
||||||
|
- 3306
|
||||||
|
options: --health-cmd="mariadb-admin ping || mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3
|
||||||
|
env:
|
||||||
|
APP_ENV: testing
|
||||||
|
APP_DEBUG: "false"
|
||||||
|
APP_KEY: ThisIsARandomStringForTests12345
|
||||||
|
APP_TIMEZONE: UTC
|
||||||
|
APP_URL: http://localhost/
|
||||||
|
APP_ENVIRONMENT_ONLY: "true"
|
||||||
|
CACHE_DRIVER: array
|
||||||
|
MAIL_MAILER: array
|
||||||
|
SESSION_DRIVER: array
|
||||||
|
QUEUE_CONNECTION: sync
|
||||||
|
DB_CONNECTION: mariadb
|
||||||
|
DB_HOST: 127.0.0.1
|
||||||
|
DB_DATABASE: testing
|
||||||
|
DB_USERNAME: root
|
||||||
|
steps:
|
||||||
|
- name: Code Checkout
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- name: Get cache directory
|
||||||
|
id: composer-cache
|
||||||
|
run: |
|
||||||
|
echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT
|
||||||
|
|
||||||
|
- name: Cache
|
||||||
|
uses: actions/cache@v4
|
||||||
|
with:
|
||||||
|
path: ${{ steps.composer-cache.outputs.dir }}
|
||||||
|
key: ${{ runner.os }}-composer-${{ matrix.php }}-${{ hashFiles('**/composer.lock') }}
|
||||||
|
restore-keys: |
|
||||||
|
${{ runner.os }}-composer-${{ matrix.php }}-
|
||||||
|
|
||||||
|
- name: Setup PHP
|
||||||
|
uses: shivammathur/setup-php@v2
|
||||||
|
with:
|
||||||
|
php-version: ${{ matrix.php }}
|
||||||
|
extensions: bcmath, curl, gd, mbstring, mysql, openssl, pdo, tokenizer, xml, zip
|
||||||
|
tools: composer:v2
|
||||||
|
coverage: none
|
||||||
|
|
||||||
|
- name: Install dependencies
|
||||||
|
run: composer install --no-interaction --no-suggest --prefer-dist
|
||||||
|
|
||||||
|
- name: Unit tests
|
||||||
|
run: vendor/bin/phpunit tests/Unit
|
||||||
|
env:
|
||||||
|
DB_HOST: UNIT_NO_DB
|
||||||
|
SKIP_MIGRATIONS: true
|
||||||
|
|
||||||
|
- name: Integration tests
|
||||||
|
run: vendor/bin/phpunit tests/Integration
|
||||||
|
env:
|
||||||
|
DB_PORT: ${{ job.services.database.ports[3306] }}
|
||||||
|
DB_USERNAME: root
|
||||||
|
|
||||||
sqlite:
|
sqlite:
|
||||||
name: SQLite
|
name: SQLite
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
@ -13,6 +13,7 @@ class DatabaseSettingsCommand extends Command
|
|||||||
|
|
||||||
public const DATABASE_DRIVERS = [
|
public const DATABASE_DRIVERS = [
|
||||||
'sqlite' => 'SQLite (recommended)',
|
'sqlite' => 'SQLite (recommended)',
|
||||||
|
'mariadb' => 'MariaDB',
|
||||||
'mysql' => 'MySQL',
|
'mysql' => 'MySQL',
|
||||||
];
|
];
|
||||||
|
|
||||||
@ -21,10 +22,10 @@ class DatabaseSettingsCommand extends Command
|
|||||||
protected $signature = 'p:environment:database
|
protected $signature = 'p:environment:database
|
||||||
{--driver= : The database driver backend to use.}
|
{--driver= : The database driver backend to use.}
|
||||||
{--database= : The database to use.}
|
{--database= : The database to use.}
|
||||||
{--host= : The connection address for the MySQL server.}
|
{--host= : The connection address for the MySQL/ MariaDB server.}
|
||||||
{--port= : The connection port for the MySQL server.}
|
{--port= : The connection port for the MySQL/ MariaDB server.}
|
||||||
{--username= : Username to use when connecting to the MySQL server.}
|
{--username= : Username to use when connecting to the MySQL/ MariaDB server.}
|
||||||
{--password= : Password to use for the MySQL database.}';
|
{--password= : Password to use for the MySQL/ MariaDB database.}';
|
||||||
|
|
||||||
protected array $variables = [];
|
protected array $variables = [];
|
||||||
|
|
||||||
@ -82,7 +83,20 @@ class DatabaseSettingsCommand extends Command
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$this->testMySQLConnection();
|
// Test connection
|
||||||
|
config()->set('database.connections._panel_command_test', [
|
||||||
|
'driver' => 'mysql',
|
||||||
|
'host' => $this->variables['DB_HOST'],
|
||||||
|
'port' => $this->variables['DB_PORT'],
|
||||||
|
'database' => $this->variables['DB_DATABASE'],
|
||||||
|
'username' => $this->variables['DB_USERNAME'],
|
||||||
|
'password' => $this->variables['DB_PASSWORD'],
|
||||||
|
'charset' => 'utf8mb4',
|
||||||
|
'collation' => 'utf8mb4_unicode_ci',
|
||||||
|
'strict' => true,
|
||||||
|
]);
|
||||||
|
|
||||||
|
$this->database->connection('_panel_command_test')->getPdo();
|
||||||
} catch (\PDOException $exception) {
|
} catch (\PDOException $exception) {
|
||||||
$this->output->error(sprintf('Unable to connect to the MySQL server using the provided credentials. The error returned was "%s".', $exception->getMessage()));
|
$this->output->error(sprintf('Unable to connect to the MySQL server using the provided credentials. The error returned was "%s".', $exception->getMessage()));
|
||||||
$this->output->error(__('commands.database_settings.DB_error_2'));
|
$this->output->error(__('commands.database_settings.DB_error_2'));
|
||||||
@ -93,6 +107,66 @@ class DatabaseSettingsCommand extends Command
|
|||||||
return $this->handle();
|
return $this->handle();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
} elseif ($this->variables['DB_CONNECTION'] === 'mariadb') {
|
||||||
|
$this->output->note(__('commands.database_settings.DB_HOST_note'));
|
||||||
|
$this->variables['DB_HOST'] = $this->option('host') ?? $this->ask(
|
||||||
|
'Database Host',
|
||||||
|
config('database.connections.mariadb.host', '127.0.0.1')
|
||||||
|
);
|
||||||
|
|
||||||
|
$this->variables['DB_PORT'] = $this->option('port') ?? $this->ask(
|
||||||
|
'Database Port',
|
||||||
|
config('database.connections.mariadb.port', 3306)
|
||||||
|
);
|
||||||
|
|
||||||
|
$this->variables['DB_DATABASE'] = $this->option('database') ?? $this->ask(
|
||||||
|
'Database Name',
|
||||||
|
config('database.connections.mariadb.database', 'panel')
|
||||||
|
);
|
||||||
|
|
||||||
|
$this->output->note(__('commands.database_settings.DB_USERNAME_note'));
|
||||||
|
$this->variables['DB_USERNAME'] = $this->option('username') ?? $this->ask(
|
||||||
|
'Database Username',
|
||||||
|
config('database.connections.mariadb.username', 'pelican')
|
||||||
|
);
|
||||||
|
|
||||||
|
$askForMariaDBPassword = true;
|
||||||
|
if (!empty(config('database.connections.mariadb.password')) && $this->input->isInteractive()) {
|
||||||
|
$this->variables['DB_PASSWORD'] = config('database.connections.mariadb.password');
|
||||||
|
$askForMariaDBPassword = $this->confirm(__('commands.database_settings.DB_PASSWORD_note'));
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($askForMariaDBPassword) {
|
||||||
|
$this->variables['DB_PASSWORD'] = $this->option('password') ?? $this->secret('Database Password');
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
// Test connection
|
||||||
|
config()->set('database.connections._panel_command_test', [
|
||||||
|
'driver' => 'mariadb',
|
||||||
|
'host' => $this->variables['DB_HOST'],
|
||||||
|
'port' => $this->variables['DB_PORT'],
|
||||||
|
'database' => $this->variables['DB_DATABASE'],
|
||||||
|
'username' => $this->variables['DB_USERNAME'],
|
||||||
|
'password' => $this->variables['DB_PASSWORD'],
|
||||||
|
'charset' => 'utf8mb4',
|
||||||
|
'collation' => 'utf8mb4_unicode_ci',
|
||||||
|
'strict' => true,
|
||||||
|
]);
|
||||||
|
|
||||||
|
$this->database->connection('_panel_command_test')->getPdo();
|
||||||
|
} catch (\PDOException $exception) {
|
||||||
|
$this->output->error(sprintf('Unable to connect to the MariaDB server using the provided credentials. The error returned was "%s".', $exception->getMessage()));
|
||||||
|
$this->output->error(__('commands.database_settings.DB_error_2'));
|
||||||
|
|
||||||
|
if ($this->confirm(__('commands.database_settings.go_back'))) {
|
||||||
|
$this->database->disconnect('_panel_command_test');
|
||||||
|
|
||||||
|
return $this->handle();
|
||||||
|
}
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
} elseif ($this->variables['DB_CONNECTION'] === 'sqlite') {
|
} elseif ($this->variables['DB_CONNECTION'] === 'sqlite') {
|
||||||
@ -108,24 +182,4 @@ class DatabaseSettingsCommand extends Command
|
|||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Test that we can connect to the provided MySQL instance and perform a selection.
|
|
||||||
*/
|
|
||||||
private function testMySQLConnection()
|
|
||||||
{
|
|
||||||
config()->set('database.connections._panel_command_test', [
|
|
||||||
'driver' => 'mysql',
|
|
||||||
'host' => $this->variables['DB_HOST'],
|
|
||||||
'port' => $this->variables['DB_PORT'],
|
|
||||||
'database' => $this->variables['DB_DATABASE'],
|
|
||||||
'username' => $this->variables['DB_USERNAME'],
|
|
||||||
'password' => $this->variables['DB_PASSWORD'],
|
|
||||||
'charset' => 'utf8mb4',
|
|
||||||
'collation' => 'utf8mb4_unicode_ci',
|
|
||||||
'strict' => true,
|
|
||||||
]);
|
|
||||||
|
|
||||||
$this->database->connection('_panel_command_test')->getPdo();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,5 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
use App\Helpers\Time;
|
|
||||||
|
|
||||||
return [
|
return [
|
||||||
|
|
||||||
'default' => env('DB_CONNECTION', 'sqlite'),
|
'default' => env('DB_CONNECTION', 'sqlite'),
|
||||||
@ -17,25 +15,41 @@ return [
|
|||||||
|
|
||||||
'mysql' => [
|
'mysql' => [
|
||||||
'driver' => 'mysql',
|
'driver' => 'mysql',
|
||||||
'url' => env('DB_URL', env('DATABASE_URL')),
|
'url' => env('DB_URL'),
|
||||||
'host' => env('DB_HOST', '127.0.0.1'),
|
'host' => env('DB_HOST', '127.0.0.1'),
|
||||||
'port' => env('DB_PORT', '3306'),
|
'port' => env('DB_PORT', '3306'),
|
||||||
'database' => env('DB_DATABASE', 'panel'),
|
'database' => env('DB_DATABASE', 'panel'),
|
||||||
'username' => env('DB_USERNAME', 'pelican'),
|
'username' => env('DB_USERNAME', 'pelican'),
|
||||||
'password' => env('DB_PASSWORD', ''),
|
'password' => env('DB_PASSWORD', ''),
|
||||||
'unix_socket' => env('DB_SOCKET', ''),
|
'unix_socket' => env('DB_SOCKET', ''),
|
||||||
'charset' => 'utf8mb4',
|
'charset' => env('DB_CHARSET', 'utf8mb4'),
|
||||||
'collation' => 'utf8mb4_unicode_ci',
|
'collation' => env('DB_COLLATION', 'utf8mb4_unicode_ci'),
|
||||||
'prefix' => env('DB_PREFIX', ''),
|
'prefix' => env('DB_PREFIX', ''),
|
||||||
'prefix_indexes' => true,
|
'prefix_indexes' => true,
|
||||||
'strict' => env('DB_STRICT_MODE', false),
|
'strict' => env('DB_STRICT_MODE', false),
|
||||||
'timezone' => env('DB_TIMEZONE', Time::getMySQLTimezoneOffset(env('APP_TIMEZONE', 'UTC'))),
|
'engine' => null,
|
||||||
'sslmode' => env('DB_SSLMODE', 'prefer'),
|
'options' => extension_loaded('pdo_mysql') ? array_filter([
|
||||||
|
PDO::MYSQL_ATTR_SSL_CA => env('MYSQL_ATTR_SSL_CA'),
|
||||||
|
]) : [],
|
||||||
|
],
|
||||||
|
|
||||||
|
'mariadb' => [
|
||||||
|
'driver' => 'mariadb',
|
||||||
|
'url' => env('DB_URL'),
|
||||||
|
'host' => env('DB_HOST', '127.0.0.1'),
|
||||||
|
'port' => env('DB_PORT', '3306'),
|
||||||
|
'database' => env('DB_DATABASE', 'panel'),
|
||||||
|
'username' => env('DB_USERNAME', 'pelican'),
|
||||||
|
'password' => env('DB_PASSWORD', ''),
|
||||||
|
'unix_socket' => env('DB_SOCKET', ''),
|
||||||
|
'charset' => env('DB_CHARSET', 'utf8mb4'),
|
||||||
|
'collation' => env('DB_COLLATION', 'utf8mb4_unicode_ci'),
|
||||||
|
'prefix' => env('DB_PREFIX', ''),
|
||||||
|
'prefix_indexes' => true,
|
||||||
|
'strict' => env('DB_STRICT_MODE', false),
|
||||||
|
'engine' => null,
|
||||||
'options' => extension_loaded('pdo_mysql') ? array_filter([
|
'options' => extension_loaded('pdo_mysql') ? array_filter([
|
||||||
PDO::MYSQL_ATTR_SSL_CA => env('MYSQL_ATTR_SSL_CA'),
|
PDO::MYSQL_ATTR_SSL_CA => env('MYSQL_ATTR_SSL_CA'),
|
||||||
PDO::MYSQL_ATTR_SSL_CERT => env('MYSQL_ATTR_SSL_CERT'),
|
|
||||||
PDO::MYSQL_ATTR_SSL_KEY => env('MYSQL_ATTR_SSL_KEY'),
|
|
||||||
PDO::MYSQL_ATTR_SSL_VERIFY_SERVER_CERT => env('MYSQL_ATTR_SSL_VERIFY_SERVER_CERT', true),
|
|
||||||
]) : [],
|
]) : [],
|
||||||
],
|
],
|
||||||
],
|
],
|
||||||
|
@ -13,7 +13,7 @@ return new class extends Migration
|
|||||||
{
|
{
|
||||||
Schema::create('activity_logs', function (Blueprint $table) {
|
Schema::create('activity_logs', function (Blueprint $table) {
|
||||||
$table->id();
|
$table->id();
|
||||||
$table->uuid('batch')->nullable();
|
$table->char('batch', 36)->nullable();
|
||||||
$table->string('event')->index();
|
$table->string('event')->index();
|
||||||
$table->string('ip');
|
$table->string('ip');
|
||||||
$table->text('description')->nullable();
|
$table->text('description')->nullable();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user