Advanced Migrations
Most Rails developers use the basic facilities of migrations to create and maintain their database schemas. But every now and then it’s useful to push migrations just a bit further. This section covers some more advanced migration usage.
Using Native SQL
Migrations give you a database-independent way of maintaining your application’s schema. However, if migrations don’t contain the methods you need to be able to do what you need to do, you’ll need to drop down to database-specific code. Rails provides two ways to do this. One is with options arguments to methods like add_column. The second is the execute method.
When you use options or execute, you might well be tying your migration to a specific database engine, because ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access