Last active
August 12, 2020 02:14
-
-
Save jhirbour/9051020 to your computer and use it in GitHub Desktop.
Code to empty a spree database of product/taxons/orders
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#### DON'T RUN THIS ON YOUR PRODUCTION DATA!!!! It will delete stuff !!!!!! | |
### | |
### | |
### FWIW this was from Spree circa 2013 | |
# clear product data | |
Spree::Product.all.map { |p| p.destroy! } | |
Spree::Variant.with_deleted.map { |v| v.destroy! } | |
Spree::StockItem.all.map { |si| si.destroy! } | |
# clear taxonomies and Taxons | |
# double check that this deletes from spree_taxons and spree_taxonomies | |
Spree::Taxonomy.all.map { |t| t.destroy! } | |
# clear out orders | |
Spree::Order.all.map { |o| o.destroy! } |
Also should be Spree::*.unscoped because if you've deleted something by hands it will be removed from default scope
And in the current version delete and destroy will not remove records from database, so we need to use really_destroy!
method from paranoia gem
Hey I am runnnig the same commands but some of my products are not deleted. Can anyone tell me how can i solve this problem?
Spree::Product.all.map { |p| p.destroy } after running this command some of my products are not deleted and It returns false ..
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You have a typo in your last command. Should be destroy! instead of destory!