2017-01-01 26 views
0

我在Capistrano的Ubuntu服务器上部署了Rails应用程序。但是,我正在尝试运行我创建的自定义任务,并且位于'lib/tasks'中。我试图使它工作由执行Capistrano 3.0 Rails 5.0.0数据库自定义任务

帽生产DB:观点

,如果它是一个自定义任务,但显然它没有工作

帽中止! 不知道如何建设任务“DB:若干意见”

该文件是sql_views.rake,这个任务是如果你使用cap install生成您Capfile在数据库中创建

namespace :db do 
    desc "Update and create SQL views" 
    task :views => :environment do 
    Dir["#{Rails.root}/db/sql_views/*.sql"].each do |file_name| 
     STDERR.puts "Applying the SQL view at #{file_name}" 
     source_file = File.new(file_name, 'r') 

     if source_file and (sql_content = source_file.read) 
     ActiveRecord::Base.transaction do 
      # Each statement ends with a semicolon followed by a newline. 
      sql_lines = sql_content.split(/;[ \t]*$/) 
      if sql_lines.respond_to?(:each) 
      sql_lines.each do |line| 
       ActiveRecord::Base.connection.execute "#{line};" 
      end 
      end 
     end # transaction 
     end 

    end # Dir.each 
    end # task 
end 

回答

0

意见,应该存在以下行:

# Load custom tasks from `lib/capistrano/tasks` if you have any defined 
Dir.glob("lib/capistrano/tasks/*.rake").each { |r| import r } 

因此它正在寻找lib/capistrano/tasks自定义任务。

移动lib/tasks/sql_views.rakelib/capistrano/tasks/sql_views.rake

或者只是导入每个耙子任务:

import 'lib/tasks/sql_views.rake'