<?php

namespace {{migrations_namespace}};

use Framework\Contracts\Migration;
use Framework\Database\Schema\Structure;
use Framework\Supports\Facades\Schema;

use function Framework\app;

class {{class_name}} implements Migration
{
    public function up()
    {
        Schema::create('{{table}}', function (Structure $table) {
            $table->id();
            $table->string('queue', 191)->default('default');
            $table->integer('priority')->default(0);
            $table->long_text('payload');
            $table->unsigned_tiny_integer('attempts')->default(0);
            $table->unsigned_integer('reserved_at')->nullable();
            $table->string('reserved_by', 32)->nullable();
            $table->unsigned_integer('available_at');
            $table->unsigned_integer('created_at');

            $table->index(
                ['reserved_at', 'available_at', 'priority'],
                app()->prefix() . 'jobs_reserved_at_available_at_priority_index'
            );
            $table->index('reserved_by', app()->prefix() . 'jobs_reserved_by_index');
        });
    }

    public function down()
    {
        Schema::drop_if_exists('{{table}}');
    }
}
