Skip to content

Active storage migration#7598

Merged
leio10 merged 133 commits intodevelopfrom
active_storage_migration
Jul 20, 2021
Merged

Active storage migration#7598
leio10 merged 133 commits intodevelopfrom
active_storage_migration

Conversation

@entantoencuanto
Copy link
Copy Markdown
Contributor

@entantoencuanto entantoencuanto commented Mar 13, 2021

🎩 What? Why?

This PR replaces CarrierWave attachments with ActiveStorage:

  • The namespace isolation of each module engine doesn't give us access to the methods to generate the urls provided by AS. The inclusion of these methods in each engine causes a drop performance (the duration of tests are doubled) so I've added all paths methods to the base uploader class. The HasUploadValidations concern adds an instance method to the classes to access the url helper methods:

For example:

user.avatar.url

changes to

user.attached_uploader(:avatar).path

CarrierWave also has a system of versions to define different sizes of images, for example. ActiveStorage has something similar, variants, but does not admit named variants by default. I've moved the CarrierWave versions definitions to a hash in the uploaders which can be used to generate named variants:

For example

user.avatar.big.url

changes to:

user.attached_uploader(:avatar).path(variant: :big) or user.attached_uploader(:avatar).variant_path(:big)

Other methods are available to generate full URLs:

user.attached_uploader(:avatar).url(host: user.organization.host)
user.attached_uploader(:avatar).url(variant: :big, host: user.organization.host)
user.attached_uploader(:avatar).variant_url(:big, host: user.organization.host)
  • This PR removes inheritance of application uploaders from CarrierWave and implements some logic provided by it. For example CarrierWave uploaders define their own processors to perform some validations. These validations has been moved to extenal validators:
    • OrganizationPresentValidator Checks the presence of an organization in the instance of the model. This is important because some configurations for the validations are defined in the organization
    • UploaderImageDimensionsValidator Checks dimension of the images and compares them with the maximum values set in the upoader

Other relevant changes of this PR:

  • Transforms the upload form builder method to work with ActiveStorage attributes: With CarrierWave when the attachment attributes were called the application returned a CarrierWave uploader, while with ActiveStorage an instance of ActiveStorage::Attached::One is returned. With attached_uploader we can access to the logic provided by the uploader. This has been used to change upload builder method which generates different output depending on the uploader configuration.
  • Removes some not null constraints on columns used by CarrierWave In a future PR these columns should be removed completely (see Plan migration of existing CarrierWave attachments to ActiveStorage #7796)
  • Changes seeds to generate ActiveStorage attachments
  • Implements remote_url= method provided by CarrierWave to attach a file from a URL in Decidim::ApplicationUploader
  • Changes content blocks attachments by defining a new Decidim::ContentBlockAttachment model which stores the name of each attachment defined in the content block manifest to use the correspoding uploader (see Migrate content block images to ActiveStorage #7739)

📌 Related Issues

Link your PR to an issue

Testing

The interface behavior should be the same as before this PR

📋 Checklist

🚨 Please review the guidelines for contributing to this repository.

  • CONSIDER adding a unit test if your PR resolves an issue.
  • ✔️ DO check open PR's to avoid duplicates.
  • ✔️ DO keep pull requests small so they can be easily reviewed.
  • ✔️ DO build locally before pushing.
  • ✔️ DO make sure tests pass.
  • ✔️ DO make sure any new changes are documented in docs/.
  • ✔️ DO add and modify seeds if necessary.
  • ✔️ DO add CHANGELOG upgrade notes if required.
  • ✔️ DO add to GraphQL API if there are new public fields.
  • ✔️ DO add link to MetaDecidim if it's a new feature.
  • AVOID breaking the continuous integration build.
  • AVOID making significant changes to the overall architecture.

📷 Screenshots

Please add screenshots of the changes you're proposing
Description

♥️ Thank you!

@entantoencuanto
Copy link
Copy Markdown
Contributor Author

Hi, @mrcasals, based on rails/rails#31325 (comment) I've added the routes to the Decidim admin engine provided by ActiveStorage:

  • The polymorphic mappings using a middleware (05c9fdb)
  • The missing path helper methods with method_missing (7649389)

It has the disadvantage that the namespace isolation of engines is broken a bit and missing routes are looked up in the main app. I can add the missing methods from ActiveStorate directly to avoid this. What do you think?

@entantoencuanto entantoencuanto force-pushed the active_storage_migration branch from 7649389 to ee3dded Compare March 15, 2021 21:12
@entantoencuanto entantoencuanto force-pushed the active_storage_migration branch 2 times, most recently from af58e54 to 558879a Compare March 16, 2021 09:00
@mrcasals
Copy link
Copy Markdown
Contributor

It has the disadvantage that the namespace isolation of engines is broken a bit and missing routes are looked up in the main app. I can add the missing methods from ActiveStorate directly to avoid this. What do you think?

I don't have a clear opinion on this yet! I'd say go ahead!

@entantoencuanto entantoencuanto force-pushed the active_storage_migration branch 12 times, most recently from a55150b to 44ef20e Compare March 24, 2021 20:00
@entantoencuanto entantoencuanto force-pushed the active_storage_migration branch 4 times, most recently from 3f293c7 to 16ec5d2 Compare March 31, 2021 16:19
@entantoencuanto entantoencuanto force-pushed the active_storage_migration branch 8 times, most recently from fe90dba to a848a3d Compare April 8, 2021 12:09
enable_processing method was a method provided by CarrierWave, not
required using ActiveStorage
@leio10 leio10 force-pushed the active_storage_migration branch from 45c824b to ca0cbe8 Compare July 14, 2021 08:29
Copy link
Copy Markdown
Contributor

@leio10 leio10 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome and huge job! 👏👏
I've checked that works well with production apps and I've reviewed specially the core changes. Let's address my comments and merge this! 💪

@entantoencuanto entantoencuanto force-pushed the active_storage_migration branch from d6b1a29 to 6bda58d Compare July 19, 2021 17:01
@leio10 leio10 merged commit c9ed674 into develop Jul 20, 2021
@leio10 leio10 deleted the active_storage_migration branch July 20, 2021 11:13
entantoencuanto added a commit that referenced this pull request Jul 26, 2021
* develop: (32 commits)
  Remove obsolete rake webpack task (#8237)
  Active storage migrations service (#7902)
  Fix content type delegation to blank attachments (#8230)
  Evote bug fixing (#8220)
  Fix the proposal data migration for proposals without authors or organization (#8015)
  Bump addressable version because security issues (#8229)
  Online meetings iframe visibility with time (#8097)
  Meetings iframe and iframe URL (#8096)
  Remove flaky test on meetings (#8226)
  Fix broken tests after problematic PRs (#8224)
  Apply permissions system to comments (#8035)
  Set current_component as commentable when commentable is a participatory space (#8189)
  Fix don't require inactive authorization handlers (#8122)
  Improve metrics calculations performance (#8215)
  Fix performance issue in notification settings page (#8155)
  Active storage migration (#7598)
  Update manual installation guide in documentation (#8217)
  Load JS configuration in elections focus mode layout (#8213)
  Fix user activity pagination when there are hidden items (#8202)
  Make it possible to define SCSS settings overrides from modules (#8198)
  ...
roxanaopr pushed a commit to i-need-another-coffee/decidim that referenced this pull request Jul 29, 2021
Co-authored-by: leio10 <leiodd@gmail.com>
Co-authored-by: Fernando Blat <fernando@blat.es>
Co-authored-by: Antti Hukkanen <antti.hukkanen@mainiotech.fi>
roxanaopr pushed a commit to i-need-another-coffee/decidim that referenced this pull request Aug 10, 2021
Co-authored-by: leio10 <leiodd@gmail.com>
Co-authored-by: Fernando Blat <fernando@blat.es>
Co-authored-by: Antti Hukkanen <antti.hukkanen@mainiotech.fi>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Migrate content block images to ActiveStorage Migrate from Carrierwave to ActiveStorage

6 participants