-- Fix conversations table to add AUTO_INCREMENT to id column
-- This script ensures the conversations table has AUTO_INCREMENT enabled

-- Check if AUTO_INCREMENT needs to be added
-- If the table already has AUTO_INCREMENT, this will just update the next value

ALTER TABLE `conversations`
  MODIFY `id` int NOT NULL AUTO_INCREMENT;

-- Set the AUTO_INCREMENT value to be higher than existing IDs
-- This prevents conflicts with existing data
SET @max_id = (SELECT COALESCE(MAX(id), 0) FROM conversations);
SET @sql = CONCAT('ALTER TABLE conversations AUTO_INCREMENT = ', @max_id + 1);
PREPARE stmt FROM @sql;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;





