<?php

declare(strict_types=1);

use App\Infrastructure\Db\Migrations\BaseMigration;

final class CreateJobLocks extends BaseMigration
{
    public function change(): void
    {
        $table = $this->table('job_locks', [
            'id' => false,
            'primary_key' => ['job_name'],
        ]);
        $table
            ->addColumn('job_name', 'string', ['limit' => 64, 'null' => false])
            ->addColumn('acquired_by', 'string', ['limit' => 128, 'null' => false]);

        $this->addTimestampColumn($table, 'acquired_at');
        $this->addTimestampColumn($table, 'expires_at');

        $table->addIndex(['expires_at'])->create();
    }
}
