Merge pull request #6026 from betagouv/main
This commit is contained in:
commit
a19107ef7e
2 changed files with 18 additions and 7 deletions
|
@ -1,16 +1,27 @@
|
|||
# This migration comes from active_storage (originally 20190112182829)
|
||||
class AddServiceNameToActiveStorageBlobs < ActiveRecord::Migration[6.0]
|
||||
disable_ddl_transaction!
|
||||
|
||||
def up
|
||||
unless column_exists?(:active_storage_blobs, :service_name)
|
||||
add_column :active_storage_blobs, :service_name, :string
|
||||
|
||||
if (configured_service = ActiveStorage::Blob.service.name)
|
||||
# rubocop:disable DS/Unscoped
|
||||
ActiveStorage::Blob.unscoped.update_all(service_name: configured_service)
|
||||
# rubocop:enable DS/Unscoped
|
||||
end
|
||||
|
||||
change_column :active_storage_blobs, :service_name, :string, null: false
|
||||
# rubocop:disable DS/Unscoped
|
||||
blobs_without_service_name = ActiveStorage::Blob.unscoped.where(service_name: nil)
|
||||
# rubocop:enable DS/Unscoped
|
||||
|
||||
if (configured_service = ActiveStorage::Blob.service.name && blobs_without_service_name.count > 0)
|
||||
# Backfill the existing blobs with the service.
|
||||
# NB: during a continuous deployments, some blobs may still be created
|
||||
# with an empty service_name. A later migration will fix those later.
|
||||
|
||||
say_with_time('backfill ActiveStorage::Blob.service.name. This could take a while…') do
|
||||
blobs_without_service_name.in_batches do |relation|
|
||||
relation.update_all service_name: configured_service
|
||||
sleep(0.01) # throttle
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
Loading…
Reference in a new issue