Page MenuHomePhorge

2021_05_12_150000_groups_add_tenant_id.php
No OneTemporary

Size
1 KB
Referenced Files
None
Subscribers
None

2021_05_12_150000_groups_add_tenant_id.php

<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Schema;
// phpcs:ignore
class GroupsAddTenantId extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table(
'groups',
function (Blueprint $table) {
$table->bigInteger('tenant_id')->unsigned()->nullable();
$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.
*
* @return void
*/
public function down()
{
Schema::table(
'groups',
function (Blueprint $table) {
$table->dropForeign(['tenant_id']);
$table->dropColumn('tenant_id');
}
);
}
}

File Metadata

Mime Type
text/x-php
Expires
Fri, May 1, 5:07 PM (1 d, 18 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
644049
Default Alt Text
2021_05_12_150000_groups_add_tenant_id.php (1 KB)

Event Timeline