Engineyard 部署:如何在 deployhooks 中检测到它是第一次尝试执行 'rake db:seed'
Engineyard Deployment: How to detect in deployhooks that its the first attempt to execute 'rake db:seed'
我无法检测到这是服务器实例启动后 部署 的第一次尝试。我只需要第一次 运行 命令 rake db:seed
来设置数据库中的默认用户和其他详细信息。我不知道这是否可能。
谁能帮帮我
有几种方法可以做到这一点。
最简单的方法是在 db/seeds.rb
中执行此操作并查询数据是否已经存在,否则在 运行ning 时会被覆盖。
如果完成,您可以 运行 rake db:seed
在部署挂钩中。
您可以在此处找到有关部署挂钩的文档:https://support.cloud.engineyard.com/hc/en-us/articles/205407008-Use-Ruby-Deploy-Hooks
最好的查找方法是发送 --extra-deploy-hook-options
while 运行 部署命令并检查 after_migrate.rb
是否存在 config[:initial]
。该命令看起来像
ey deploy -e myapp_staging --config=initial:true
after_migrate.rb 钩子看起来像:
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
更多信息ey help deploy
我无法检测到这是服务器实例启动后 部署 的第一次尝试。我只需要第一次 运行 命令 rake db:seed
来设置数据库中的默认用户和其他详细信息。我不知道这是否可能。
谁能帮帮我
有几种方法可以做到这一点。
最简单的方法是在 db/seeds.rb
中执行此操作并查询数据是否已经存在,否则在 运行ning 时会被覆盖。
如果完成,您可以 运行 rake db:seed
在部署挂钩中。
您可以在此处找到有关部署挂钩的文档:https://support.cloud.engineyard.com/hc/en-us/articles/205407008-Use-Ruby-Deploy-Hooks
最好的查找方法是发送 --extra-deploy-hook-options
while 运行 部署命令并检查 after_migrate.rb
是否存在 config[:initial]
。该命令看起来像
ey deploy -e myapp_staging --config=initial:true
after_migrate.rb 钩子看起来像:
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
更多信息ey help deploy