Capistrano 3.0 Rails 5.0.0数据库自定义任务



我已经在使用Capistrano的Ubuntu Server上部署了一个Rails应用程序。但是,我正在尝试运行我创建的自定义任务,并且正在" LIB/TASKS"中。我试图通过执行

来使其起作用

CAP生产DB:视图

好像这是一项自定义任务,但显然它没有起作用

帽子中止了! 不知道如何构建任务'db:views'

文件是sql_views.rake,此任务用于数据库中的创建视图

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

如果使用cap install生成Capfile,则应存在以下行:

# 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.rake移至lib/capistrano/tasks/sql_views.rake

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

import 'lib/tasks/sql_views.rake'

最新更新