| @@ -6,4 +6,5 @@ enum QueueName: string | |||||
| { | { | ||||
| case EMAIL = 'email'; | case EMAIL = 'email'; | ||||
| case JOB = 'job'; | case JOB = 'job'; | ||||
| case MIGRATE = 'migrate'; | |||||
| } | } | ||||
| @@ -3,12 +3,12 @@ | |||||
| namespace App\Console\Commands\Migration; | namespace App\Console\Commands\Migration; | ||||
| use App\Codes\EnvironmentName; | use App\Codes\EnvironmentName; | ||||
| use App\Codes\QueueName; | |||||
| use App\Console\Commands\BaseCommand; | use App\Console\Commands\BaseCommand; | ||||
| use App\Models\Htpms\MstCustomer; | use App\Models\Htpms\MstCustomer; | ||||
| use App\Models\HtpmsCustomer\Existing\Parking; | |||||
| use App\Models\HtpmsCustomer\HtpmsCustomerConnectionSwitch; | use App\Models\HtpmsCustomer\HtpmsCustomerConnectionSwitch; | ||||
| use Exception; | use Exception; | ||||
| use Illuminate\Database\QueryException; | |||||
| use Illuminate\Support\Facades\Artisan; | |||||
| use Illuminate\Support\Facades\DB; | use Illuminate\Support\Facades\DB; | ||||
| class 全顧客マイグレーション extends BaseCommand | class 全顧客マイグレーション extends BaseCommand | ||||
| @@ -83,7 +83,7 @@ class 全顧客マイグレーション extends BaseCommand | |||||
| // ## 暫定的に対象を絞り中 テスト中 | // ## 暫定的に対象を絞り中 テスト中 | ||||
| if (!in_array($customer->id, [1, 520], true)) { | |||||
| if (!in_array($customer->id, [1, 131, 520], true)) { | |||||
| return; | return; | ||||
| } | } | ||||
| @@ -91,15 +91,9 @@ class 全顧客マイグレーション extends BaseCommand | |||||
| $this->outputWarn(sprintf("存在しないスキーマのためスキップ htpms_%d (%s:%s)", $customer->id, $customer->customer_name, $customer->customer_id)); | $this->outputWarn(sprintf("存在しないスキーマのためスキップ htpms_%d (%s:%s)", $customer->id, $customer->customer_name, $customer->customer_id)); | ||||
| return; | return; | ||||
| } | } | ||||
| HtpmsCustomerConnectionSwitch::switch($customer->id); | |||||
| try { | try { | ||||
| $this->outputInfo(sprintf("start htpms_%d migration (%s:%s) ", $customer->id, $customer->customer_name, $customer->customer_id)); | |||||
| $this->call("migrate", ["--force" => true]); | |||||
| $this->outputInfo(sprintf("end htpms_%d migration (%s:%s)", $customer->id, $customer->customer_name, $customer->customer_id)); | |||||
| Artisan::queue("migrate:customer", ["customerId" => $customer->id]) | |||||
| ->onQueue(QueueName::MIGRATE->value); | |||||
| } catch (Exception $e) { | } catch (Exception $e) { | ||||
| print_r(DB::getConfig()); | print_r(DB::getConfig()); | ||||
| throw $e; | throw $e; | ||||
| @@ -0,0 +1,97 @@ | |||||
| <?php | |||||
| namespace App\Console\Commands\Migration; | |||||
| use App\Console\Commands\BaseCommand; | |||||
| use App\Models\Htpms\MstCustomer; | |||||
| use App\Models\HtpmsCustomer\HtpmsCustomerConnectionSwitch; | |||||
| use Exception; | |||||
| use Illuminate\Support\Facades\DB; | |||||
| use Illuminate\Support\Facades\Schema; | |||||
| class 顧客マイグレーション extends BaseCommand | |||||
| { | |||||
| const COMMAND = "migrate:customer {customerId}"; | |||||
| /** | |||||
| * The name and signature of the console command. | |||||
| * | |||||
| * @var string | |||||
| */ | |||||
| protected $signature = self::COMMAND; | |||||
| /** | |||||
| * The console command description. | |||||
| * | |||||
| * @var string | |||||
| */ | |||||
| protected $description = '顧客毎テーブルをマイグレーションする'; | |||||
| 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 | |||||
| { | |||||
| $customerId = $this->argument("customerId"); | |||||
| $customer = MstCustomer::query() | |||||
| ->whereId($customerId) | |||||
| ->firstOrFail(); | |||||
| HtpmsCustomerConnectionSwitch::switch($customerId); | |||||
| $this->printMigrationStatus(); | |||||
| try { | |||||
| $this->outputInfo(sprintf("start htpms_%d migration (%s:%s) ", $customer->id, $customer->customer_name, $customer->customer_id)); | |||||
| $this->call("migrate", ["--force" => true]); | |||||
| $this->outputInfo(sprintf("end htpms_%d migration (%s:%s)", $customer->id, $customer->customer_name, $customer->customer_id)); | |||||
| } 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)); | |||||
| } | |||||
| } | |||||
| } | |||||
| @@ -37,6 +37,7 @@ return [ | |||||
| 'database' => [ | 'database' => [ | ||||
| 'driver' => 'database', | 'driver' => 'database', | ||||
| 'table' => 'tbl3_jobs', | 'table' => 'tbl3_jobs', | ||||
| 'connection' => 'htpms', | |||||
| 'queue' => 'default', | 'queue' => 'default', | ||||
| 'retry_after' => 90, | 'retry_after' => 90, | ||||
| 'after_commit' => false, | 'after_commit' => false, | ||||
| @@ -102,7 +103,7 @@ return [ | |||||
| 'failed' => [ | 'failed' => [ | ||||
| 'driver' => env('QUEUE_FAILED_DRIVER', 'database-uuids'), | 'driver' => env('QUEUE_FAILED_DRIVER', 'database-uuids'), | ||||
| 'database' => env('DB_CONNECTION', 'mysql'), | |||||
| 'database' => "htpms", | |||||
| 'table' => 'tbl3_failed_jobs', | 'table' => 'tbl3_failed_jobs', | ||||
| ], | ], | ||||