Chapter 10. Managing Databases with Migrations
To improve is to change; to be perfect is to change often.
Winston Churchill
Winston Churchill’s quote is quite applicable in the case of migrations. Part of the goal of migrations is to track changes to your database over time. Migrations might seem strange at first, but over time they’ll become a very ordinary part of your work, whether you generate them automatically or customize them by hand. The Rails approach to managing data structures is very different from the traditional separation of database design from programming. While Rails still maintains a separate toolkit for defining data structures, that toolkit attempts to improve on the traditional SQL data definition language (DDL) by wrapping DDL in Ruby code.
Migrations are something of a world of their own in the Rails environment, but they are still recognizably Rails, built into the same development process. Migrations are all written in Ruby code using a fairly small set of conventions. This book has used migrations throughout—you can’t write much of a Rails application without them—but until the last chapter, and then only once, those migrations were generated with Rails’s inventive scripts. Once you move past those scripts, migrations are a little more difficult, but still not that complicated.
Note
The details of migrations may not be your first priority. You can safely skip this chapter and come back to it if database and data structure management seem like good ...
Get Learning Rails 5 now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.