-- Hot lookup indexes (2026-10-17) - same as migration
-- database/migrations/2026_10_17_000001_add_hot_lookup_indexes.php.
--
-- Prefer `php artisan migrate`: it skips any index whose column is already
-- indexed. If you run this file by hand instead, run it at a quiet hour
-- (products has a FULLTEXT index), one statement at a time; an error
-- "Duplicate key name" only means that index is already there - go on.
-- Nothing here changes data. To undo: ALTER TABLE <t> DROP INDEX <name>.

ALTER TABLE `carts`
  ADD INDEX `carts_user_id_index` (`user_id`),
  ADD INDEX `carts_temp_user_id_index` (`temp_user_id`);

ALTER TABLE `products`
  ADD INDEX `products_slug_index` (`slug`(191)),
  ADD INDEX `products_category_id_index` (`category_id`),
  ADD INDEX `products_brand_id_index` (`brand_id`),
  ADD INDEX `products_user_id_index` (`user_id`);

ALTER TABLE `product_taxes` ADD INDEX `product_taxes_product_id_index` (`product_id`);

ALTER TABLE `orders`
  ADD INDEX `orders_user_id_index` (`user_id`),
  ADD INDEX `orders_seller_id_index` (`seller_id`);

ALTER TABLE `order_details`
  ADD INDEX `order_details_product_id_index` (`product_id`),
  ADD INDEX `order_details_seller_id_index` (`seller_id`);

ALTER TABLE `combined_orders` ADD INDEX `combined_orders_user_id_index` (`user_id`);
ALTER TABLE `users` ADD INDEX `users_phone_index` (`phone`);
ALTER TABLE `wishlists` ADD INDEX `wishlists_user_product_index` (`user_id`, `product_id`);
ALTER TABLE `reviews` ADD INDEX `reviews_product_id_index` (`product_id`);
ALTER TABLE `flash_deal_products` ADD INDEX `flash_deal_products_flash_deal_id_index` (`flash_deal_id`);
ALTER TABLE `last_viewed_products` ADD INDEX `last_viewed_products_user_id_index` (`user_id`);
ALTER TABLE `category_translations` ADD INDEX `category_translations_category_lang_index` (`category_id`, `lang`);
ALTER TABLE `brand_translations` ADD INDEX `brand_translations_brand_id_index` (`brand_id`);
ALTER TABLE `firebase_notifications` ADD INDEX `firebase_notifications_receiver_id_index` (`receiver_id`);
ALTER TABLE `shops` ADD INDEX `shops_user_id_index` (`user_id`);
ALTER TABLE `searches` ADD INDEX `searches_query_index` (`query`(191));
ALTER TABLE `addresses` ADD INDEX `addresses_user_id_index` (`user_id`);

-- Then record the migration as run, so `migrate` does not try again:
-- INSERT INTO migrations (migration, batch)
--   SELECT '2026_10_17_000001_add_hot_lookup_indexes', COALESCE(MAX(batch), 0) + 1 FROM migrations;
