Skip to content

Data Migrations

Saray Cabrera Padrón edited this page Mar 26, 2020 · 6 revisions

In OBS codebase we differentiate migrations that only affect the database structure from migrations that modify the already existing data.

The first type are the common Rails migrations we all know.

The second type is what we call data migrations and they are occasionally needed to modify data that is already in the database. Something that shouldn't be mixed with the evolution of the database structure, so they are located in a different directory and are executed in a different way.

Table comparing both:

Migration Data Migration
Location: db/migrations/ db/data/
Generating a new migration file: rails g migration AddSomethingToSomewhere rails g data_migration ModifySomething
Run the migration: rake db:migrate rake db:migrate:with_data (after running the normal one in a previous step)
Clone this wiki locally