<?php
declare(strict_types=1);

return function (\App\Core\Database $db): void {
    $exists = $db->selectOne(
        "SELECT 1 FROM information_schema.columns WHERE table_schema = DATABASE() AND table_name = 'workflow_instances' AND column_name = 'created_by'"
    );
    if (!$exists) {
        $db->raw("ALTER TABLE workflow_instances ADD COLUMN created_by BIGINT UNSIGNED NULL AFTER completed_at");
    }

    $exists2 = $db->selectOne(
        "SELECT 1 FROM information_schema.columns WHERE table_schema = DATABASE() AND table_name = 'workflow_transition_log' AND column_name = 'created_by'"
    );
    if (!$exists2) {
        $db->raw("ALTER TABLE workflow_transition_log ADD COLUMN created_by BIGINT UNSIGNED NULL AFTER created_at");
    }
};
