Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Should I flatten Rails migrations?

It's possible to replace db/migrate/* with the contents of db/schema.rb, so that you only have one migration step.

Do any of you ever do this? Why?

like image 841
jes5199 Avatar asked Dec 15 '09 20:12

jes5199


People also ask

What is the purpose of migration in Rails?

The main purpose of Rails' migration feature is to issue commands that modify the schema using a consistent process. Migrations can also be used to add or modify data. This is useful in an existing database that can't be destroyed and recreated, such as a production database.

How does rails keep track of migrations?

Rails stores the most recent database schema in the file db/schema. rb . This file is the Ruby representation of all the migrations run on your database over the life of the application. Because of this file, we don't need to keep old migrations files in the codebase.

Are Rails migrations wrapped in a transaction?

Rails Migrations are wrapped by a database transaction by default, so if you need to disable it by any reason use disable_ddl_transaction!() .


2 Answers

Why would you want to do this? You could just run rake db:schema:load if you don't want to run all migrations. Migrations are used not (only) to initialize a new database, but to migrate it to another version.

like image 98
Tomas Markauskas Avatar answered Sep 30 '22 07:09

Tomas Markauskas


Also, some big Ruby on Rails kit packages (like that one that's slipping my mind now that lets you set up an ecommerce site in your Rails app), flatten their migrations.

I've also known of projects with a ton of migrations to do this every once in a while to reduce the amount of time it takes to run rake db:migrate start to finish (say, on the continuous integration server)

like image 21
RyanWilcox Avatar answered Sep 30 '22 07:09

RyanWilcox