March 2025
Intermediate to advanced
472 pages
12h 10m
English
Migrations suffer from one serious problem. The underlying DDL statements that update the database schema are not transactional. This isn’t a failing in Rails—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:
| | 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.
But what happens if there’s a problem creating the second table? We’ll end up with a database containing table one but not ...
Read now
Unlock full access