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;

    IF NOT EXISTS (
        SELECT * FROM information_schema.columns 
        WHERE table_name = 'users' AND column_name = 'is_blocked'
    ) THEN
        ALTER TABLE users 
        ADD COLUMN is_blocked TINYINT(1) NOT NULL DEFAULT 0,
        ADD COLUMN block_reason TEXT;
    END IF;
END //
DELIMITER ;

CALL migrate_if_needed();
DROP PROCEDURE IF EXISTS migrate_if_needed; 