db: fix ActiveStorage migration to Rails 6.1

1. Executing an `update_all` on a lot of records is slow. Instead we
backfill the column in batches (without locking the table).

2. We can't mark the colum as not-null, because already running
instances still using the old code will not use the service_name
column yet.

  A later migration will backfill the remaining data and make the column
non-null.
This commit is contained in:
Pierre de La Morinerie 2021-03-25 16:46:18 +00:00
parent 703f13c34d
commit a08c18eb81
2 changed files with 18 additions and 7 deletions

View file

@ -44,7 +44,7 @@ ActiveRecord::Schema.define(version: 2021_03_18_090001) do
t.bigint "byte_size", null: false
t.string "checksum", null: false
t.datetime "created_at", null: false
t.string "service_name", null: false
t.string "service_name"
t.index ["key"], name: "index_active_storage_blobs_on_key", unique: true
end