diff options
author | aschmitz <andy.schmitz@gmail.com> | 2017-10-11 14:20:39 -0500 |
---|---|---|
committer | Eugen Rochko <eugen@zeonfederated.com> | 2017-10-11 21:20:39 +0200 |
commit | e5d8166a12bc5db2f15afa8f2573be6892481e01 (patch) | |
tree | 47bb7bafa3ec4534b45d437b7155dbf72c3d414e | |
parent | 07ea625cb228b36b8d87de32141024ec98d875da (diff) |
Fix #5329 (#5332)
This fixes #5329, which occurred when using MigrationHelpers on a table that Postgres estimated to be non-empty when it was actually empty.
-rw-r--r-- | lib/mastodon/migration_helpers.rb | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/lib/mastodon/migration_helpers.rb b/lib/mastodon/migration_helpers.rb index ed716501e..80a8f440c 100644 --- a/lib/mastodon/migration_helpers.rb +++ b/lib/mastodon/migration_helpers.rb @@ -335,7 +335,10 @@ module Mastodon start_arel = table.project(table[:id]).order(table[:id].asc).take(1) start_arel = yield table, start_arel if block_given? - start_id = exec_query(start_arel.to_sql).to_hash.first['id'].to_i + first_row = exec_query(start_arel.to_sql).to_hash.first + # In case there are no rows but we didn't catch it in the estimated size: + return unless first_row + start_id = first_row['id'].to_i say "Migrating #{table_name}.#{column} (~#{total.to_i} rows)" |