What are the Slack Archives?
Itβs a history of our time together in the Slack Community! Thereβs a ton of knowledge in here, so feel free to search through the archives for a possible answer to your question.
Because this space is not active, you wonβt be able to create a new post or comment here. If you have a question or want to start a discussion about something, head over to our categories and pick one to post in! You can always refer back to a post from Slack Archives if needed; just copy the link to use it as a reference..
Hey guys! Does someone maybe has a SQL Query to remove orders and all related enities? I want to rem
Hey guys!
Does someone maybe has a SQL Query to remove orders and all related enities?
I want to remove some testdata
Comments
-
Deleting order data is tricky, because there are so many relations. You will need to adapt this to include any payment tables you might have but this covers the core:
BEGIN; -- We need to cache these ids because the addresses must be deleted after the order has been -- deleted, and if we don't have this cache we cannot find the addresses by id_order CREATE TEMP TABLE tmp_sales_order_address_id ( id_sales_order_address INT ); INSERT INTO tmp_sales_order_address_id SELECT fk_sales_order_address_billing FROM spy_sales_order WHERE id_sales_order = :orderid; INSERT INTO tmp_sales_order_address_id SELECT fk_sales_order_address_shipping FROM spy_sales_order WHERE id_sales_order = :orderid; INSERT INTO tmp_sales_order_address_id SELECT fk_sales_order_address FROM spy_sales_shipment WHERE fk_sales_order = :orderid; delete from spy_oms_order_item_state_history where fk_sales_order_item IN (select id_sales_order_item from spy_sales_order_item where fk_sales_order = :orderid); delete from spy_oms_transition_log where fk_sales_order = :orderid; delete from spy_sales_order_totals where fk_sales_order = :orderid; delete from spy_sales_discount where fk_sales_order = :orderid; delete from spy_sales_payment where fk_sales_order = :orderid; delete from spy_oms_event_timeout where fk_sales_order_item IN (select id_sales_order_item from spy_sales_order_item where fk_sales_order = :orderid); delete from spy_sales_order_item_metadata where fk_sales_order_item IN (select id_sales_order_item from spy_sales_order_item where fk_sales_order = :orderid); delete from spy_sales_order_item where fk_sales_order = :orderid; delete from spy_sales_order_comment where fk_sales_order = :orderid; delete from spy_sales_shipment where fk_sales_order = :orderid; delete from spy_sales_expense where fk_sales_order = :orderid; delete from spy_sales_order where id_sales_order = :orderid; DELETE FROM spy_sales_order_address WHERE id_sales_order_address IN (SELECT id_sales_order_address FROM tmp_sales_order_address_id); DROP TABLE tmp_sales_order_address_id; COMMIT;
0 -
I had this to hand because I am doing exactly the same thing at the moment π
0 -
Wow Rick, that was exactly what I was looking for!
Deleting order data is tricky, because there are so many relations.
That's why I asked π
0 -
Iβm not sure if it will work directly with a propel connection, because itβs a multi statement script. We are using it directly with
psql
and using the-v
option to pass in theorderid
parameter.0 -
Here it is a bit pimped including some missing tables (discount_code and marketplace stuff)
And runnable from a good old SQL console useinsert into tmp_sales_order_id SELECT id_sales_order from spy_sales_order;
To control which orders should be deleted
0
Categories
- All Categories
- 42 Getting Started & Guidelines
- 7 Getting Started in the Community
- 8 Additional Resources
- 7 Community Ideas and Feedback
- 76 Spryker News
- 930 Developer Corner
- 788 Spryker Development
- 89 Spryker Dev Environment
- 362 Spryker Releases
- 3 Oryx frontend framework
- 35 Propel ORM
- 68 Community Projects
- 3 Community Ideation Board
- 30 Hackathon
- 3 PHP Bridge
- 6 Gacela Project
- 26 Job Opportunities
- 3.2K π Slack Archives
- 116 Academy
- 5 Business Users
- 370 Docker
- 551 Slack General
- 2K Help
- 75 Knowledge Sharing
- 6 Random Stuff
- 4 Code Testing
- 32 Product & Business Questions
- 70 Spryker Safari Questions
- 50 Random