0

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

Shiva
  • 11,485
  • 2
  • 67
  • 84

2 Answers2

1

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

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

bastilian
  • 9
  • 2
  • actually I know about seeding.. I wanted to know if I could detect inside the deploy hooks if this deploy attempt is the first one so that seeding only occur when needed #bastilian – Shiva Jun 03 '15 at 15:27