doctrine.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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. use Doctrine\DBAL\Types\Type;
  19. (@include_once __DIR__.'/../vendor/autoload.php') || @include_once __DIR__.'/../../../autoload.php';
  20. $directories = array(getcwd(), getcwd().DIRECTORY_SEPARATOR.'config');
  21. $configFile = null;
  22. foreach ($directories as $directory) {
  23. $configFile = $directory.DIRECTORY_SEPARATOR.'cli-config.php';
  24. if (file_exists($configFile)) {
  25. break;
  26. }
  27. }
  28. if (!file_exists($configFile)) {
  29. ConsoleRunner::printCliConfigTemplate();
  30. exit(1);
  31. }
  32. if (!is_readable($configFile)) {
  33. echo 'Configuration file ['.$configFile.'] does not have read permission.'."\n";
  34. exit(1);
  35. }
  36. Type::overrideType(
  37. Type::DATETIME,
  38. Database::getUTCDateTimeTypeClass()
  39. );
  40. Type::addType(
  41. 'json',
  42. 'Sonata\Doctrine\Types\JsonType'
  43. );
  44. $commands = array(
  45. new \Doctrine\DBAL\Migrations\Tools\Console\Command\DiffCommand(),
  46. new \Doctrine\DBAL\Migrations\Tools\Console\Command\ExecuteCommand(),
  47. new \Doctrine\DBAL\Migrations\Tools\Console\Command\GenerateCommand(),
  48. new \Doctrine\DBAL\Migrations\Tools\Console\Command\LatestCommand(),
  49. new \Doctrine\DBAL\Migrations\Tools\Console\Command\MigrateCommand(),
  50. new \Doctrine\DBAL\Migrations\Tools\Console\Command\StatusCommand(),
  51. new \Doctrine\DBAL\Migrations\Tools\Console\Command\VersionCommand()
  52. );
  53. $helperSet = require $configFile;
  54. if (!($helperSet instanceof HelperSet)) {
  55. foreach ($GLOBALS as $helperSetCandidate) {
  56. if ($helperSetCandidate instanceof HelperSet) {
  57. $helperSet = $helperSetCandidate;
  58. break;
  59. }
  60. }
  61. }
  62. \Doctrine\ORM\Tools\Console\ConsoleRunner::run($helperSet, $commands);