|
@@ -36,13 +36,25 @@ class CreateTenant extends Command
|
|
}
|
|
}
|
|
|
|
|
|
$this->info("creating tenant $tenantCode");
|
|
$this->info("creating tenant $tenantCode");
|
|
- Tenant::create([
|
|
|
|
|
|
+ $tenant = [
|
|
'id' => $tenantCode,
|
|
'id' => $tenantCode,
|
|
- 'tenancy_db_connection' => $this->option('db-connection') ?? config('tenancy.database.central_connection'),
|
|
|
|
- 'tenancy_db_name' => $this->option('db-name') ?? $tenantCode,
|
|
|
|
'tenancy_db_username' => $this->option('db-username') ?? $tenantCode,
|
|
'tenancy_db_username' => $this->option('db-username') ?? $tenantCode,
|
|
'tenancy_db_password' => $this->option('db-password') ?? $tenantCode,
|
|
'tenancy_db_password' => $this->option('db-password') ?? $tenantCode,
|
|
- ]);
|
|
|
|
|
|
+ ];
|
|
|
|
+ // 默认值为 tenancy.database.prefix配置 + 租户 ID +tenancy.database.suffix配置
|
|
|
|
+ if (!empty($this->option('db-name'))) {
|
|
|
|
+ $tenant['tenancy_db_name'] = $this->option('db-name');
|
|
|
|
+ }
|
|
|
|
+ // 默认值为 tenancy.database.template_connection配置
|
|
|
|
+ if (!empty($this->option('db-connection'))) {
|
|
|
|
+ $tenant['tenancy_db_connection'] = $this->option('db-connection');
|
|
|
|
+ }
|
|
|
|
+ try {
|
|
|
|
+ Tenant::create($tenant);
|
|
|
|
+ } catch (\Exception $e) {
|
|
|
|
+ // TODO: handle exception
|
|
|
|
+ $this->error("create tenant $tenantCode fail:" . $e->getMessage());
|
|
|
|
+ }
|
|
$this->info("create tenant $tenantCode success");
|
|
$this->info("create tenant $tenantCode success");
|
|
}
|
|
}
|
|
}
|
|
}
|