Add constraint for hubs, which must have the same host and region for a zone
This commit is contained in:
parent
cb63ec50d2
commit
de34052c3b
32
database/migrations/2024_05_23_204853_address_hub.php
Normal file
32
database/migrations/2024_05_23_204853_address_hub.php
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
<?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('addresses', function (Blueprint $table) {
|
||||||
|
$table->dropForeign(['hub_id']);
|
||||||
|
$table->unique(['zone_id','region_id','host_id','id']);
|
||||||
|
$table->foreign(['zone_id','region_id','host_id','hub_id'])->references(['zone_id','region_id','host_id','id'])->on('addresses');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reverse the migrations.
|
||||||
|
*/
|
||||||
|
public function down(): void
|
||||||
|
{
|
||||||
|
Schema::table('addresses', function (Blueprint $table) {
|
||||||
|
$table->dropForeign(['zone_id','region_id','host_id','hub_id']);
|
||||||
|
$table->dropUnique(['zone_id','region_id','host_id','id']);
|
||||||
|
$table->foreign('hub_id')->references('id')->on('addresses');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
Loading…
Reference in New Issue
Block a user