Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

phpmig and capistrano #48

Open
lalop opened this issue Oct 1, 2013 · 5 comments
Open

phpmig and capistrano #48

lalop opened this issue Oct 1, 2013 · 5 comments

Comments

@lalop
Copy link
Contributor

lalop commented Oct 1, 2013

I'm looking to a way to handle database rollback on capistrano rollback.
One off the solution that I'm seeing is to dump migrations done in a file after each deploy.
Like that on rollback I could do a diff and rollback the newest migrations.

What do you think about that ?

Capistrano being a common deployement tools, what do you think about integrate capistrano's helper in phpmig ?

@davedevelopment
Copy link
Owner

I'm open to anything really, but if it could be used with anything other than capistrano as well, that would be useful.

How does capistrano do it for the rails migrations?

@lalop
Copy link
Contributor Author

lalop commented Oct 1, 2013

For sure it's better if that works for the maximum of deployement's tools.

By default capistrano handle rails db migration doing a simple rake db:migrate but it handle not the db rollback ( or I don't find anything on that ).

But I have found some tricks where the idea is to have the migration version in the depot and rollback to it at the migration:rollback.

What I suggest is not to have the max migration dump in a file but all the done migration, like that we can do a real migration diff between two app's version, or play with different branch on git.

Do you see what I mean ?

@davedevelopment
Copy link
Owner

I know what you mean. It's been a long time since I used capistrano, does it work with symlinks, kind of like:

releases/
    12345/
    67890/
current -> releases/67890
previous -> releases/12345

If so, could it be the case of just comparing the migrations returned from the current and previous version? I guess that could get a little complicated.

I guess the other option would be to leave some artifacts behind during deployment, e.g.

phpmig migrate -o log.json

You could then have something to parse it and work backwards through the migrations that were done as part of that migration.

@lalop
Copy link
Contributor Author

lalop commented Oct 1, 2013

Yes, it works with symlinks but only for the current path, there is no previous.

I'm for the artifacts, but two things :

  • a raw format can be more simple, no need of json here ( one line by migration version, and only this information )
  • maybe that can be directly versionned than the migration script just has to check the diff between the database and the versions in this file

Like that there is nothing done just for capistrano, all that can be done by a new command or by adding some options on the existing one.

@loftyD
Copy link

loftyD commented Nov 8, 2020

Sorry to necro an old issue, but I'm using phpmig with Capistrano, this is what I've got in my deploy.rb for my project and works rather well (as a reference point):

namespace :deploy do
    before :publishing, 'db:migrate'
end

namespace :db do
	desc 'db tasks'	
	  task :migrate do
	    on roles(:app) do
	      execute "cd #{release_path}; PROJECT_ENV=production ./vendor/bin/phpmig migrate"
	  end
	end
end

hence to rollback change ./vendor/bin/phpmig migrate to /vendor/bin/phpmig rollback so you'd have a task that looks like this:

	  task :rollback do
	    on roles(:app) do
	      execute "cd #{release_path}; PROJECT_ENV=production ./vendor/bin/phpmig rollback"
	  end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants