It's best practice to use the ApplicationRecord. But when Rake is
loaded, our application is not loaded yet and the ApplicationRecord
class wasn't available yet. Requiring within the task solves the problem
because Rake loads the Rails environment before executing this task.
I also removed the unused highline loading.
Active Storage needs a checksum for each file and AWS S3 provides this
checksum as "ETag". They are both MD5 but AWS stores it as hexdigest and
Active Storage as base64digest. We need to convert it from on to the
other to get a valid checksum for Active Storage.
Where the migration task has already run (only staging servers), delete all
Active Storage data first and then run the task again:
bundle exec rake db:migrate:down VERSION=20220316055458
bundle exec rake db:migrate
bundle exec rake from_paperclip_to_active_storage:copy_content_config
bundle exec rake from_paperclip_to_active_storage:migrate
Common migrations look for all models with *_file_name attributes but I
found that unreliable in our code base. It finds too many model classes
and doesn't allow us to be more selective in the migration. So I used
our own migration declaration to migrate exactly those attachments
specified.
We removed some Spree magic a while back and that broke our sample data
script. This is now corrected.
I also added a spec so that we will notice broken seed data earlier.
We were passing too many parameters to the product creation. Rails 5.2
complained that products don't have a distributor. Filtering the
parameters helps.
Enumerable#uniq is fine (eg calling #uniq on an Array object), but now using #uniq on an ActiveRecord::Relation is deprecated in favour of #distinct (which modifies the query itself, as opposed to iterating over the results of the query).
The script was failing with:
NoMethodError: undefined method `update!' for nil:NilClass
Now it's failing with:
ActiveRecord::RecordNotFound: Couldn't find OrderCycle with id=1
When the indent of arguments is aligned with the method brackets, it
needs to be changed when the method changes. Putting all arguments on
their own line makes diffs of method changes or argument changes
clearer. See the next commit.