When Migrations Go Bad
Learn about the downside of migrations.
We'll cover the following...
Overview
Migrations suffer from one serious problem. The underlying DDL statements that update the database schema are not transactional. This isn’t exclusively a failing in Rails, though, as most databases don’t support the rolling back of create table
, alter table
, and other DDL
statements.
Let’s look at a migration that tries to add two tables to a database:
Press + to interact
class ExampleMigration < ActiveRecord::Migrationdef changecreate_table :one do ...endcreate_table :two do ...endendend
In the normal course of events, the up()
method adds tables one
and two
, and the down()
method removes them.
What happens if ...