maintenance_tasks: CSV task fails if uuid is used for active_storage_attachments.record_id
Background
We use uuid for primary keys, thus active_storage_attachments.record_id is uuid. On the other hand, maintenance_tasks_runs.id is bigint. Therefore, when a CSV task tries to upload a CSV as an ActiveStorage::Attachment, the attachment fails to reference the CSV task’s run record (MaintenanceTasks::Run) because of the type inconsistency.
Possible solutions
- Document that the generated migration file must be manually edited when uuid is used.
- Respect
g.orm :active_record, primary_key_type: :uuidwhen generating the migration file.
Thanks in advance.
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Reactions: 5
- Comments: 18 (12 by maintainers)
I found myself in this situation and decided to hack it out with some monkeypatching and I thought I’d just offer this to anyone else who has a similar short-sighted need.
I’m using Zeitwerk overrides as described here: https://guides.rubyonrails.org/classic_to_zeitwerk_howto.html#decorating-classes-and-modules-from-engines
It uses ActiveRecordExtended for a window function and CTE because I was already using it, I’m sure we wouldn’t want to pull this dependency into the gem but it could certainly be written without it.
The meat of the change above is substituting the old:
for the new scope:
With no other changes
And now I can run CSV tasks. No tests, no promises, works for me.
This is a similar patch based on the version posted above but without the additional gem dependency. Still need to convert columns to UUID as above. I put this into an an initializer. Use at own risk
My team is currently pretty heads down, but we could potentially look at it later this year. If this issue gets closed as stale, can we reopen it later in the year when we’re able to better contribute?