feat: update default image value for standalone ClickHouse instances

This commit is contained in:
Andras Bacsai 2025-12-17 11:22:41 +01:00
parent f37eef8266
commit 6e7ce9d822
3 changed files with 59 additions and 11 deletions

View file

@ -19,7 +19,6 @@ public function up(): void
$table->string('clickhouse_admin_user')->default('default');
$table->text('clickhouse_admin_password');
$table->string('clickhouse_db')->default('default');
$table->boolean('is_log_drain_enabled')->default(false);
$table->boolean('is_include_timestamps')->default(false);
@ -27,7 +26,7 @@ public function up(): void
$table->string('status')->default('exited');
$table->string('image')->default('clickhouse/clickhouse-server:latest');
$table->string('image')->default('bitnami/clickhouse');
$table->boolean('is_public')->default(false);
$table->integer('public_port')->nullable();

View file

@ -0,0 +1,32 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
public function up()
{
// Change the default value for the 'image' column
Schema::table('standalone_clickhouses', function (Blueprint $table) {
$table->string('image')->default('bitnamilegacy/clickhouse')->change();
});
// Optionally, update any existing rows with the old default to the new one
DB::table('standalone_clickhouses')
->where('image', 'bitnami/clickhouse')
->update(['image' => 'bitnamilegacy/clickhouse']);
}
public function down()
{
Schema::table('standalone_clickhouses', function (Blueprint $table) {
$table->string('image')->default('bitnami/clickhouse')->change();
});
// Optionally, revert any changed values
DB::table('standalone_clickhouses')
->where('image', 'bitnamilegacy/clickhouse')
->update(['image' => 'bitnami/clickhouse']);
}
};

View file

@ -1,11 +1,11 @@
<?php
use App\Models\LocalPersistentVolume;
use App\Models\StandaloneClickhouse;
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
use Illuminate\Support\Facades\DB;
use App\Models\StandaloneClickhouse;
use App\Models\LocalPersistentVolume;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
@ -17,22 +17,31 @@
*/
public function up(): void
{
if (!Schema::hasColumn('standalone_clickhouses', 'clickhouse_db')) {
// Add clickhouse_db column if it doesn't exist
if (! Schema::hasColumn('standalone_clickhouses', 'clickhouse_db')) {
Schema::table('standalone_clickhouses', function (Blueprint $table) {
$table->string('clickhouse_db')
->default('default')
->after('clickhouse_admin_password');
});
}
// Change the default value for the 'image' column to the official image
Schema::table('standalone_clickhouses', function (Blueprint $table) {
$table->string('image')->default('clickhouse/clickhouse-server:latest')->change();
});
// Update existing ClickHouse instances from Bitnami images to official image
StandaloneClickhouse::where(function ($query) {
$query->where('image', 'like', '%bitnami/clickhouse%')
->orWhere('image', 'like', '%bitnamilegacy/clickhouse%');
})
$query->where('image', 'like', '%bitnami/clickhouse%')
->orWhere('image', 'like', '%bitnamilegacy/clickhouse%');
})
->update([
'image' => 'clickhouse/clickhouse-server:latest',
'clickhouse_db' => DB::raw("COALESCE(clickhouse_db, 'default')")
'clickhouse_db' => DB::raw("COALESCE(clickhouse_db, 'default')"),
]);
// Update volume mount paths from Bitnami to official image paths
LocalPersistentVolume::where('resource_type', StandaloneClickhouse::class)
->where('mount_path', '/bitnami/clickhouse')
->update(['mount_path' => '/var/lib/clickhouse']);
@ -43,8 +52,16 @@ public function up(): void
*/
public function down(): void
{
// Revert the default value for the 'image' column
Schema::table('standalone_clickhouses', function (Blueprint $table) {
$table->string('image')->default('bitnamilegacy/clickhouse')->change();
});
// Revert existing ClickHouse instances back to Bitnami image
StandaloneClickhouse::where('image', 'clickhouse/clickhouse-server:latest')
->update(['image' => 'bitnami/clickhouse']);
->update(['image' => 'bitnamilegacy/clickhouse']);
// Revert volume mount paths
LocalPersistentVolume::where('resource_type', StandaloneClickhouse::class)
->where('mount_path', '/var/lib/clickhouse')
->update(['mount_path' => '/bitnami/clickhouse']);