db: migrate ActiveStorage to Rails 6.1

This commit is contained in:
Pierre de La Morinerie 2021-03-09 11:05:02 +00:00
parent 5990439ab7
commit 305a312815
3 changed files with 43 additions and 1 deletions

View file

@ -0,0 +1,20 @@
# 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)
# 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
end
end
def down
remove_column :active_storage_blobs, :service_name
end
end

View file

@ -0,0 +1,14 @@
# This migration comes from active_storage (originally 20191206030411)
# rubocop:disable Rails/CreateTableWithTimestamps
class CreateActiveStorageVariantRecords < ActiveRecord::Migration[6.0]
def change
create_table :active_storage_variant_records do |t|
t.belongs_to :blob, null: false, index: false
t.string :variation_digest, null: false
t.index [:blob_id, :variation_digest], name: "index_active_storage_variant_records_uniqueness", unique: true
t.foreign_key :active_storage_blobs, column: :blob_id
end
end
end
# rubocop:enable Rails/CreateTableWithTimestamps