-- API hot lookup indexes (2026-10-21) - same as migration
-- database/migrations/2026_10_21_000001_add_api_hot_indexes.php.
--
-- Prefer `php artisan migrate`: it skips any index whose leading column is already
-- indexed. If you run this file by hand instead, run it one statement at a time; an
-- error "Duplicate key name" only means that index is already there - go on.
-- None of these tables has a FULLTEXT index (no table rebuild). Nothing here changes
-- data. To undo: ALTER TABLE <t> DROP INDEX <name>.

ALTER TABLE `users` ADD INDEX `users_device_token_index` (`device_token`(191));
ALTER TABLE `translations` ADD INDEX `translations_lang_key_index` (`lang`, `lang_key`(191));

ALTER TABLE `discount_products`
  ADD INDEX `discount_products_product_id_index` (`product_id`),
  ADD INDEX `discount_products_discount_id_index` (`discount_id`);

ALTER TABLE `frequently_bought_products` ADD INDEX `frequently_bought_products_product_id_index` (`product_id`);
ALTER TABLE `user_loyalties` ADD INDEX `user_loyalties_user_end_index` (`user_id`, `end_date`);
ALTER TABLE `follow_sellers` ADD INDEX `follow_sellers_user_shop_index` (`user_id`, `shop_id`);

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