SET @dbname = DATABASE();
SET @tablename = 'redemption_code';
SET @colname = 'status';
SET @sql = (
    SELECT IF(
        COUNT(*) = 0,
        'ALTER TABLE `redemption_code` ADD COLUMN `status` TINYINT NOT NULL DEFAULT 1 COMMENT ''Status: 1=enabled, 0=disabled'' AFTER `quantity`;',
        'SELECT "Column `status` already exists";'
    )
    FROM information_schema.COLUMNS
    WHERE TABLE_SCHEMA = @dbname
      AND TABLE_NAME = @tablename
      AND COLUMN_NAME = @colname
);
PREPARE stmt FROM @sql;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
