...

/

When Migrations Go Bad

When Migrations Go Bad

Learn about the downside of migrations.

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::Migration
def change
create_table :one do ...
end
create_table :two do ...
end
end
end

In the normal course of events, the up() method adds tables one and two, and the down() method removes them.

What happens if ...