2013-06-13 68 views
2

我正在使用應用程序和application_ruby食譜。而我定義我的應用程序像這樣與遷移「真」:廚師:數據庫遷移未在應用程序配方中運行

application 'railsapp' do 
    owner 'vagrant' 
    group 'vagrant' 
    path '/home/vagrant/railsapp' 
    revision 'master' 
    repository '[email protected]:rohshall/railsreadings.git' 
    migrate true 
    rails do 
    bundler true 
    database do 
     host 'localhost' 
     username mysql_connection_info[:username] 
     password mysql_connection_info[:password] 
     database 'railsreadings_production' 
     adapter 'mysql2' 
     encoding 'utf8' 
    end 
    end 
    unicorn do 
    worker_processes 2 
    end 
end 

不過,我沒有看到任何遷移運行。我認爲這是因爲application_ruby在運行後將其刪除。但是,就我而言,數據庫用戶憑據存在問題,並且遷移未成功。除了手動運行遷移之外,有沒有辦法讓它運行?

ruby_block "remove_run_migrations" do 
    block do 
     if node.role?("#{new_resource.name}_run_migrations") 
     Chef::Log.info("Migrations were run, removing role[#{new_resource.name}_run_migrations]") 
     node.run_list.remove("role[#{new_resource.name}_run_migrations]") 
     end 
    end 
end 
+0

您是否找到解決方案?請不要忘記標記答案是正確的! :) – sethvargo

回答

1

我想我遇到了同樣的問題,聲明遷移命令後,它確實有效。所以像這樣:

application 'railsapp' do 
    owner 'vagrant' 
    group 'vagrant' 
    path '/home/vagrant/railsapp' 
    revision 'master' 
    repository '[email protected]:rohshall/railsreadings.git' 
    migrate true 
    migration_command "bundle exec rake db:migrate" 
    rails do 
    bundler true 
    database do 
     host 'localhost' 
     username mysql_connection_info[:username] 
     password mysql_connection_info[:password] 
     database 'railsreadings_production' 
     adapter 'mysql2' 
     encoding 'utf8' 
    end 
    end 
    unicorn do 
    worker_processes 2 
    end 
end