mirror of
https://github.com/dyzulk/trustlab-api.git
synced 2026-01-26 05:15:35 +07:00
refactor: isolate CA migrations into separate directory for multi-database integrity
This commit is contained in:
@@ -11,9 +11,9 @@ return new class extends Migration
|
|||||||
*/
|
*/
|
||||||
public function up(): void
|
public function up(): void
|
||||||
{
|
{
|
||||||
// 1. Create table if not exists (Clean Slate for fresh install)
|
// 1. Create table if not exists
|
||||||
if (!Schema::connection('mysql_ca')->hasTable('ca_certificates')) {
|
if (!Schema::hasTable('ca_certificates')) {
|
||||||
Schema::connection('mysql_ca')->create('ca_certificates', function (Blueprint $table) {
|
Schema::create('ca_certificates', function (Blueprint $table) {
|
||||||
$table->string('uuid', 32)->primary();
|
$table->string('uuid', 32)->primary();
|
||||||
$table->string('ca_type');
|
$table->string('ca_type');
|
||||||
$table->longText('cert_content')->nullable();
|
$table->longText('cert_content')->nullable();
|
||||||
@@ -42,36 +42,36 @@ return new class extends Migration
|
|||||||
$table->timestamps();
|
$table->timestamps();
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
// 2. Self-Healing: Add missing columns if table already exists (Production Sync)
|
// 2. Self-Healing: Add missing columns if table already exists
|
||||||
Schema::connection('mysql_ca')->table('ca_certificates', function (Blueprint $table) {
|
Schema::table('ca_certificates', function (Blueprint $table) {
|
||||||
if (!Schema::connection('mysql_ca')->hasColumn('ca_certificates', 'cert_path')) {
|
if (!Schema::hasColumn('ca_certificates', 'cert_path')) {
|
||||||
$table->string('cert_path')->nullable()->after('serial_number');
|
$table->string('cert_path')->nullable()->after('serial_number');
|
||||||
}
|
}
|
||||||
if (!Schema::connection('mysql_ca')->hasColumn('ca_certificates', 'der_path')) {
|
if (!Schema::hasColumn('ca_certificates', 'der_path')) {
|
||||||
$table->string('der_path')->nullable()->after('cert_path');
|
$table->string('der_path')->nullable()->after('cert_path');
|
||||||
}
|
}
|
||||||
if (!Schema::connection('mysql_ca')->hasColumn('ca_certificates', 'bat_path')) {
|
if (!Schema::hasColumn('ca_certificates', 'bat_path')) {
|
||||||
$table->string('bat_path')->nullable()->after('der_path');
|
$table->string('bat_path')->nullable()->after('der_path');
|
||||||
}
|
}
|
||||||
if (!Schema::connection('mysql_ca')->hasColumn('ca_certificates', 'mac_path')) {
|
if (!Schema::hasColumn('ca_certificates', 'mac_path')) {
|
||||||
$table->string('mac_path')->nullable()->after('bat_path');
|
$table->string('mac_path')->nullable()->after('bat_path');
|
||||||
}
|
}
|
||||||
if (!Schema::connection('mysql_ca')->hasColumn('ca_certificates', 'linux_path')) {
|
if (!Schema::hasColumn('ca_certificates', 'linux_path')) {
|
||||||
$table->string('linux_path')->nullable()->after('mac_path');
|
$table->string('linux_path')->nullable()->after('mac_path');
|
||||||
}
|
}
|
||||||
if (!Schema::connection('mysql_ca')->hasColumn('ca_certificates', 'last_synced_at')) {
|
if (!Schema::hasColumn('ca_certificates', 'last_synced_at')) {
|
||||||
$table->timestamp('last_synced_at')->nullable()->after('linux_path');
|
$table->timestamp('last_synced_at')->nullable()->after('linux_path');
|
||||||
}
|
}
|
||||||
if (!Schema::connection('mysql_ca')->hasColumn('ca_certificates', 'is_latest')) {
|
if (!Schema::hasColumn('ca_certificates', 'is_latest')) {
|
||||||
$table->boolean('is_latest')->default(false)->after('last_synced_at');
|
$table->boolean('is_latest')->default(false)->after('last_synced_at');
|
||||||
}
|
}
|
||||||
if (!Schema::connection('mysql_ca')->hasColumn('ca_certificates', 'issuer_name')) {
|
if (!Schema::hasColumn('ca_certificates', 'issuer_name')) {
|
||||||
$table->string('issuer_name')->nullable()->after('organization');
|
$table->string('issuer_name')->nullable()->after('organization');
|
||||||
}
|
}
|
||||||
if (!Schema::connection('mysql_ca')->hasColumn('ca_certificates', 'issuer_serial')) {
|
if (!Schema::hasColumn('ca_certificates', 'issuer_serial')) {
|
||||||
$table->string('issuer_serial')->nullable()->after('issuer_name');
|
$table->string('issuer_serial')->nullable()->after('issuer_name');
|
||||||
}
|
}
|
||||||
if (!Schema::connection('mysql_ca')->hasColumn('ca_certificates', 'family_id')) {
|
if (!Schema::hasColumn('ca_certificates', 'family_id')) {
|
||||||
$table->string('family_id')->nullable()->after('issuer_serial');
|
$table->string('family_id')->nullable()->after('issuer_serial');
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -83,6 +83,6 @@ return new class extends Migration
|
|||||||
*/
|
*/
|
||||||
public function down(): void
|
public function down(): void
|
||||||
{
|
{
|
||||||
Schema::connection('mysql_ca')->dropIfExists('ca_certificates');
|
Schema::dropIfExists('ca_certificates');
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
Reference in New Issue
Block a user