laravel / ideas

Issues board used for Laravel internals discussions.
938 stars 28 forks source link

Make db schema dump migration work independent of mysql command #2638

Open hugotiburtino opened 3 years ago

hugotiburtino commented 3 years ago

Developing with docker-compose got the following error:

$ docker-compose exec app php artisan migrate --seed --path=/database/migrations/legacy
Migration table created successfully.
Loading stored database schema: /var/www/html/database/schema/mysql-schema.dump

   Symfony\Component\Process\Exception\ProcessFailedException 

  The command "mysql  --user="${:LARAVEL_LOAD_USER}" --password="${:LARAVEL_LOAD_PASSWORD}" --host="${:LARAVEL_LOAD_HOST}" --port="${:LARAVEL_LOAD_PORT}" --database="${:LARAVEL_LOAD_DATABASE}" < "${:LARAVEL_LOAD_PATH}"" failed.

Exit Code: 127(Command not found)

Working directory: /var/www/html

Output:
================

Error Output:
================
sh: 1: mysql: not found

  at vendor/symfony/process/Process.php:267
    263▕      */
    264▕     public function mustRun(callable $callback = null, array $env = []): self
    265▕     {
    266▕         if (0 !== $this->run($callback, $env)) {
  ➜ 267▕             throw new ProcessFailedException($this);
    268▕         }
    269▕ 
    270▕         return $this;
    271▕     }

      +19 vendor frames 
  20  artisan:37
      Illuminate\Foundation\Console\Kernel::handle(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))

That happens because the app container does not have mysql server, which is run in another container.

Desired change:

michaeldyrynda commented 3 years ago

You ought to be able to add the mysql-client package stand-alone to the server into the app container, without installing the server package i.e. apt install mysql-client

This will allow your app container to talk to MySQL, without having to bring in the database itself.

hugotiburtino commented 3 years ago

That is indeed a simple and elegant solution. At the error handling there could be such suggestion.

Even though, it would be good if the command wouldn't need that external dependency.