48 lines
1.2 KiB
PHP
48 lines
1.2 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.
|
|
*/
|
|
public function up(): void
|
|
{
|
|
Schema::table('supplier_user', function (Blueprint $table) {
|
|
$table->string('supplier_ref')->nullable();
|
|
$table->dropUnique(['id','site_id']);
|
|
$table->dropUnique(['id','supplier_id']);
|
|
$table->unique(['user_id','supplier_ref']);
|
|
});
|
|
|
|
DB::update('UPDATE supplier_user set supplier_ref=id');
|
|
DB::update('ALTER TABLE supplier_user ALTER COLUMN supplier_ref SET NOT NULL');
|
|
|
|
Schema::table('supplier_user', function (Blueprint $table) {
|
|
$table->dropColumn('id');
|
|
});
|
|
}
|
|
|
|
/**
|
|
* Reverse the migrations.
|
|
*/
|
|
public function down(): void
|
|
{
|
|
Schema::table('supplier_user', function (Blueprint $table) {
|
|
$table->string('id')->nullable();
|
|
$table->unique(['id','site_id']);
|
|
$table->unique(['id','supplier_id']);
|
|
$table->dropUnique(['user_id','supplier_ref']);
|
|
});
|
|
|
|
DB::update('UPDATE supplier_user set id=supplier_ref');
|
|
|
|
Schema::table('supplier_user', function (Blueprint $table) {
|
|
$table->dropColumn('supplier_ref');
|
|
});
|
|
}
|
|
};
|