Page MenuHomePhorge

2020_05_05_095212_create_tenants_table.php
No OneTemporary

Size
2 KB
Referenced Files
None
Subscribers
None

2020_05_05_095212_create_tenants_table.php

<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
// phpcs:ignore
class CreateTenantsTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create(
'tenants',
function (Blueprint $table) {
$table->bigIncrements('id');
$table->string('title', 32);
$table->timestamps();
}
);
$tenantId = \config('app.tenant_id');
$tenant = \App\Tenant::create(['id' => $tenantId, 'title' => 'Kolab Now']);
foreach (['users', 'discounts', 'domains', 'plans', 'packages', 'skus'] as $tableName) {
Schema::table(
$tableName,
function (Blueprint $table) {
$table->bigInteger('tenant_id')->unsigned()->nullable();
$table->foreign('tenant_id')->references('id')->on('tenants')->onDelete('set null');
}
);
if ($tenantId) {
DB::statement("UPDATE `{$tableName}` SET `tenant_id` = {$tenantId}");
}
}
// Add fee column
foreach (['entitlements', 'skus'] as $table) {
Schema::table(
$table,
function (Blueprint $table) {
$table->integer('fee')->nullable();
}
);
}
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
foreach (['users', 'discounts', 'domains', 'plans', 'packages', 'skus'] as $tableName) {
Schema::table(
$tableName,
function (Blueprint $table) {
$table->dropForeign(['tenant_id']);
$table->dropColumn('tenant_id');
}
);
}
foreach (['entitlements', 'skus'] as $table) {
Schema::table(
$table,
function (Blueprint $table) {
$table->dropColumn('fee');
}
);
}
Schema::dropIfExists('tenants');
}
}

File Metadata

Mime Type
text/x-php
Expires
Mon, Oct 19, 10:09 PM (1 d, 10 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
1548304
Default Alt Text
2020_05_05_095212_create_tenants_table.php (2 KB)

Event Timeline