Skip to content

Instantly share code, notes, and snippets.

@jhirbour
Last active August 12, 2020 02:14
Show Gist options
  • Save jhirbour/9051020 to your computer and use it in GitHub Desktop.
Save jhirbour/9051020 to your computer and use it in GitHub Desktop.
Code to empty a spree database of product/taxons/orders
#### 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! }
@logicielsjpb
Copy link

You have a typo in your last command. Should be destroy! instead of destory!

@AKovtunov
Copy link

Also should be Spree::*.unscoped because if you've deleted something by hands it will be removed from default scope

@AKovtunov
Copy link

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

@kunalbluebash
Copy link

kunalbluebash commented May 26, 2020

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