-- Find and drop the COMPOSITE unique index
-- This index includes BOTH inquiryId AND supplierId together

-- STEP 1: Find the composite unique index
-- Run this query:
SELECT 
    INDEX_NAME as Key_name,
    GROUP_CONCAT(COLUMN_NAME ORDER BY SEQ_IN_INDEX) as Columns,
    NON_UNIQUE
FROM INFORMATION_SCHEMA.STATISTICS
WHERE TABLE_SCHEMA = DATABASE()
  AND TABLE_NAME = 'bids'
  AND COLUMN_NAME IN ('inquiryId', 'supplierId')
GROUP BY INDEX_NAME, NON_UNIQUE
HAVING COUNT(DISTINCT COLUMN_NAME) = 2  -- Both columns in same index
  AND NON_UNIQUE = 0;  -- Must be unique

-- STEP 2: Note the Key_name from the result above
-- Common names might be:
--   - bids_inquiry_id_supplier_id
--   - bids_inquiryId_supplierId
--   - bids_inquiryId_supplierId_unique
--   - Or something else

-- STEP 3: Drop the foreign key constraints first (if needed)
-- Try this if dropping the index fails:
SET FOREIGN_KEY_CHECKS = 0;
ALTER TABLE `bids` DROP INDEX `KEY_NAME_FROM_STEP_1`;
SET FOREIGN_KEY_CHECKS = 1;

-- STEP 4: Recreate foreign keys (if you disabled FK checks)
ALTER TABLE `bids` 
  ADD CONSTRAINT `bids_inquiryId_fk` FOREIGN KEY (`inquiryId`) REFERENCES `inquiries` (`id`) ON DELETE CASCADE;

ALTER TABLE `bids` 
  ADD CONSTRAINT `bids_supplierId_fk` FOREIGN KEY (`supplierId`) REFERENCES `suppliers` (`id`) ON DELETE CASCADE;

-- STEP 5: Verify
SHOW INDEX FROM `bids` WHERE Column_name IN ('inquiryId', 'supplierId');
-- Should see idx_bids_inquiry_supplier with Non_unique = 1
-- Should NOT see any index with Non_unique = 0

