根据这篇描述如何使用 Sprockets 编写小型 SQL 清单文件的文章,我在每个rake db:migrate
. 在最后一次升级到 Rails 5.1 之前,这工作得很好
突然清单文件被编译,但是每*= require
一条语句都被忽略了,我最终得到了一个空的清单文件。我已经尝试了几种注释样式DirectiveProcessor
,有和没有文件扩展名,有和没有相对路径。无论我提供什么,我最终都会得到一个通过数据库执行的空文件。
我的设置
db/functions/application.sql
/*
* This is a manifest file that'll be compiled into application.sql, which will include all the files
* from db/functions listed below.
*
*= require kill_all_connections.sql
*= require invalidate_emails.sql
*
*= require days_until_birthday.sql
*/
lib/tasks/db_functions.rake
namespace :db do
desc 'creates DB functions listed in db/functions.sql'
task :functions => :environment do
sprocket_env = Sprockets::Environment.new do |env|
env.register_mime_type('text/sql', '.sql')
env.register_processor('text/sql', Sprockets::DirectiveProcessor)
env.append_path 'db/functions'
end
ActiveRecord::Base.connection.execute(sprocket_env['application.sql'].to_s)
end
end
我的结果
执行时查看控制台rails db:functions
,我看到以下内容:
(69.2ms) /*
* This is a manifest file that'll be compiled into application.sql, which will include all the files
* from db/functions listed below.
*
*
*/
所以文件被执行但看起来是空的......有人有什么想法吗?