|
|
@@ -0,0 +1,92 @@ |
|
|
|
|
|
<?php |
|
|
|
|
|
|
|
|
|
|
|
namespace App\Console\Commands\Migration; |
|
|
|
|
|
|
|
|
|
|
|
use App\Console\Commands\BaseCommand; |
|
|
|
|
|
use App\Models\HtpmsCustomer\HtpmsCustomerConnectionSwitch; |
|
|
|
|
|
use Exception; |
|
|
|
|
|
use Illuminate\Support\Facades\DB; |
|
|
|
|
|
use Illuminate\Support\Facades\Schema; |
|
|
|
|
|
|
|
|
|
|
|
class テンプレートマイグレーション extends BaseCommand |
|
|
|
|
|
{ |
|
|
|
|
|
|
|
|
|
|
|
const COMMAND = "migrate:template"; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* The name and signature of the console command. |
|
|
|
|
|
* |
|
|
|
|
|
* @var string |
|
|
|
|
|
*/ |
|
|
|
|
|
protected $signature = self::COMMAND; |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* The console command description. |
|
|
|
|
|
* |
|
|
|
|
|
* @var string |
|
|
|
|
|
*/ |
|
|
|
|
|
protected $description = 'テンプレートDBをマイグレーションする'; |
|
|
|
|
|
|
|
|
|
|
|
static public function getCommand() |
|
|
|
|
|
{ |
|
|
|
|
|
return self::COMMAND; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* Create a new command instance. |
|
|
|
|
|
* |
|
|
|
|
|
* @return void |
|
|
|
|
|
*/ |
|
|
|
|
|
public function __construct() |
|
|
|
|
|
{ |
|
|
|
|
|
$this->outputInfoForBase = false; |
|
|
|
|
|
parent::__construct(); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* Execute the console command. |
|
|
|
|
|
* |
|
|
|
|
|
* @return int |
|
|
|
|
|
*/ |
|
|
|
|
|
public function service(): int |
|
|
|
|
|
{ |
|
|
|
|
|
|
|
|
|
|
|
HtpmsCustomerConnectionSwitch::switchToTemplate(); |
|
|
|
|
|
|
|
|
|
|
|
$this->printMigrationStatus(); |
|
|
|
|
|
|
|
|
|
|
|
try { |
|
|
|
|
|
$this->outputInfo("start htpms_template migration"); |
|
|
|
|
|
$this->call("migrate", ["--force" => true]); // 対話OFF |
|
|
|
|
|
$this->outputInfo("end htpms_template migration"); |
|
|
|
|
|
} catch (Exception $e) { |
|
|
|
|
|
print_r(DB::getConfig()); |
|
|
|
|
|
throw $e; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return self::RESULTCODE_SUCCESS; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private function printMigrationStatus() |
|
|
|
|
|
{ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$conn = DB::connection("htpms_customer"); |
|
|
|
|
|
$config = $conn->getConfig(); |
|
|
|
|
|
$database = data_get($config, "database", "htpms_XXX"); |
|
|
|
|
|
if (!Schema::connection("htpms_customer")->hasTable("tbl3_migrations")) { |
|
|
|
|
|
$this->outputInfo(sprintf("初回マイグレーション:%s", $database)); |
|
|
|
|
|
return; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$mig = $conn->table("tbl3_migrations")->orderByDesc("id")->first(); |
|
|
|
|
|
if ($mig) { |
|
|
|
|
|
$this->outputInfo(sprintf("最新:%s:%s", $database, $mig->migration)); |
|
|
|
|
|
} else { |
|
|
|
|
|
$this->outputInfo(sprintf("最新:%s:なし", $database)); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |