13 Commits
Author SHA1 Message Date
Robert SpeicherandRobert Speicher 432347426c Merge branch 'update-column-in-batches-where' into 'master'
Allow customising of queries used for `update_column_in_batches`

This MR makes two changes to `add_column_with_default` and `update_column_in_batches`:

1. `add_column_with_default` no longer wraps the entire set of updates in a single transaction, preventing any locks from sticking around for the duration of the entire transaction
2. `update_column_in_batches` now takes a block which can be used to customise the queries. This uses Arel as messing with raw SQL strings is a total pain

In !4381 there's a need for updating existing rows/columns in a table in batches using a custom `WHERE` condition. Without the changes in this MR this would not be possible.

See merge request !4680
2016-06-17 14:14:25 -04:00
Yorick Peterse ea7ff13410 Removed old comment from update_column_in_batches 2016-06-13 11:50:27 +02:00
Yorick Peterse 9c238dc970 Update columns in batches until no rows are left
Instead of updating a fixed number of rows (based on the amount of rows
available at the start of the update) the method
"update_column_in_batches" will now continue updating rows until it runs
out of rows to process.

For a table with a high rate of inserts this may result in the migration
taking quite some time. However, the alternative is not all rows being
updated or the "change_column_null" method raising an error due to there
being NULL values.
2016-06-13 11:38:57 +02:00
Yorick Peterse b33b7be53e Handle NULL migration errors in migration helpers
This ensures that whenever changing the NULL constraint of a column
fails we still drop the column.
2016-06-13 11:22:58 +02:00
Felipe Artur 9264203103 change add_concurrent_index function arguments 2016-06-06 13:06:21 -03:00
Felipe Artur 8450fe3074 Add index to notification settings 2016-06-03 16:46:10 -03:00
Grzegorz Bizon 7f9092da1e Extend comment for migrations helper MySQL fix 2016-05-22 23:31:33 +02:00
Grzegorz Bizon 2df8b48dbb Add MySQL compatibility fix in migration helpers 2016-05-22 22:44:59 +02:00
Yorick Peterse c22be75794 Removed outdated comment from migration helpers 2016-05-19 12:36:02 -05:00
Yorick Peterse 59640866ce Remove left-over use of strip_heredoc 2016-05-19 10:04:46 -05:00
Yorick Peterse 6a29117793 Removed stray strip_heredoc from migration helpers 2016-05-13 00:11:01 +02:00
Yorick Peterse 36083b4d0e Fixed styling per Rubocop pedantics 2016-05-12 13:03:55 +02:00
Yorick Peterse e867099091 Added helper methods for database migrations
These helpers can be used to perform migrations without taking down the
entire application.

For example, the method "add_column_with_default" can be used to add a
new column with a default value without locking the entire table.
2016-05-12 12:59:40 +02:00