ruby-on-railsrubyactiverecordsinatrasinatra-activerecord

Migrations: What is actually moving from point A to point B in migrations?


In Active Record, when we deal with migrations, what exactly is moving? When I think of migrations, I think of something moving from point A to point B like the common meaning in English. I haven't been able to see what is moving in my research.


Solution

  • A migration in the context of database migrations is more of an abstract concept than data being "moved" around. In a database migration, we conceptualize the database being in state A and "migrating" to state B.

    Take for example, when we add a new field to a table. The table during state A is:

    ID | Field1 | Field2
    1  | foo    | bar
    2  | foo2   | bar2
    

    When we add the field, data is not being literally moved, but we can conceptualize that the data is "moving" or "migrating" from the above state A to the new table state of B:

    ID | Field1 | Field2 | Field3
    1  | foo    | bar    | nil
    2  | foo2   | bar2   | nil