From 574a5d00679a3512c217fcb4c846ef13ec397e98 Mon Sep 17 00:00:00 2001 From: taitus Date: Mon, 31 Aug 2020 12:31:08 +0200 Subject: [PATCH 1/2] Update old migrations to maintain consistency After merge "Bump paperclip from 5.2.1 to 6.1.0 #3905" as indicated in the release_notes columns type for attachments are changed from integer to bigint. For this reason we edit old migrations so that they continue to generate integer as before. --- ...20170322145702_create_site_customization_images.rb | 5 ++++- db/migrate/20170627113331_create_images.rb | 11 +++++------ db/migrate/20170720092638_create_documents.rb | 5 ++++- 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/db/migrate/20170322145702_create_site_customization_images.rb b/db/migrate/20170322145702_create_site_customization_images.rb index 749601f46..4f468d81a 100644 --- a/db/migrate/20170322145702_create_site_customization_images.rb +++ b/db/migrate/20170322145702_create_site_customization_images.rb @@ -2,7 +2,10 @@ class CreateSiteCustomizationImages < ActiveRecord::Migration[4.2] def change create_table :site_customization_images do |t| t.string :name, null: false - t.attachment :image + t.string :image_file_name + t.string :image_content_type + t.integer :image_file_size + t.datetime :image_updated_at t.timestamps null: false end diff --git a/db/migrate/20170627113331_create_images.rb b/db/migrate/20170627113331_create_images.rb index e82e3cd14..5f0d0e5e4 100644 --- a/db/migrate/20170627113331_create_images.rb +++ b/db/migrate/20170627113331_create_images.rb @@ -1,14 +1,13 @@ class CreateImages < ActiveRecord::Migration[4.2] - def up + def change create_table :images do |t| t.references :imageable, polymorphic: true, index: true t.string :title, limit: 80 t.timestamps null: false + t.string :attachment_file_name + t.string :attachment_content_type + t.integer :attachment_file_size + t.datetime :attachment_updated_at end - add_attachment :images, :attachment - end - - def down - remove_attachment :images, :attachment end end diff --git a/db/migrate/20170720092638_create_documents.rb b/db/migrate/20170720092638_create_documents.rb index 429487def..cd8a9461c 100644 --- a/db/migrate/20170720092638_create_documents.rb +++ b/db/migrate/20170720092638_create_documents.rb @@ -2,7 +2,10 @@ class CreateDocuments < ActiveRecord::Migration[4.2] def change create_table :documents do |t| t.string :title - t.attachment :attachment + t.string :attachment_file_name + t.string :attachment_content_type + t.integer :attachment_file_size + t.datetime :attachment_updated_at t.references :user, index: true, foreign_key: true t.references :documentable, polymorphic: true, index: true From 819e2c82ce128cbb3abaf2bd3e56fd6979a159a6 Mon Sep 17 00:00:00 2001 From: taitus Date: Tue, 8 Sep 2020 10:59:33 +0200 Subject: [PATCH 2/2] Add migration to change columns type of attachments As suggested in the paperclip update discussed in the previous commit, we force the type of these fields to be bigint. --- ...00908084257_change_attachment_size_fields_to_bigint.rb | 7 +++++++ db/schema.rb | 8 ++++---- 2 files changed, 11 insertions(+), 4 deletions(-) create mode 100644 db/migrate/20200908084257_change_attachment_size_fields_to_bigint.rb diff --git a/db/migrate/20200908084257_change_attachment_size_fields_to_bigint.rb b/db/migrate/20200908084257_change_attachment_size_fields_to_bigint.rb new file mode 100644 index 000000000..65d36a3c8 --- /dev/null +++ b/db/migrate/20200908084257_change_attachment_size_fields_to_bigint.rb @@ -0,0 +1,7 @@ +class ChangeAttachmentSizeFieldsToBigint < ActiveRecord::Migration[5.1] + def change + change_column :site_customization_images, :image_file_size, :bigint + change_column :images, :attachment_file_size, :bigint + change_column :documents, :attachment_file_size, :bigint + end +end diff --git a/db/schema.rb b/db/schema.rb index f2002efc6..c513ce015 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: 20200519120717) do +ActiveRecord::Schema.define(version: 20200908084257) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -545,7 +545,7 @@ ActiveRecord::Schema.define(version: 20200519120717) do t.string "title" t.string "attachment_file_name" t.string "attachment_content_type" - t.integer "attachment_file_size" + t.bigint "attachment_file_size" t.datetime "attachment_updated_at" t.integer "user_id" t.string "documentable_type" @@ -641,7 +641,7 @@ ActiveRecord::Schema.define(version: 20200519120717) do t.datetime "updated_at", null: false t.string "attachment_file_name" t.string "attachment_content_type" - t.integer "attachment_file_size" + t.bigint "attachment_file_size" t.datetime "attachment_updated_at" t.integer "user_id" t.index ["imageable_type", "imageable_id"], name: "index_images_on_imageable_type_and_imageable_id" @@ -1347,7 +1347,7 @@ ActiveRecord::Schema.define(version: 20200519120717) do t.string "name", null: false t.string "image_file_name" t.string "image_content_type" - t.integer "image_file_size" + t.bigint "image_file_size" t.datetime "image_updated_at" t.datetime "created_at", null: false t.datetime "updated_at", null: false