

UPDATE zamzam.api_usersorder
SET restaurant_id = rt.id
FROM zamzam.api_restaurant rt
WHERE zamzam.api_usersorder.restaurant_id = rt.restaurant_id;

UPDATE zamzam.api_usersorderitems 
SET item_id = mt.id
FROM zamzam.api_menuitems mt
WHERE zamzam.api_usersorderitems.item_id = mt.item_id;

UPDATE zamzam.api_usersorderitems 
SET item_variation_id = mt.id
FROM zamzam.api_menuitemsvariation mt
WHERE zamzam.api_usersorderitems .item_variation_id = mt.item_variation_id;


UPDATE zamzam.api_usersorderitemtax 
SET order_item_tax_id = mt.id
FROM zamzam.api_menutaxes mt
WHERE zamzam.api_usersorderitemtax .order_item_tax_id = mt.tax_id;

UPDATE zamzam.api_usersordertax
SET order_tax_id = mt.id
FROM zamzam.api_menutaxes mt
WHERE zamzam.api_usersordertax.order_tax_id = mt.tax_id;

-- discountt
UPDATE zamzam.api_usersorderdiscount a
SET order_discount_id = mt.id
FROM zamzam.api_menudiscounts mt
WHERE a.order_discount_id = mt.discount_id;

-- order items addons
UPDATE zamzam_test.api_usersorderitemaddons a
SET addon_id = mt.id
FROM zamzam_test.api_menuaddonsgroupitems mt
WHERE a.addon_id = mt.addon_group_item_id;


UPDATE zamzam.api_menuaddonsgroupitems 
SET addon_group_id = mt.id
FROM zamzam.api_menuaddonsgroup mt
WHERE zamzam.api_menuaddonsgroupitems.addon_group_id = mt.addon_group_id;

UPDATE zamzam.api_menuaddonsgroup 
SET restaurant_id = mt.id
FROM zamzam.api_restaurant mt
WHERE zamzam.api_menuaddonsgroup.restaurant_id = mt.restaurant_id;

UPDATE zamzam.api_menutaxes 
SET restaurant_id = mt.id
FROM zamzam.api_restaurant mt
WHERE zamzam.api_menutaxes.restaurant_id = mt.restaurant_id::INT;

UPDATE zamzam.api_menudiscounts 
SET restaurant_id = mt.id
FROM zamzam.api_restaurant mt
WHERE zamzam.api_menudiscounts.restaurant_id = mt.restaurant_id::INT;

UPDATE zamzam.api_menuattributes 
SET restaurant_id = mt.id
FROM zamzam.api_restaurant mt
WHERE zamzam.api_menuattributes.restaurant_id = mt.restaurant_id;


UPDATE zamzam.api_menuvariations 
SET restaurant_id = mt.id
FROM zamzam.api_restaurant mt
WHERE zamzam.api_menuvariations.restaurant_id = mt.restaurant_id;

UPDATE zamzam.api_menuitemsaddons 
SET addon_group_id = mt.id
FROM zamzam.api_menuaddonsgroup mt
WHERE zamzam.api_menuitemsaddons.addon_group_id = mt.addon_group_id;

UPDATE zamzam.api_menuitemsaddons
SET item_id = mt.id
FROM zamzam.api_menuitems mt
WHERE zamzam.api_menuitemsaddons.item_id = mt.item_id;

UPDATE zamzam.api_menuitemsvariationaddons 
SET addon_group_id = mt.id
FROM zamzam.api_menuaddonsgroup mt
WHERE zamzam.api_menuitemsvariationaddons.addon_group_id = mt.addon_group_id;

UPDATE zamzam.api_menuitemsvariation 
SET item_variation_id = mt.id
FROM zamzam.api_menuvariations mt
WHERE zamzam.api_menuitemsvariation.item_variation_id = mt.variation_id;

UPDATE zamzam.api_menuitemsvariation 
SET item_id = mt.id
FROM zamzam.api_menuitems mt
WHERE zamzam.api_menuitemsvariation.item_id = mt.item_id::INT;

UPDATE zamzam.api_menuitems a
SET restaurant_id = mt.id
FROM zamzam.api_restaurant mt
WHERE a.restaurant_id = mt.restaurant_id::INT;

-- check error before executing
UPDATE zamzam.api_menuitems a
SET item_category_id = mt.id
FROM zamzam.api_menucategory mt
WHERE a.item_category_id = mt.category_id;

UPDATE zamzam.api_menucategory a
SET restaurant_id = mt.id
FROM zamzam.api_restaurant mt
WHERE a.restaurant_id = mt.restaurant_id;


UPDATE zamzam.api_restaurantordertypes a
SET restaurant_id = mt.id
FROM zamzam.api_restaurant mt
WHERE a.restaurant_id = mt.restaurant_id;

UPDATE zamzam.api_userviewedproducts
SET item_id = mt.id
FROM zamzam.api_menuitems mt
WHERE zamzam.api_userviewedproducts.item_id = mt.item_id::INT;

UPDATE zamzam.api_userwishlist
SET item_id = mt.id
FROM zamzam.api_menuitems mt
WHERE zamzam.api_userwishlist.item_id = mt.item_id::INT;


UPDATE zamzam.api_usercart
SET item_id = mt.id
FROM zamzam.api_menuitems mt
WHERE zamzam.api_usercart.item_id = mt.item_id::INT;

UPDATE zamzam.api_usercart
SET variation_id = mt.id
FROM zamzam.api_menuitemsvariation mt
WHERE zamzam.api_usercart.variation_id = mt.item_variation_id::INT;

UPDATE zamzam.api_restaurantcredentials
SET restaurant_id = mt.id
FROM zamzam.api_restaurant mt
WHERE zamzam.api_restaurantcredentials.restaurant_id = mt.restaurant_id;