[RUBY] Understand migration in rails
As I was studying Ruby on Rails, I didn't understand various words and concepts related to data manipulation, so I will organize them as a memorandum.
Questions about migration h2>
While studying Rails, I had the following questions.
Part 1 What are migrations, models, and migration files in the first place?
Part 2 When do you migrate?
Part 3 What do you create a migration file for? b>
I will think about each while organizing.
Part 1 What are migrations, models, and migration files in the first place? h2>
When manipulating data with Rails, the terms "migration," "model," and "migration file" come up. If you continue studying without understanding the meaning of the terms, you will always come across the question, "What does this mean?" (Me too, I was like that)
Therefore, I decided to deepen my understanding of the terms once again.
In a word, it looks like this.
A class that manipulates data. Define for each table </ b>
Rewrite the table design document </ b>
● Migration file
A description of how to rewrite the design document </ b>
Let's take a closer look.
● Model h3>
Rails uses a design pattern called MVC. The image looks like an image.
While each component has its own role, the role of the model is data and business logic. Especially used for database operations. Here is the logic for the operation. In rails, models are defined in the form of classes.
Models are created for each table, and operations such as creating and deleting tables are performed through each model. (Image like in a purple balloon)
● Migration h3>
The word migration means "migration" in English.
And "migration" in Rails means "changing the schema of the table".
By the way, the schema is "a design document that determines the outline of the table", so more roughly speaking, migration is "changing the design document of the table" b>.
● Migration file h3>
Rails uses a "migration file" when migrating.
In the file, define how you want to change the schema and make the changes based on this file.