-- ============================================
-- SIMPLE WORKAROUND: Drop unique index by temporarily disabling FK checks
-- ============================================

-- STEP 1: Disable foreign key checks
SET FOREIGN_KEY_CHECKS = 0;

-- STEP 2: Drop the unique index
ALTER TABLE `bids` DROP INDEX `bids_inquiry_id_supplier_id`;

-- STEP 3: Re-enable foreign key checks
SET FOREIGN_KEY_CHECKS = 1;

-- STEP 4: Verify foreign keys still exist (they should)
SELECT 
    CONSTRAINT_NAME,
    TABLE_NAME,
    COLUMN_NAME,
    REFERENCED_TABLE_NAME
FROM INFORMATION_SCHEMA.KEY_COLUMN_USAGE
WHERE TABLE_SCHEMA = DATABASE()
  AND TABLE_NAME = 'bids'
  AND REFERENCED_TABLE_NAME IS NOT NULL;

-- STEP 5: If foreign keys are missing, recreate them:
-- 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 6: Create non-unique index (only if it doesn't exist)
CREATE INDEX IF NOT EXISTS `idx_bids_inquiry_supplier` ON `bids` (`inquiryId`, `supplierId`);

-- STEP 7: Final verification
SHOW INDEX FROM `bids` WHERE Column_name IN ('inquiryId', 'supplierId');
-- Should see idx_bids_inquiry_supplier with Non_unique = 1

