How to manage migrations for a rails engine + dummy app

丶灬走出姿态 提交于 2019-12-10 03:36:21

问题


I just joined a project developing a rails engine, that also has a dummy app for testing.

foo/
foo/spec/dummy/

There are identical migrations in

foo/db/migrate/
foo/spec/dummy/db/migrate/

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) Are the Rakefiles borked? (should db:migrate recurse down to the dummy app?)

Q2) Should the migrations only be in one directory? If so, which one?

We are using Rails 3.2.9, ruby 1.9.3p194.


回答1:


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'

Here's more detailed example rakefile, https://github.com/twinge/questionnaire_engine/blob/engine2/Rakefile

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.

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.

Example Engine
https://github.com/twinge/questionnaire_engine/tree/engine2



来源:https://stackoverflow.com/questions/14465754/how-to-manage-migrations-for-a-rails-engine-dummy-app

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!