Engineyard Deployment: How to detect in deployhooks that its the first attempt to execute 'rake db:seed'

125 views Asked by At

I am having trouble to detect that this is the first attempt of deployment after a server instance is booted. I need to run the command rake db:seed only the first time to set the default users and other details in database. I have no idea if this is possible.

can anybody help me please

2

There are 2 answers

0
ananta lamichhane On BEST ANSWER

The best way to find out is by sending --extra-deploy-hook-options while running deployment command and check in the after_migrate.rb if config[:initial] is present or not. The command would look like

  ey deploy -e myapp_staging --config=initial:true

after_migrate.rb hook will looks like:

on_app_servers do
  if config[:initial] == 'true'
    $stderr.puts "Seeding the data"
    run "cd #{config.release_path}"
    run "bundle exec rake db:seed"
  else
    $stderr.puts "Skipping the Seeding process"
   end
end

For more information ey help deployenter image description here

1
bastilian On

There are a few ways you can do this.

The most simple one would be to do this in db/seeds.rb and query if data already exists that would otherwise be overwritten when running.

If that is done you can run rake db:seed in a deploy hook. You can find documentation on deploy hooks here: https://support.cloud.engineyard.com/hc/en-us/articles/205407008-Use-Ruby-Deploy-Hooks