doctrine.php 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * Very useful script in order to create a Migration file based in the
  5. * current differences of the database:
  6. *
  7. * php bin/doctrine.php migrations:diff
  8. *
  9. * This script also show doctrine basic commands:
  10. * - Create schema
  11. * - Drop schema
  12. * - Update schema,
  13. * etc
  14. *
  15. **/
  16. use Doctrine\ORM\Tools\Console\ConsoleRunner;
  17. use Symfony\Component\Console\Helper\HelperSet;
  18. (@include_once __DIR__ . '/../vendor/autoload.php') || @include_once __DIR__ . '/../../../autoload.php';
  19. $directories = array(getcwd(), getcwd() . DIRECTORY_SEPARATOR . 'config');
  20. $configFile = null;
  21. foreach ($directories as $directory) {
  22. $configFile = $directory . DIRECTORY_SEPARATOR . 'cli-config.php';
  23. if (file_exists($configFile)) {
  24. break;
  25. }
  26. }
  27. if ( ! file_exists($configFile)) {
  28. ConsoleRunner::printCliConfigTemplate();
  29. exit(1);
  30. }
  31. if ( ! is_readable($configFile)) {
  32. echo 'Configuration file [' . $configFile . '] does not have read permission.' . "\n";
  33. exit(1);
  34. }
  35. $commands = array(
  36. new \Doctrine\DBAL\Migrations\Tools\Console\Command\DiffCommand(),
  37. new \Doctrine\DBAL\Migrations\Tools\Console\Command\ExecuteCommand(),
  38. new \Doctrine\DBAL\Migrations\Tools\Console\Command\GenerateCommand(),
  39. new \Doctrine\DBAL\Migrations\Tools\Console\Command\LatestCommand(),
  40. new \Doctrine\DBAL\Migrations\Tools\Console\Command\MigrateCommand(),
  41. new \Doctrine\DBAL\Migrations\Tools\Console\Command\StatusCommand(),
  42. new \Doctrine\DBAL\Migrations\Tools\Console\Command\VersionCommand()
  43. );
  44. $helperSet = require $configFile;
  45. if ( ! ($helperSet instanceof HelperSet)) {
  46. foreach ($GLOBALS as $helperSetCandidate) {
  47. if ($helperSetCandidate instanceof HelperSet) {
  48. $helperSet = $helperSetCandidate;
  49. break;
  50. }
  51. }
  52. }
  53. \Doctrine\ORM\Tools\Console\ConsoleRunner::run($helperSet, $commands);