Changeset View
Changeset View
Standalone View
Standalone View
src/database/migrations/2021_05_12_150000_groups_add_tenant_id.php
- This file was moved from src/database/migrations/2021_05_07_150000_groups_add_tenant_id.php.
<?php | <?php | ||||
use Illuminate\Database\Migrations\Migration; | use Illuminate\Database\Migrations\Migration; | ||||
use Illuminate\Database\Schema\Blueprint; | use Illuminate\Database\Schema\Blueprint; | ||||
use Illuminate\Support\Facades\DB; | |||||
use Illuminate\Support\Facades\Schema; | use Illuminate\Support\Facades\Schema; | ||||
// phpcs:ignore | // phpcs:ignore | ||||
class GroupsAddTenantId extends Migration | class GroupsAddTenantId extends Migration | ||||
{ | { | ||||
/** | /** | ||||
* Run the migrations. | * Run the migrations. | ||||
* | * | ||||
* @return void | * @return void | ||||
*/ | */ | ||||
public function up() | public function up() | ||||
{ | { | ||||
Schema::table( | Schema::table( | ||||
'groups', | 'groups', | ||||
function (Blueprint $table) { | function (Blueprint $table) { | ||||
$table->bigInteger('tenant_id')->unsigned()->default(\config('app.tenant_id'))->nullable(); | $table->bigInteger('tenant_id')->unsigned()->nullable(); | ||||
$table->foreign('tenant_id')->references('id')->on('tenants')->onDelete('set null'); | $table->foreign('tenant_id')->references('id')->on('tenants')->onDelete('set null'); | ||||
} | } | ||||
); | ); | ||||
if ($tenant_id = \config('app.tenant_id')) { | |||||
DB::statement("UPDATE `groups` SET `tenant_id` = {$tenant_id}"); | |||||
} | |||||
} | } | ||||
/** | /** | ||||
* Reverse the migrations. | * Reverse the migrations. | ||||
* | * | ||||
* @return void | * @return void | ||||
*/ | */ | ||||
public function down() | public function down() | ||||
Show All 10 Lines |