Database collations (#489)

* SyncDatabases

* Collation on Create inc WordPress

* Refactored Enum

* Resolve sync issue

* Fix for PostgreSQL

* pint

* reversed enum

* style adjustments

* add unit tests

* style

* fix tests

* more tests

---------

Co-authored-by: Saeed Vaziry <61919774+saeedvaziry@users.noreply.github.com>
Co-authored-by: Saeed Vaziry <mr.saeedvaziry@gmail.com>
This commit is contained in:
Richard Anderson
2025-03-02 16:18:27 +00:00
committed by GitHub
parent 269ee8d962
commit 5a12ed76bb
35 changed files with 585 additions and 19 deletions

View File

@ -0,0 +1,50 @@
<?php
use App\Enums\ServerStatus;
use App\Models\Server;
use App\SSH\Services\Database\Database;
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::table('databases', function (Blueprint $table) {
$table->string('collation')->nullable();
$table->string('charset')->nullable();
});
$servers = Server::query()->where('status', ServerStatus::READY)->get();
/** @var Server $server */
foreach ($servers as $server) {
$service = $server->database();
if (! $service) {
continue;
}
/** @var Database $db */
$db = $service->handler();
$db->syncDatabases(false);
$db->updateCharsets();
}
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::table('databases', function (Blueprint $table) {
$table->dropColumn('collation');
$table->dropColumn('charset');
});
}
};