-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Replace acts_as_paranoid/paranoia with discard #2354
Comments
Great summary. I think it'd be great to figure out how to move things over to |
Aye, I've been burned too many times by our paranoia stuff to want to keep it around. I imagine most of these are individually not giant changes, and there isn't any reason we couldn't try it with one model first and see how much work its going to be, right? I also can't imagine too many cases where extensions are really going to care about what we're using for deletion. |
I think this can be safely closed 🎉 |
It was missing from the work done in solidusio#2354. With the magic of ResourceController, it will start using discard when we perform admin destroys, since it now responds to .discard.
Our acts_as_paranoid models have been the cause of a lot of pain and confusion.
paranoia
overrides activerecord'sdelete
anddestroy
methods, which can surprise users expecting a real delete, but also surprises users when a record isn't declaredacts_as_paranoid
(or they use a method acts_as_paranoid doesn't override, likedelete_all
). It also has callback issues,dependent: :destroy
and any otherafter_destroy
callbacks happen on a soft-destroy or a real destroy.Ideally, these would all be switched to use discard, my extremely simple alternative: <40 LOC and no ActiveRecord overrides. But it's in no way a drop-in replacement.
A possible stepping stone is to switch to
paranoia_delete
first, which has much more similar semantics to discard (nodependent: :destroy
callbacks run).To start planning how to replace it I've cataloged all the models in core it is used on, and the effects either hard or soft deletes have.
Stock Transfers(Removed by Extract stock transfers to solidus_stock_transfers extension #2379)Product models
This is the most complicated group of models. Also the most frequently used, with the most possible admin interactions.
I'm not 100% sure why
Price
isacts_as_paranoid
, but I suspect it's just to prevent them being destroyed when a variant is soft-destroyed. Other than that I think it would be safe for them to be hard-destroyed. Maybe there is a need to keep them around for auditing (in which case we should represent them better and show the "historic" prices in the admin)Product and Variant should only ever be soft-destroyed. Soft-destroying a product will soft-destroy all the variants, which seems reasonable (although makes it harder to distinguish variants which were removed from a product from variants whose product was deleted. Might not matter.)
I'm not sure about StockItem deletion. It happens when a variant is deleted, but I'm not sure there it is desirable outside of that. The API allows it, but we have no interface in the admin, and it is never done.
Payment Method
These should only ever be soft-destroyed.
There are no
dependent: :destroy
s so we should be able to switch to discard.This is inheritable, so there may be additional issues.
Shipping Method
These should only ever be soft-destroyed.
I'm not sure if the
dependent: destroy
s are desirable here, they seem to bepart of the information we might want to keep, but it might make for faster
queries coming from the other direction (needs more consideration).
These are a good candidate for
paranoia_delete
ordiscard
Taxation
These both have potential leave orphaned records on a hard-destroy, and so are
only suitable for a soft destroy.
I'm not sure if the destroy on tax_rate_tax_categories is necessary, but it
might make querying for tax rates faster (needs more consideration)
Promotion Actions
These only use a soft-destroy.
Promotion actions aren't explicitly delted, but are deleted through assignment
(
promotion.promotion_actions=
). This makes it hard to change the behaviour.Other than that they would be a good candidate to switch to discard.
Store Credits
Neither of these have any
dependent: :destroy
s, so we can probably just switch to eitherparanoia_delete
ordiscard
Stock Transfers (to be removed in #2379)
We might be extracting stock transfers to an extension.
These can probably both just be hard-deleted (unless they have been finalized or have a stock movement).
The text was updated successfully, but these errors were encountered: