SET @questions_published_at_exists = (
    SELECT COUNT(*)
    FROM information_schema.COLUMNS
    WHERE TABLE_SCHEMA = DATABASE()
      AND TABLE_NAME = 'questions'
      AND COLUMN_NAME = 'published_at'
);

SET @questions_published_at_sql = IF(
    @questions_published_at_exists = 0,
    'ALTER TABLE questions ADD COLUMN published_at DATETIME NULL AFTER meta_description',
    'SELECT 1'
);

PREPARE questions_published_at_stmt FROM @questions_published_at_sql;

EXECUTE questions_published_at_stmt;

DEALLOCATE PREPARE questions_published_at_stmt;

SET @questions_rejected_reason_exists = (
    SELECT COUNT(*)
    FROM information_schema.COLUMNS
    WHERE TABLE_SCHEMA = DATABASE()
      AND TABLE_NAME = 'questions'
      AND COLUMN_NAME = 'rejected_reason'
);

SET @questions_rejected_reason_sql = IF(
    @questions_rejected_reason_exists = 0,
    'ALTER TABLE questions ADD COLUMN rejected_reason VARCHAR(255) NULL AFTER published_at',
    'SELECT 1'
);

PREPARE questions_rejected_reason_stmt FROM @questions_rejected_reason_sql;

EXECUTE questions_rejected_reason_stmt;

DEALLOCATE PREPARE questions_rejected_reason_stmt;
