Populate tags for nodes

This commit is contained in:
Lance Pioch 2024-04-09 20:08:55 -04:00
parent 8ce84239e1
commit f6eede37aa
2 changed files with 23 additions and 8 deletions

View File

@ -27,6 +27,7 @@ return new class extends Migration
->update(['tags' => "[\"$egg->name\"]"]);
}
Schema::table('eggs', function (Blueprint $table) {
$table->dropForeign('service_options_nest_id_foreign');
$table->dropColumn('nest_id');
@ -44,6 +45,7 @@ return new class extends Migration
});
}
// Not really reversible, but...
public function down(): void
{
Schema::table('api_keys', function (Blueprint $table) {
@ -62,12 +64,12 @@ return new class extends Migration
Schema::table('eggs', function (Blueprint $table) {
$table->dropColumn('tags');
$table->mediumInteger('nest_id')->unsigned();
// $table->foreign(['nest_id'], 'service_options_nest_id_foreign');
$table->foreign(['nest_id'], 'service_options_nest_id_foreign');
});
Schema::table('servers', function (Blueprint $table) {
$table->mediumInteger('nest_id')->unsigned();
// $table->foreign(['nest_id'], 'servers_nest_id_foreign');
$table->foreign(['nest_id'], 'servers_nest_id_foreign');
});
if (class_exists('Database\Seeders\NestSeeder')) {

View File

@ -2,15 +2,30 @@
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
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::table('nodes', function (Blueprint $table) {
$table->text('tags');
});
DB::table('nodes')->update(['tags' => '[]']);
$nodesWithLocations = DB::table('nodes')
->select(['nodes.id', 'locations.short'])
->join('locations', 'locations.id', '=', 'nodes.location_id')
->get();
foreach ($nodesWithLocations as $node) {
DB::table('nodes')
->where('id', $node->id)
->update(['tags' => "[\"$node->short\"]"]);
}
Schema::table('nodes', function (Blueprint $table) {
$table->dropForeign('nodes_location_id_foreign');
$table->dropColumn('location_id');
@ -23,9 +38,7 @@ return new class extends Migration
});
}
/**
* Reverse the migrations.
*/
// Not really reversible, but...
public function down(): void
{
Schema::create('locations', function (Blueprint $table) {