osb/database/migrations/2022_08_06_140410_supplier_constraint.php
2022-08-10 15:30:39 +10:00

47 lines
1.1 KiB
PHP

<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('supplier_details', function (Blueprint $table) {
$table->foreign(['supplier_id'])->references(['id'])->on('suppliers');
});
Schema::create('supplier_user', function (Blueprint $table) {
$table->integer('site_id')->unsigned();
$table->integer('supplier_id')->unsigned();
$table->integer('user_id')->unsigned();
$table->string('id');
$table->dateTime('created_at');
$table->unique(['supplier_id','user_id']);
$table->foreign(['supplier_id'])->references(['id'])->on('suppliers');
$table->foreign(['user_id','site_id'])->references(['id','site_id'])->on('users');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('supplier_details', function (Blueprint $table) {
$table->dropForeign(['supplier_id']);
});
Schema::dropIfExists('supplier_user');
}
};