fix: #58 - pivot table logo_site was broken, foreign keys were inverted

This commit is contained in:
Noah Lancien 2024-07-29 10:59:03 +02:00
parent 9065e3295a
commit d1855d8771

View file

@ -0,0 +1,44 @@
<?php
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.
*
* @return void
*/
public function up(): void
{
// The foreign keys in the database were inverted, so i needed to recreate them and reinsert the datas.
$relations = DB::table('logo_site')->get();
Schema::dropIfExists('logo_site');
Schema::create('logo_site', function (Blueprint $table) {
$table->foreignId('logo_id')->constrained()->cascadeOnUpdate()->cascadeOnDelete();
$table->foreignId('site_id')->constrained()->cascadeOnUpdate()->cascadeOnDelete();
});
foreach ($relations as $relation) {
DB::table('logo_site')->insert(
[
'logo_id' => $relation->logo_id,
'site_id' => $relation->site_id,
]
);
}
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down(): void
{
Schema::dropIfExists('logo_site');
}
};