Address input fixes, region_id/host_id must not be null, address constraints changes

This commit is contained in:
Deon George
2021-06-25 16:42:12 +10:00
parent 848f41b382
commit 1f04f8374e
6 changed files with 77 additions and 13 deletions

View File

@@ -0,0 +1,46 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class AddSoftdeletesToAddresses extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('addresses', function (Blueprint $table) {
$table->dropUnique(['zone_id','region_id','host_id','node_id']);
$table->dropUnique(['zone_id','host_id','node_id','point_id']);
$table->integer('hub_id')->nullable();
$table->foreign('hub_id')->references('id')->on('addresses');
$table->softDeletes();
});
DB::statement("ALTER TABLE addresses ALTER COLUMN region_id set NOT NULL");
DB::statement("ALTER TABLE addresses ALTER COLUMN host_id set NOT NULL");
DB::statement("CREATE UNIQUE INDEX active_addresses ON addresses (zone_id,region_id,host_id,node_id,point_id) WHERE active = true");
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('addresses', function (Blueprint $table) {
$table->dropSoftDeletes();
$table->dropForeign(['hub_id']);
$table->dropColumn('hub_id');
$table->dropIndex('active_addresses');
$table->unique(['zone_id','region_id','host_id','node_id']);
$table->unique(['zone_id','host_id','node_id','point_id']);
});
}
}