# Tuesday, May 25, 2010

One thing you might want to do before putting a new uCommerce solution into a production environment is remove any test baskets and orders you might have placed during development. The schema gets a little complicated with the rich functionality found in the uCommerce Transaction Foundation requiring the objects to be removed in a certain order.

image

Here’s how you go about deleting them.

*** WARNING! HERE BE DRAGONS! ***

Please be aware that running the following script will remove any baskets and orders found in the system with no way to get them back unless you have a database backup handy.

--DELETE PURCHASEORDERS AND ASSOCIATED DATA
BEGIN TRAN
 
-- Delete reviews
DELETE FROM uCommerce_ProductReviewComment
DELETE FROM uCommerce_ProductReview
 
-- Delete discounts
DELETE FROM uCommerce_OrderLineDiscountRelation
DELETE FROM uCommerce_Discount
 
-- Remove shipment <-> order line link
UPDATE uCommerce_OrderLine SET ShipmentId = NULL
 
UPDATE uCommerce_PurchaseOrder SET BillingAddressId = NULL
DELETE FROM uCommerce_Shipment
DELETE FROM uCommerce_OrderAddress
DELETE FROM uCommerce_OrderProperty
DELETE FROM uCommerce_OrderLine
DELETE FROM uCommerce_PaymentProperty
DELETE FROM uCommerce_Payment
DELETE FROM uCommerce_OrderStatusAudit
DELETE FROM uCommerce_PurchaseOrder
DELETE FROM uCommerce_Address
DELETE FROM uCommerce_Customer
--COMMIT

As an added precaution I uncommented the commit statement in case you were wondering why the data isn’t being deleted :)

This post was written for uCommerce 2.0.0.0 (schema version 50).

Tuesday, May 25, 2010 11:28:35 PM (Romance Daylight Time, UTC+02:00)
Naise, I've been needing that db diagram for a while now :-)

Isn't truncating the tables a better thing to do? Otherwise I think you'll get an entry in the transaction log for each record in all the tables (or something, been years since I worked with databases).

Here's a couple more tables I noticed in my "deleteAllOrders" cleanup script:

TRUNCATE TABLE uCommerce_Address
UPDATE uCommerce_OrderAddress SET OrderId = NULL
DELETE FROM uCommerce_OrderAddress
DELETE FROM uCommerce_Customer

Tuesday, May 25, 2010 11:39:55 PM (Romance Daylight Time, UTC+02:00)
Truncating or deleting doesn't make much difference when we're dealing with a dev environment. You usually have to create a backup of your database to move it anyway so you'll reset the log.

You're absolutely right that you could opt to delete customer information as well by including uCommerce_Address and uCommerce_Customer to the script. You'd have to add them to the end of the script to get the sequence right.
Comments are closed.