问题描述
我刚刚加入了一个开发 rails 引擎的项目,该项目也有一个用于测试的虚拟应用程序.
I just joined a project developing a rails engine, that also has a dummy app for testing.
foo/
foo/spec/dummy/
在
foo/db/migrate/
foo/spec/dummy/db/migrate/
如果我 rake db:migrate
从虚拟应用程序中,一切都很好.如果我从引擎执行相同操作(当前目录 = foo),我会收到关于多个同名迁移的错误.
If I rake db:migrate
from the dummy app, all is well. If I do the same from the engine (current directory = foo) I get an error about multiple migrations with the same name.
Q1) Rakefiles 是否被破坏了?(应该 db:migrate
递归到虚拟应用程序吗?)
Q1) Are the Rakefiles borked? (should db:migrate
recurse down to the dummy app?)
Q2) 迁移应该只在一个目录中吗?如果有,是哪一个?
Q2) Should the migrations only be in one directory? If so, which one?
我们使用的是 Rails 3.2.9,ruby 1.9.3p194.
We are using Rails 3.2.9, ruby 1.9.3p194.
推荐答案
问题 1
Rakefile 应该有一个条目来说明规范/虚拟应用程序.例如,
Question 1
The Rakefile should have an entry to account for the spec/dummy app. For example,
Bundler::GemHelper.install_tasks
APP_RAKEFILE = File.expand_path("../spec/dummy/Rakefile", __FILE__)
load 'rails/tasks/engine.rake'
这里有更详细的 rakefile 示例,https://github.com/twinge/questionnaire_engine/blob/engine2/Rakefile
Here's more detailed example rakefile, https://github.com/twinge/questionnaire_engine/blob/engine2/Rakefile
问题 2
IMO,迁移应该只存在于 foo/db/migrate 文件夹中,不 foo/spec/dummy/db/migrate.事实上,我不会对虚拟的 db/migrate 或 db/schema 进行版本控制.
Question 2
IMO, the migrations should only exist on the foo/db/migrate folder, and not the foo/spec/dummy/db/migrate. In fact, I don't version control the dummy's db/migrate or the db/schema.
为什么?我使用虚拟应用程序确保完全安装我的引擎工作 100%.因此,如果我对 foo/spec/dummy db 状态进行版本控制,我会像以前安装一样进行测试.
Why? I use the dummy app the make sure a full on install of my engine works 100%. Therefore, if I version controlled the foo/spec/dummy db state, I would be testing as if there was a previous install.
示例引擎
https://github.com/twinge/questionnaire_engine/tree/engine2
这篇关于如何管理 Rails 引擎 + 虚拟应用程序的迁移的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!