Answer the question
In order to leave comments, you need to log in
How to combine all migrations into one?
The project is being developed by several programmers and more than 20 migration files have been collected over time. Is there any way to combine all migrations into one. So that when creating a database, an actual database is immediately created, and not a basis on which migrations will be imposed
Answer the question
In order to leave comments, you need to log in
Rails has a file db/schema.rb which is:
1) updated after each migration is applied
2) it is recommended to store it under version control
3) it is used to create a database schema without migrations, see the rake task db:schema:load
Migration is an iteration of changing the database, with the possibility of rollback in case of errors. Raising the issue of merging migrations into one makes sense only if this leads to unpleasant consequences, for example: raising the dev environment - it performs UP of the database for more than an hour, or in the event of a rollback, the data will be destroyed (although for such a migration, the developer needs to put a mop somewhere ), or something else. Just "many migration files" is NOT the reason.
Generally speaking, you can do the following: dump the database, and then create a separate migration that will only perform this dump.
Strictly speaking, if you use code in migrations that is no longer in the project, you need to edit such migrations yourself (or it’s better not to create them at all).
See also https://github.com/jalkoby/squasher. Haven't tried it myself, but it seems to be what you need.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question