What are database model migrations?

Asked

Viewed 194 times

6

Some MVC frameworks (Rails, Laravel and others) provide database model migrations. What they are, how they work and what are the advantages / disadvantages of using them?

2 answers

2

Migration is the procedure that changes the state of a database.

As well as source code, the structure of a database changes as we develop an application tied to that database. For example, throughout development, we may want to add a new table; or after a deployment routine, we note that we will need to add a new index or column. It is important that we monitor these structural changes in the database (called migrations) as we do with the source code. If the source code and database are out of sync, it is very likely that the system as a whole will start having problems.

(translated from http://www.yiiframework.com/doc/guide/1.1/pt/database.migration)

In short: suppose your application has been modeled for a state A of a database, and after inserting a certain new resource, the database had to be changed to a state B. This change occurred through a migration, which in general are a set of darlings adding columns, tables, indexes and data into the database so that it is in the format required by the application.

2

What are the advantages / disadvantages of using them?

Basically, you gain greater control of the bank’s states at different times. It can also be used in conjunction with a version control system, such as Git, so that it can be run easily by other programmers, to have the current state of the database.

Making the changes "at hand" via SQL, other users will not be able to play the changes on their machines unless they know exactly what has changed.

Like Orms, Migrations also generate the correct SQL syntax depending on the database.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.