-- ============================================================================
-- Migration v12: Adsterra pixel-based positioning (replaces the old
-- top/bottom/left/right dropdown) + premium UI CSS (no DB change needed for
-- that part — just re-upload assets/css/style.css).
-- Run this ONCE on your existing database (phpMyAdmin > SQL tab).
-- Safe to run more than once.
-- ============================================================================

ALTER TABLE adsterra_ads
    ADD COLUMN IF NOT EXISTS position_top INT DEFAULT NULL AFTER height,
    ADD COLUMN IF NOT EXISTS position_bottom INT DEFAULT NULL AFTER position_top,
    ADD COLUMN IF NOT EXISTS position_left INT DEFAULT NULL AFTER position_bottom,
    ADD COLUMN IF NOT EXISTS position_right INT DEFAULT NULL AFTER position_left;

-- Best-effort migration of old dropdown values into a sensible pixel default,
-- so existing banners don't just disappear after this update.
UPDATE adsterra_ads SET position_top = 20 WHERE position = 'top' AND position_top IS NULL;
UPDATE adsterra_ads SET position_bottom = 20 WHERE position = 'bottom' AND position_bottom IS NULL;
UPDATE adsterra_ads SET position_left = 20 WHERE position = 'left' AND position_left IS NULL;
UPDATE adsterra_ads SET position_right = 20 WHERE position = 'right' AND position_right IS NULL;
