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

try {
    $pdo = db();

    echo "Starting migration 021: Rename camelCase columns to snake_case...\n";

    // Process instances table
    $pdo->exec("ALTER TABLE `process_instances` CHANGE `lastActivityAt` `last_activity_at` TIMESTAMP NULL;");
    
    echo "Columns in 'process_instances' table renamed.\n";

    // Process events table
    $pdo->exec("ALTER TABLE `process_events` CHANGE `processInstanceId` `process_instance_id` INT(11) UNSIGNED NOT NULL;");
    $pdo->exec("ALTER TABLE `process_events` CHANGE `createdBy` `created_by` INT(11) UNSIGNED NOT NULL;");
    $pdo->exec("ALTER TABLE `process_events` CHANGE `createdAt` `created_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP;");

    echo "Columns in 'process_events' table renamed.\n";

    echo "Migration 021 completed successfully.\n";

} catch (PDOException $e) {
    die("Migration 021 failed: " . $e->getMessage());
}

