Converting database / data structure in Rails

This relates to the following question: Can Rails Migrations be used to transform data?

If I work on a branch, which, when it is reintegrated and put into production, will significantly change the database schema. What is the best way to ensure that all data in production is converted to a new format?

A simple example might be a number column, which we want to change in the text and do some data conversion work. Then we want to remove the old column.

I was advised not to do any data manipulation in migrations, but to create rake tasks for them. Is there a mechanism for rake tasks to be performed along with migrations?

Currently, the only solution I can come up with is to combine all the migrations that transfer non-existent columns into a second collection. Run the first set of migrations that add new tables. Run the rake tasks, then run the second set of migrations. This doesn’t seem like the perfect solution for me and could easily be mistaken.

+3
source share
1 answer

Migrations are designed specifically for this kind of thing. Transferring data to the database for a new version of the application with or without changing the schema should be a transfer. This is a guarantee that new changes will be made before the new version of the application.

, , . , . - () .

, , , Rake.

+2

Source: https://habr.com/ru/post/1708516/


All Articles