1
0

console 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. #!/usr/bin/env php
  2. <?php
  3. declare(strict_types=1);
  4. require __DIR__ . '/../vendor/autoload.php';
  5. $argv = $_SERVER['argv'] ?? [];
  6. $command = $argv[1] ?? null;
  7. $phinxBin = __DIR__ . '/../vendor/bin/phinx';
  8. $phinxConfig = __DIR__ . '/../config/phinx.php';
  9. $run = static function (string $phinxCommand) use ($phinxBin, $phinxConfig): never {
  10. $cmd = sprintf(
  11. '%s %s --configuration=%s',
  12. escapeshellarg($phinxBin),
  13. $phinxCommand,
  14. escapeshellarg($phinxConfig)
  15. );
  16. passthru($cmd, $exitCode);
  17. exit($exitCode);
  18. };
  19. switch ($command) {
  20. case 'db:migrate':
  21. $run('migrate');
  22. // no break
  23. case 'db:rollback':
  24. $run('rollback');
  25. // no break
  26. case 'db:seed':
  27. $run('seed:run');
  28. // no break
  29. case null:
  30. case '--help':
  31. case '-h':
  32. fwrite(STDOUT, <<<TXT
  33. Usage: console <command>
  34. Commands:
  35. db:migrate Run Phinx migrations
  36. db:rollback Roll back the most recent migration
  37. db:seed Run all seeders idempotently
  38. TXT);
  39. exit(0);
  40. default:
  41. fwrite(STDERR, "Unknown command: {$command}\n");
  42. exit(1);
  43. }