'use strict';

/** @type {import('sequelize-cli').Migration} */
module.exports = {
  async up(queryInterface, Sequelize) {
    // Add index on latitude and longitude columns for faster geospatial queries
    // This improves performance of the bounding box pre-filter used in radius searches
    await queryInterface.addIndex('Items', ['latitude', 'longitude'], {
      name: 'idx_items_lat_lng',
      where: {
        latitude: { [Sequelize.Op.ne]: null },
        longitude: { [Sequelize.Op.ne]: null }
      }
    });
  },

  async down(queryInterface, Sequelize) {
    await queryInterface.removeIndex('Items', 'idx_items_lat_lng');
  }
};
