osb/database/migrations/2024_07_23_210016_update_supplier_user.php
Deon George cb9be6534f
All checks were successful
Create Docker Image / Build Docker Image (x86_64) (push) Successful in 33s
Create Docker Image / Final Docker Image Manifest (push) Successful in 9s
Move user suppliers to account suppliers
2024-07-23 22:17:09 +10:00

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');
});
}
};