LendingHome / zero_downtime_migrations

Zero downtime migrations with ActiveRecord 3+ and PostgreSQL
MIT License
561 stars 27 forks source link

Throw error if column is added without disabling ddl transaction #11

Open chaner opened 7 years ago

chaner commented 7 years ago

We have found that adding columns to large database tables with default transactions turned on is unsafe. It will lock the table and do bad things. This PR will throw an error if a column is added without turning off ddl transactions.

shuber commented 6 years ago

@chaner Were you having an issue with this when calling something like this?

add_column :some_large_table, :some_column, :string

Just want to verify that you weren't using the default option when you noticed this issue e.g.

add_column :some_large_table, :some_column, :some_type, default: "some-default-value"
nikolai-b commented 5 years ago

I would have thought it was the default that caused adding the column to be slow. Adding a column is very fast (at least with Postgres). Defaults are also fast if you are using postgres versions > 11

see https://www.depesz.com/2018/04/04/waiting-for-postgresql-11-fast-alter-table-add-column-with-a-non-null-default/