fix: make CA migration idempotent for multi-db migrate:fresh safety

This commit is contained in:
dyzulk
2026-01-06 11:22:00 +07:00
parent 8a982bb499
commit b57645451d

View File

@@ -11,22 +11,24 @@ return new class extends Migration
*/ */
public function up(): void public function up(): void
{ {
Schema::create('ca_certificates', function (Blueprint $table) { if (!Schema::connection('mysql_ca')->hasTable('ca_certificates')) {
$table->string('uuid', 32)->primary(); Schema::connection('mysql_ca')->create('ca_certificates', function (Blueprint $table) {
$table->string('ca_type'); // root, intermediate_4096, intermediate_2048 $table->string('uuid', 32)->primary();
$table->longText('cert_content')->nullable(); $table->string('ca_type'); // root, intermediate_4096, intermediate_2048
$table->longText('key_content')->nullable(); $table->longText('cert_content')->nullable();
$table->string('serial_number')->nullable(); $table->longText('key_content')->nullable();
$table->string('common_name')->nullable(); $table->string('serial_number')->nullable();
$table->string('organization')->nullable(); $table->string('common_name')->nullable();
$table->dateTime('valid_from')->nullable(); $table->string('organization')->nullable();
$table->dateTime('valid_to')->nullable(); $table->dateTime('valid_from')->nullable();
$table->dateTime('valid_to')->nullable();
// Tracking
$table->unsignedBigInteger('download_count')->default(0); // Tracking
$table->timestamp('last_downloaded_at')->nullable(); $table->unsignedBigInteger('download_count')->default(0);
$table->timestamps(); $table->timestamp('last_downloaded_at')->nullable();
}); $table->timestamps();
});
}
} }
/** /**
@@ -34,6 +36,6 @@ return new class extends Migration
*/ */
public function down(): void public function down(): void
{ {
Schema::dropIfExists('ca_certificates'); Schema::connection('mysql_ca')->dropIfExists('ca_certificates');
} }
}; };