Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to manage migrations for a rails engine + dummy app

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.

like image 870
zjaquish Avatar asked Jan 22 '13 18:01

zjaquish


People also ask

How do I run a specific migration in Rails?

To run a specific migration up or down, use db:migrate:up or db:migrate:down . The version number in the above commands is the numeric prefix in the migration's filename. For example, to migrate to the migration 20160515085959_add_name_to_users. rb , you would use 20160515085959 as the version number.

How does a Rails engine work?

Engines can be considered miniature applications that provide functionality to their host applications. A Rails application is actually just a "supercharged" engine, with the Rails::Application class inheriting a lot of its behavior from Rails::Engine. Engines are the reusable rails applications/plugins.

What is Mount in rails?

Mounting rails are constructive items in electrical engineering and mechanical engineering projects; they are used to hold devices. A mounting rail is usually attached to a mounting panel or an enclosure profile.


1 Answers

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

like image 165
westonplatter Avatar answered Oct 20 '22 19:10

westonplatter