<?php
require_once __DIR__ . '/../config.php';

function migrate_022($pdo) {
    try {
        $sql = "ALTER TABLE process_definitions ADD COLUMN is_active TINYINT(1) NOT NULL DEFAULT 1 AFTER definition_json";
        $pdo->exec($sql);
        echo "Migration successful: is_active column added to process_definitions table.\n";
    } catch (PDOException $e) {
        // Ignore if column already exists
        if ($e->getCode() !== '42S21') {
            die("Migration failed: " . $e->getMessage() . "\n");
        }
    }
}

// If called directly, run the migration
if (basename(__FILE__) == basename($_SERVER["SCRIPT_FILENAME"])) {
    require_once __DIR__ . '/../../db/config.php';
    $pdo = db();
    migrate_022($pdo);
}