aboutsummaryrefslogtreecommitdiff
path: root/db/migrate/20210121192038_add_service_name_to_active_storage_blobs.active_storage.rb
blob: 9967a1323707f5a6a17135422feb9598884e9e15 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# This migration comes from active_storage (originally 20190112182829)
class AddServiceNameToActiveStorageBlobs < ActiveRecord::Migration[6.0]
  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
        ActiveStorage::Blob.unscoped.update_all(service_name: configured_service)
      end

      change_column :active_storage_blobs, :service_name, :string, null: false
    end
  end

  def down
    remove_column :active_storage_blobs, :service_name
  end
end