Cайт веб-разработчика, программиста Ruby on Rails ESV Corp. Екатеринбург, Москва, Санкт-Петербург, Новосибирск, Первоуральск

Админка на Ruby on Rails

Миграция для Engine

Engine setup

The engine contains migrations for the blorgh_posts and blorgh_comments table which need to be created in the application's database so that the engine's models can query them correctly. To copy these migrations into the application use this command:

$ rake blorgh:install:migrations

If you have multiple engines that need migrations copied over, use railties:install:migrations instead:

$ rake railties:install:migrations

This command, when run for the first time will copy over all the migrations from the engine. When run the next time, it will only copy over migrations that haven't been copied over already. The first run for this command will output something such as this:
Copied migration [timestamp_1]_create_blorgh_posts.rb from blorgh
Copied migration [timestamp_2]_create_blorgh_comments.rb from blorgh

The first timestamp ([timestamp_1]) will be the current time and the second timestamp ([timestamp_2]) will be the current time plus a second. The reason for this is so that the migrations for the engine are run after any existing migrations in the application.

To run these migrations within the context of the application, simply run rake db:migrate. When accessing the engine through http://localhost:3000/blog, the posts will be empty. This is because the table created inside the application is different from the one created within the engine. Go ahead, play around with the newly mounted engine. You'll find that it's the same as when it was only an engine.

If you would like to run migrations only from one engine, you can do it by specifying SCOPE:

$ rake db:migrate SCOPE=blorgh

This may be useful if you want to revert engine's migrations before removing it. In order to revert all migrations from blorgh engine you can run such code:

$ rake db:migrate SCOPE=blorgh VERSION=0


Getting Started with Engines