Populate new tags
This commit is contained in:
		
							parent
							
								
									2e3d17b94a
								
							
						
					
					
						commit
						8ce84239e1
					
				| @ -139,6 +139,7 @@ class Egg extends Model | ||||
|             'features' => 'array', | ||||
|             'docker_images' => 'array', | ||||
|             'file_denylist' => 'array', | ||||
|             'tags' => 'array', | ||||
|         ]; | ||||
|     } | ||||
| 
 | ||||
|  | ||||
| @ -3,12 +3,30 @@ | ||||
| use Illuminate\Database\Migrations\Migration; | ||||
| use Illuminate\Database\Schema\Blueprint; | ||||
| use Illuminate\Support\Facades\Artisan; | ||||
| use Illuminate\Support\Facades\DB; | ||||
| use Illuminate\Support\Facades\Schema; | ||||
| 
 | ||||
| return new class extends Migration | ||||
| { | ||||
|     public function up(): void | ||||
|     { | ||||
|         Schema::table('eggs', function (Blueprint $table) { | ||||
|             $table->text('tags'); | ||||
|         }); | ||||
| 
 | ||||
|         DB::table('eggs')->update(['tags' => '[]']); | ||||
| 
 | ||||
|         $eggsWithNests = DB::table('eggs') | ||||
|             ->select(['eggs.id', 'nests.name']) | ||||
|             ->join('nests', 'nests.id', '=', 'eggs.nest_id') | ||||
|             ->get(); | ||||
| 
 | ||||
|         foreach ($eggsWithNests as $egg) { | ||||
|             DB::table('eggs') | ||||
|                 ->where('id', $egg->id) | ||||
|                 ->update(['tags' => "[\"$egg->name\"]"]);
 | ||||
|         } | ||||
| 
 | ||||
|         Schema::table('eggs', function (Blueprint $table) { | ||||
|             $table->dropForeign('service_options_nest_id_foreign'); | ||||
|             $table->dropColumn('nest_id'); | ||||
| @ -42,13 +60,14 @@ 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')) { | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 Lance Pioch
						Lance Pioch