C
C
Ciscoridze2014-08-21 20:42:46
Ruby on Rails
Ciscoridze, 2014-08-21 20:42:46

Do you need add/remove columns files after migration (Rails)?

Are Rails migration files generated by rails g migration AddXXXToXXX or RemoveXXXtoXXX required after database migration? And if they are needed, then why, because the columns have already been added / removed?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Sergey Krasnodemsky, 2014-08-21
@Ciscoridze

Needed in order to raise the project to another developer or to you on another machine, for example, for a staging server with test data.
The structure of the database is stored along with the code.
Migrations do not depend on the type of database, in production, for example, PosgreSQL - locally SQLite.
It can be very expensive to carry a large database in the form of backups around the machines (especially if these are completely different databases, as in my example above).
In addition, the task of migrations is to have a quick way to roll back changes in the database a few steps back / forward, to a certain stage of development.
Including up to a certain version - rake db:rollback VERSION=X
This is the main part of the arguments, read the office. documentation on migrations and best practices.
There is also a workaround with the database schema, you can raise the database from a single migration, having previously created it.

C
Ciscoridze, 2014-08-21
@Ciscoridze

I can ask you another question so as not to create a separate topic: when deploying to heroku, I filled in all the migration files, tried to do heroku run rake db:migrate. An error occurs - column XXX is already present in the UUU table. I had to delete some of the migration files for which heroku cursed. But some had to be left - without them, the application did not work, because. There were NO corresponding columns in the table, but everything was fine in the development environment. And so a question - why some columns were, and some were not? And was it possible to somehow do without deleting the migration files?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question