<?php
declare(strict_types=1);
// ==================================================
// Nuclear Fancy Pants Edition™ -- NUCLEAR+++
// File: /home/ploi/automarketer-ai.com/public/wp-content/plugins/automarketer-ai/migrations/033_scheduled_posts_platform_ids.php
// Description: Adds x_post_id and instagram_media_id columns to wp_amai_scheduled_posts - NUCLEAR+++
// Last Edited: 2026-05-14
// ==================================================
namespace AutoMarketerAI\Migrations;
defined('ABSPATH') || exit;
class Migration_033_ScheduledPostsPlatformIds
{
    public function up(): void
    {
        global $wpdb;
        $table = $wpdb->prefix . 'amai_scheduled_posts';

        // Add x_post_id after facebook_post_id
        $col_x = $wpdb->get_var(
            $wpdb->prepare(
                "SELECT COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_SCHEMA = %s AND TABLE_NAME = %s AND COLUMN_NAME = 'x_post_id'",
                DB_NAME,
                $table
            )
        );
        if ($col_x === null) {
            $wpdb->query("ALTER TABLE `{$table}` ADD COLUMN `x_post_id` VARCHAR(64) NULL DEFAULT NULL AFTER `facebook_post_id`");
        }

        // Add instagram_media_id after x_post_id
        $col_ig = $wpdb->get_var(
            $wpdb->prepare(
                "SELECT COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_SCHEMA = %s AND TABLE_NAME = %s AND COLUMN_NAME = 'instagram_media_id'",
                DB_NAME,
                $table
            )
        );
        if ($col_ig === null) {
            $wpdb->query("ALTER TABLE `{$table}` ADD COLUMN `instagram_media_id` VARCHAR(64) NULL DEFAULT NULL AFTER `x_post_id`");
        }
    }
}