refactor: update server tag storage to individual columns and remove JSON tags migration

This commit is contained in:
2025-12-18 20:48:30 -05:00
parent 1caf5bc160
commit 96001cbecd
3 changed files with 32 additions and 36 deletions

View File

@@ -104,8 +104,13 @@ class ServerTagController
];
}
// Update local database
$server->tags = $processedTags;
// Update individual tag columns
$server->tag1 = $processedTags[0]['text'] ?? null;
$server->tag1color = $processedTags[0]['color'] ?? null;
$server->tag2 = $processedTags[1]['text'] ?? null;
$server->tag2color = $processedTags[1]['color'] ?? null;
$server->tag3 = $processedTags[2]['text'] ?? null;
$server->tag3color = $processedTags[2]['color'] ?? null;
$server->save();
// Sync to Proxmox

View File

@@ -23,12 +23,33 @@ class Server extends Model
'user_set_icon',
'user_set_icon_color',
'user_set_icon_prefix',
'tags',
'tag1',
'tag1color',
'tag2',
'tag2color',
'tag3',
'tag3color',
];
protected $casts = [
'tags' => 'array',
];
/**
* Get tags as an array of objects
*/
public function getTagsAttribute(): array
{
$tags = [];
if (!empty($this->tag1)) {
$tags[] = ['text' => $this->tag1, 'color' => $this->tag1color ?? '#3498db'];
}
if (!empty($this->tag2)) {
$tags[] = ['text' => $this->tag2, 'color' => $this->tag2color ?? '#3498db'];
}
if (!empty($this->tag3)) {
$tags[] = ['text' => $this->tag3, 'color' => $this->tag3color ?? '#3498db'];
}
return $tags;
}
public function node()
{

View File

@@ -1,30 +0,0 @@
<?php
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('ext_proxmox_servers', function (Blueprint $table) {
// Store tags as JSON array with format: [{"text": "tag1", "color": "#ff0000"}, ...]
// Maximum 3 tags per server
$table->json('tags')->nullable()->after('user_set_icon_prefix');
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::table('ext_proxmox_servers', function (Blueprint $table) {
$table->dropColumn('tags');
});
}
};