pmu*_*ens 3 ruby rake ruby-on-rails ruby-on-rails-3
我现在正在开发一个装有引擎的 Rails 应用程序。
我认为编写 rake tast 代码是个好主意,它将从引擎复制迁移并运行 rake db:migrate。
但是,如果我在engines-Arry(见下文)中只使用一个引擎运行rake任务,rake tast将从引擎复制迁移并迁移数据库。但是如果我将另一个引擎添加到数组中,rake-Task 将不再起作用。
namespace :work_in_progress do
desc 'Migrate the engines db tables'
task migrate_migrations_from_engines: :environment do
# The array with the available engines (just add the new engine here)
engines = [
'engine_one',
'engine_two'
]
puts 'Migrating migrations from engines...'
engines.each do |engine|
puts 'Copying migrations from ' + engine
Rake::Task[engine + ':install:migrations'].invoke
end
puts 'Migrating the database...'
Rake::Task['db:migrate'].invoke
puts 'Done...'
end
end
Run Code Online (Sandbox Code Playgroud)
如何改进上面的脚本,以便可以迁移多个引擎?是否还有其他脚本可以解决此问题(从 Engines 复制迁移并运行它们?)?
非常感谢!
菲利普
您必须运行 rake 任务来安装迁移,然后运行它们。试试这个代码来执行任务:
namespace :work_in_progress do
desc 'Migrate the engines db tables'
task migrate_migrations_from_engines: :environment do
# The array with the available engines (just add the new engine here)
engines = ['engine_one','engine_two']
puts 'Migrating migrations from engines...'
engines.each do |engine|
puts 'Copying migrations from ' + engine
`bundle exec rake #{engine}:install:migrations`
end
puts 'Migrating the database...'
`bundle exec rake db:migrate`
puts 'Done...'
end
end
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
606 次 |
| 最近记录: |