-- Migration: Add tv_rating column to anime table
-- Date: 2025-01-20
-- Description: Adds tv_rating field to store content rating (PG, R+, etc.)

-- Check if column exists, if not add it
SET @dbname = DATABASE();
SET @tablename = 'anime';
SET @columnname = 'tv_rating';
SET @preparedStatement = (SELECT IF(
  (
    SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS
    WHERE
      (TABLE_SCHEMA = @dbname)
      AND (TABLE_NAME = @tablename)
      AND (COLUMN_NAME = @columnname)
  ) > 0,
  'SELECT 1', -- Column exists, do nothing
  CONCAT('ALTER TABLE ', @tablename, ' ADD COLUMN ', @columnname, ' VARCHAR(50) AFTER tv_quality')
));
PREPARE alterIfNotExists FROM @preparedStatement;
EXECUTE alterIfNotExists;
DEALLOCATE PREPARE alterIfNotExists;

-- Alternative simple version (if above doesn't work, uncomment this):
-- ALTER TABLE anime ADD COLUMN tv_rating VARCHAR(50) AFTER tv_quality;

