From b57645451da61442f4523042a68f7dabc14272d3 Mon Sep 17 00:00:00 2001 From: dyzulk <66510723+dyzulk@users.noreply.github.com> Date: Tue, 6 Jan 2026 11:22:00 +0700 Subject: [PATCH] fix: make CA migration idempotent for multi-db migrate:fresh safety --- ...23_123913_create_ca_certificates_table.php | 36 ++++++++++--------- 1 file changed, 19 insertions(+), 17 deletions(-) diff --git a/database/migrations/2025_12_23_123913_create_ca_certificates_table.php b/database/migrations/2025_12_23_123913_create_ca_certificates_table.php index 42a5cb4..7083e35 100644 --- a/database/migrations/2025_12_23_123913_create_ca_certificates_table.php +++ b/database/migrations/2025_12_23_123913_create_ca_certificates_table.php @@ -11,22 +11,24 @@ return new class extends Migration */ public function up(): void { - Schema::create('ca_certificates', function (Blueprint $table) { - $table->string('uuid', 32)->primary(); - $table->string('ca_type'); // root, intermediate_4096, intermediate_2048 - $table->longText('cert_content')->nullable(); - $table->longText('key_content')->nullable(); - $table->string('serial_number')->nullable(); - $table->string('common_name')->nullable(); - $table->string('organization')->nullable(); - $table->dateTime('valid_from')->nullable(); - $table->dateTime('valid_to')->nullable(); - - // Tracking - $table->unsignedBigInteger('download_count')->default(0); - $table->timestamp('last_downloaded_at')->nullable(); - $table->timestamps(); - }); + if (!Schema::connection('mysql_ca')->hasTable('ca_certificates')) { + Schema::connection('mysql_ca')->create('ca_certificates', function (Blueprint $table) { + $table->string('uuid', 32)->primary(); + $table->string('ca_type'); // root, intermediate_4096, intermediate_2048 + $table->longText('cert_content')->nullable(); + $table->longText('key_content')->nullable(); + $table->string('serial_number')->nullable(); + $table->string('common_name')->nullable(); + $table->string('organization')->nullable(); + $table->dateTime('valid_from')->nullable(); + $table->dateTime('valid_to')->nullable(); + + // Tracking + $table->unsignedBigInteger('download_count')->default(0); + $table->timestamp('last_downloaded_at')->nullable(); + $table->timestamps(); + }); + } } /** @@ -34,6 +36,6 @@ return new class extends Migration */ public function down(): void { - Schema::dropIfExists('ca_certificates'); + Schema::connection('mysql_ca')->dropIfExists('ca_certificates'); } };