Merge pull request #6026 from betagouv/main

This commit is contained in:
Pierre de La Morinerie 2021-03-25 19:17:09 +01:00 committed by GitHub
commit a19107ef7e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 7 deletions

View file

@ -1,16 +1,27 @@
# This migration comes from active_storage (originally 20190112182829) # This migration comes from active_storage (originally 20190112182829)
class AddServiceNameToActiveStorageBlobs < ActiveRecord::Migration[6.0] class AddServiceNameToActiveStorageBlobs < ActiveRecord::Migration[6.0]
disable_ddl_transaction!
def up def up
unless column_exists?(:active_storage_blobs, :service_name) unless column_exists?(:active_storage_blobs, :service_name)
add_column :active_storage_blobs, :service_name, :string 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 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
end end

View file

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