How can PHP doctrine/phinx migrations be deployed?

765 Views Asked by At

I am trying to setup a fairly simple CI/CD toolchain in TravisCI for a PHP project using composer libraries, resulting in deployment on a baremetal server via rsync. Steps are:

  1. Getting the code from the Github Repo upon git push.
  2. Run composer install to get the dependencies.
  3. (Perform Unit tests - Integration tests) - Not setup yet
  4. Lint, codequality steps
  5. Deploy the code to a remote apache server via rsync, using ssh keys.

Toolchain works OK so far, but I can't seem to get my head around on how the SQL migrations (in Doctrine or Phinx) can be executed automatically on the remote server.

Is the strategy of executing doctrine:migrations:migrate via ssh as the last step on the deploy section of TravisCI the best choice, or is there another better option? How do you deploy your migrations?

Thanks a lot

1

There are 1 best solutions below

0
On

I once deployed to Heroku using Travis.

It was for a project using Laravel.

Because Heroku is sofisticated I have been able to tell it (from its configuration) to migrate your database after you have deployed.

However, with a classic rsync server you would need to connect to it from travis using SSH in order to migrate. (If your are as lazy as me and want to automate everything).

According to this doc you can add a after_deploy or after_success step. From this step you would run your ssh commands and migrate your database.

Apparently you can even run commands or a script via ssh so it might not be that hard. Look at the following: https://www.shellhacks.com/ssh-execute-remote-command-script-linux/

You have to pay EXTRA attention at what you put in your github repo in order to avoid security troubles with your rsync server.

Whether use this way to provide credentials to your Travis Job or that way