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']); | $tenantId = \config('app.tenant_id'); | ||||
foreach (['users', 'discounts', 'domains', 'plans', 'packages', 'skus'] as $table_name) { | $tenant = \App\Tenant::create(['id' => $tenantId, 'title' => 'Kolab Now']); | ||||
foreach (['users', 'discounts', 'domains', 'plans', 'packages', 'skus'] as $tableName) { | |||||
Schema::table( | Schema::table( | ||||
$table_name, | $tableName, | ||||
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')) { | if ($tenantId) { | ||||
DB::statement("UPDATE `{$table_name}` SET `tenant_id` = {$tenant_id}"); | DB::statement("UPDATE `{$tableName}` SET `tenant_id` = {$tenantId}"); | ||||
machniak: You set $tenantId above, you don't have to read the config again and again. | |||||
} | } | ||||
} | } | ||||
// Add fee column | // Add fee column | ||||
foreach (['entitlements', 'skus'] as $table) { | foreach (['entitlements', 'skus'] as $table) { | ||||
Schema::table( | Schema::table( | ||||
$table, | $table, | ||||
function (Blueprint $table) { | function (Blueprint $table) { | ||||
$table->integer('fee')->nullable(); | $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) { | foreach (['users', 'discounts', 'domains', 'plans', 'packages', 'skus'] as $tableName) { | ||||
Schema::table( | Schema::table( | ||||
$table_name, | $tableName, | ||||
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) { | foreach (['entitlements', 'skus'] as $table) { | ||||
Show All 11 Lines |
You set $tenantId above, you don't have to read the config again and again.