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

Why does rails:db_migrate run on the previous release? #300

Closed
ivanyv opened this issue Apr 7, 2015 · 7 comments
Closed

Why does rails:db_migrate run on the previous release? #300

ivanyv opened this issue Apr 7, 2015 · 7 comments

Comments

@ivanyv
Copy link

ivanyv commented Apr 7, 2015

Forgive me if I'm missing something obvious (though I think not, I've been reading the docs and source), but why does rails:db_migrate run on the current directory before linking to the new version?

Shouldn't there be a release_path property where it should be run?

@ivanyv ivanyv changed the title rails:db_migrate on previous release? Why does rails:db_migrate run on the previous release? Apr 7, 2015
@d4be4st
Copy link
Member

d4be4st commented Apr 7, 2015

if you are running the default deploy.rb script that mina generates, db_migrate is run in default scope

    task :deploy => :environment do
      deploy do
        ...
        invoke :'rails:db_migrate'
        ...
      end
    end

this will end up in command(:default) array. If you then take a look at deploy.sh.erb you will see that that command array is run inside $build_path directory

    <% prepare = commands(:default).map { |s| "(\n\n#{indent 2, s}\n\n)" }.join(" && ") %>
    ...
    (
      echo "-----> Creating a temporary build path"
      <%= echo_cmd %[touch "#{lock_file}"] %> &&
      <%= echo_cmd %[mkdir -p "$build_path"] %> &&
      <%= echo_cmd %[cd "$build_path"] %> &&
      (
    <%= indent 4, (prepare.empty? ? "true" : prepare) %>
      )
    ) &&

@ivanyv
Copy link
Author

ivanyv commented Apr 7, 2015

That's what I thought, but look at this line in the https://github.com/mina-deploy/mina/blob/master/lib/mina/rails.rb#L72 file:

queue echo_cmd %[cd "#{deploy_to!}/#{current_path!}" && #{command} #{arguments}]

Doesn't that specifically make the commands run on the current path, i.e., the previous release?

@d4be4st
Copy link
Member

d4be4st commented Apr 7, 2015

That lambda is not used inside tasks which are used for db_migrate or other which are invoked in deploy script.

This one is used in deploy script:
https://github.com/mina-deploy/mina/blob/master/lib/mina/rails.rb#L108

@ivanyv
Copy link
Author

ivanyv commented Apr 7, 2015

Ah, confusing but I'm beginning to understand.

Still, say I want to run my own commands inside the build_path? I haven't found a way of doing that yet :(

@d4be4st
Copy link
Member

d4be4st commented Apr 7, 2015

Just queue/invoke them among others in deploy do block

    task :deploy => :environment do
      deploy do
        ...
        queue "command my_something"
        invoke :'rails:db_migrate'
        ...
      end
    end

@ivanyv
Copy link
Author

ivanyv commented Apr 7, 2015

That was what I tried. I will test this further, maybe it's a difference between invoking a task and using queue directly.

@ivanyv
Copy link
Author

ivanyv commented Apr 8, 2015

I'm not sure what I was doing wrong before, but it seems you're 100% right. Sorry for the time waster!

@ivanyv ivanyv closed this as completed Apr 8, 2015
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

2 participants