DELIMITER //
CREATE OR REPLACE PROCEDURE migrate_if_needed()
BEGIN
    IF EXISTS (
        SELECT * FROM information_schema.columns 
        WHERE table_name = 'registrations' AND column_name = 'ip'
    ) THEN
        DROP INDEX IF EXISTS idx_ip_created ON registrations;
        ALTER TABLE registrations DROP COLUMN ip;
    END IF;
END //
DELIMITER ;

CALL migrate_if_needed();
DROP PROCEDURE IF EXISTS migrate_if_needed; 