Changeset View
Changeset View
Standalone View
Standalone View
src/database/migrations/2020_05_05_095212_create_tenants_table.php
Show All 17 Lines | public function up() | ||||
'tenants', | 'tenants', | ||||
function (Blueprint $table) { | function (Blueprint $table) { | ||||
$table->bigIncrements('id'); | $table->bigIncrements('id'); | ||||
$table->string('title', 32); | $table->string('title', 32); | ||||
$table->timestamps(); | $table->timestamps(); | ||||
} | } | ||||
); | ); | ||||
\App\Tenant::create(['title' => 'Kolab Now']); | |||||
foreach (['users', 'discounts', 'domains', 'plans', 'packages', 'skus'] as $table_name) { | |||||
Schema::table( | Schema::table( | ||||
'users', | $table_name, | ||||
function (Blueprint $table) { | function (Blueprint $table) { | ||||
$table->bigInteger('tenant_id')->unsigned()->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 `{$table_name}` SET `tenant_id` = {$tenant_id}"); | |||||
} | |||||
} | |||||
// Add fee column | |||||
foreach (['entitlements', 'skus'] as $table) { | |||||
Schema::table( | |||||
$table, | |||||
function (Blueprint $table) { | |||||
$table->integer('fee')->nullable(); | |||||
} | |||||
); | |||||
} | |||||
// FIXME: Should we also have package_skus.fee ? | |||||
// We have package_skus.cost, but I think it is not used anywhere. | |||||
} | } | ||||
/** | /** | ||||
* Reverse the migrations. | * Reverse the migrations. | ||||
* | * | ||||
* @return void | * @return void | ||||
*/ | */ | ||||
public function down() | public function down() | ||||
{ | { | ||||
foreach (['users', 'discounts', 'domains', 'plans', 'packages', 'skus'] as $table_name) { | |||||
Schema::table( | Schema::table( | ||||
'users', | $table_name, | ||||
function (Blueprint $table) { | function (Blueprint $table) { | ||||
$table->dropForeign(['tenant_id']); | $table->dropForeign(['tenant_id']); | ||||
$table->dropColumn('tenant_id'); | $table->dropColumn('tenant_id'); | ||||
} | } | ||||
); | ); | ||||
} | |||||
foreach (['entitlements', 'skus'] as $table) { | |||||
Schema::table( | |||||
$table, | |||||
function (Blueprint $table) { | |||||
$table->dropColumn('fee'); | |||||
} | |||||
); | |||||
} | |||||
Schema::dropIfExists('tenants'); | Schema::dropIfExists('tenants'); | ||||
} | } | ||||
} | } |