<?php
declare(strict_types=1);

use Phinx\Db\Adapter\AdapterInterface;
use Phinx\Migration\AbstractMigration;

/**
 * Adds a `run_after` epoch column so a queued job can be deferred until a
 * future time (the basis for scheduled-retry / exponential backoff).
 *
 * Non-breaking: defaults to 0, which the task finder treats as "due now",
 * so all existing jobs and any caller that doesn't set it behave exactly
 * as before.
 */
final class AddRunAfterToJobQueue extends AbstractMigration
{
    public function change(): void
    {
        $this->table('job_queue')
            ->addColumn('run_after', AdapterInterface::PHINX_TYPE_INTEGER, [
                'signed'  => false,
                'null'    => false,
                'default' => 0,
                'after'   => 'attempts',
                'comment' => 'epoch; job is skipped until now >= run_after (0 = due immediately)',
            ])
            ->addIndex('run_after')
            ->update();
    }
}
