You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

93 satır
2.2KB

  1. <?php
  2. namespace App\Console\Commands\Migration;
  3. use App\Console\Commands\BaseCommand;
  4. use App\Models\HtpmsCustomer\HtpmsCustomerConnectionSwitch;
  5. use Exception;
  6. use Illuminate\Support\Facades\DB;
  7. use Illuminate\Support\Facades\Schema;
  8. class テンプレートマイグレーション extends BaseCommand
  9. {
  10. const COMMAND = "migrate:template";
  11. /**
  12. * The name and signature of the console command.
  13. *
  14. * @var string
  15. */
  16. protected $signature = self::COMMAND;
  17. /**
  18. * The console command description.
  19. *
  20. * @var string
  21. */
  22. protected $description = 'テンプレートDBをマイグレーションする';
  23. static public function getCommand()
  24. {
  25. return self::COMMAND;
  26. }
  27. /**
  28. * Create a new command instance.
  29. *
  30. * @return void
  31. */
  32. public function __construct()
  33. {
  34. $this->outputInfoForBase = false;
  35. parent::__construct();
  36. }
  37. /**
  38. * Execute the console command.
  39. *
  40. * @return int
  41. */
  42. public function service(): int
  43. {
  44. HtpmsCustomerConnectionSwitch::switchToTemplate();
  45. $this->printMigrationStatus();
  46. try {
  47. $this->outputInfo("start htpms_template migration");
  48. $this->call("migrate", ["--force" => true]); // 対話OFF
  49. $this->outputInfo("end htpms_template migration");
  50. } catch (Exception $e) {
  51. print_r(DB::getConfig());
  52. throw $e;
  53. }
  54. return self::RESULTCODE_SUCCESS;
  55. }
  56. private function printMigrationStatus()
  57. {
  58. $conn = DB::connection("htpms_customer");
  59. $config = $conn->getConfig();
  60. $database = data_get($config, "database", "htpms_XXX");
  61. if (!Schema::connection("htpms_customer")->hasTable("tbl3_migrations")) {
  62. $this->outputInfo(sprintf("初回マイグレーション:%s", $database));
  63. return;
  64. }
  65. $mig = $conn->table("tbl3_migrations")->orderByDesc("id")->first();
  66. if ($mig) {
  67. $this->outputInfo(sprintf("最新:%s:%s", $database, $mig->migration));
  68. } else {
  69. $this->outputInfo(sprintf("最新:%s:なし", $database));
  70. }
  71. }
  72. }