SET @meta_title_exists = (
    SELECT COUNT(*)
    FROM information_schema.COLUMNS
    WHERE TABLE_SCHEMA = DATABASE()
      AND TABLE_NAME = 'questions'
      AND COLUMN_NAME = 'meta_title'
);
SET @meta_title_sql = IF(
    @meta_title_exists = 0,
    'ALTER TABLE questions ADD COLUMN meta_title VARCHAR(255) NULL AFTER meta_description',
    'SELECT 1'
);
PREPARE meta_title_stmt FROM @meta_title_sql;
EXECUTE meta_title_stmt;
DEALLOCATE PREPARE meta_title_stmt;

SET @canonical_url_exists = (
    SELECT COUNT(*)
    FROM information_schema.COLUMNS
    WHERE TABLE_SCHEMA = DATABASE()
      AND TABLE_NAME = 'questions'
      AND COLUMN_NAME = 'canonical_url'
);
SET @canonical_url_sql = IF(
    @canonical_url_exists = 0,
    'ALTER TABLE questions ADD COLUMN canonical_url VARCHAR(500) NULL AFTER meta_title',
    'SELECT 1'
);
PREPARE canonical_url_stmt FROM @canonical_url_sql;
EXECUTE canonical_url_stmt;
DEALLOCATE PREPARE canonical_url_stmt;

SET @seo_index_exists = (
    SELECT COUNT(*)
    FROM information_schema.COLUMNS
    WHERE TABLE_SCHEMA = DATABASE()
      AND TABLE_NAME = 'questions'
      AND COLUMN_NAME = 'seo_index'
);
SET @seo_index_sql = IF(
    @seo_index_exists = 0,
    'ALTER TABLE questions ADD COLUMN seo_index VARCHAR(16) NOT NULL DEFAULT ''inherit'' AFTER canonical_url',
    'SELECT 1'
);
PREPARE seo_index_stmt FROM @seo_index_sql;
EXECUTE seo_index_stmt;
DEALLOCATE PREPARE seo_index_stmt;
