<?php
declare(strict_types=1);
// ==================================================
// Nuclear Fancy Pants Edition™ — NUCLEAR+++
// File: /migrations/009_instagram_account_id.php
// Description: Add instagram_account_id column to wp_amai_facebook_connection - NUCLEAR+++
// Last Edited: 2026-04-09
// ==================================================
namespace AutoMarketerAI\Migrations;
defined('ABSPATH') || exit;
final class Migration_009_InstagramAccountId
{
    public const VERSION     = '009';
    public const DESCRIPTION = 'Add instagram_account_id column to wp_amai_facebook_connection';
    public function up(): void
    {
        global $wpdb;
        $table = $wpdb->prefix . 'amai_facebook_connection';
        $exists = $wpdb->get_results(
            "SHOW COLUMNS FROM `{$table}` LIKE 'instagram_account_id'"
        );
        if (empty($exists)) {
            $wpdb->query(
                "ALTER TABLE `{$table}`
                 ADD COLUMN `instagram_account_id` VARCHAR(64) NULL DEFAULT NULL
                 AFTER `access_token_enc`"
            );
        }
    }
    public function down(): void
    {
        global $wpdb;
        $table = $wpdb->prefix . 'amai_facebook_connection';
        $exists = $wpdb->get_results(
            "SHOW COLUMNS FROM `{$table}` LIKE 'instagram_account_id'"
        );
        if (!empty($exists)) {
            $wpdb->query("ALTER TABLE `{$table}` DROP COLUMN `instagram_account_id`");
        }
    }
}