From 305a3128154901bef8f58d3056a6b095fdd28413 Mon Sep 17 00:00:00 2001 From: Pierre de La Morinerie Date: Tue, 9 Mar 2021 11:05:02 +0000 Subject: [PATCH] db: migrate ActiveStorage to Rails 6.1 --- ..._to_active_storage_blobs.active_storage.rb | 20 +++++++++++++++++++ ..._storage_variant_records.active_storage.rb | 14 +++++++++++++ db/schema.rb | 10 +++++++++- 3 files changed, 43 insertions(+), 1 deletion(-) create mode 100644 db/migrate/20210318090000_add_service_name_to_active_storage_blobs.active_storage.rb create mode 100644 db/migrate/20210318090001_create_active_storage_variant_records.active_storage.rb diff --git a/db/migrate/20210318090000_add_service_name_to_active_storage_blobs.active_storage.rb b/db/migrate/20210318090000_add_service_name_to_active_storage_blobs.active_storage.rb new file mode 100644 index 000000000..365bafc7f --- /dev/null +++ b/db/migrate/20210318090000_add_service_name_to_active_storage_blobs.active_storage.rb @@ -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 diff --git a/db/migrate/20210318090001_create_active_storage_variant_records.active_storage.rb b/db/migrate/20210318090001_create_active_storage_variant_records.active_storage.rb new file mode 100644 index 000000000..438b6b02c --- /dev/null +++ b/db/migrate/20210318090001_create_active_storage_variant_records.active_storage.rb @@ -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 diff --git a/db/schema.rb b/db/schema.rb index b1cff1bdb..750d0157b 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 2021_03_11_141956) do +ActiveRecord::Schema.define(version: 2021_03_18_090001) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -44,9 +44,16 @@ ActiveRecord::Schema.define(version: 2021_03_11_141956) 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.index ["key"], name: "index_active_storage_blobs_on_key", unique: true end + create_table "active_storage_variant_records", force: :cascade do |t| + t.bigint "blob_id", null: false + t.string "variation_digest", null: false + t.index ["blob_id", "variation_digest"], name: "index_active_storage_variant_records_uniqueness", unique: true + end + create_table "administrateurs", id: :serial, force: :cascade do |t| t.datetime "created_at" t.datetime "updated_at" @@ -727,6 +734,7 @@ ActiveRecord::Schema.define(version: 2021_03_11_141956) do t.index ["procedure_id"], name: "index_without_continuation_mails_on_procedure_id" end + add_foreign_key "active_storage_variant_records", "active_storage_blobs", column: "blob_id" add_foreign_key "assign_tos", "groupe_instructeurs" add_foreign_key "attestation_templates", "procedures" add_foreign_key "attestations", "dossiers"