TableCommand.php
TLDR
This file contains a class called TableCommand
which extends MigrationGeneratorCommand
and is used to create a migration for the queue jobs database table.
Methods
migrationTableName
This method returns the migration table name by accessing the queue.connections.database.table
configuration value from Laravel.
migrationStubFile
This method returns the path to the migration stub file.
migrationExists
This method determines whether a migration for the table already exists. If the table name is "jobs", it checks if there are any migration files in the Laravel migrations directory that match the predefined pattern for creating the jobs table. Otherwise, it calls the parent implementation of migrationExists
.
Classes
Class TableCommand
This class extends MigrationGeneratorCommand
and is responsible for creating a migration for the queue jobs database table. It has the following properties:
-
$name
: The console command name (set to'make:queue-table'
). -
$aliases
: The console command name aliases (set to['queue:table']
). -
$description
: The console command description (set to'Create a migration for the queue jobs database table'
).
The class also overrides the following methods:
-
migrationTableName()
: Returns the migration table name. -
migrationStubFile()
: Returns the path to the migration stub file. -
migrationExists($table)
: Determines whether a migration for the table already exists.
<?php
namespace Illuminate\Queue\Console;
use Illuminate\Console\MigrationGeneratorCommand;
use Symfony\Component\Console\Attribute\AsCommand;
use function Illuminate\Filesystem\join_paths;
#[AsCommand(name: 'make:queue-table')]
class TableCommand extends MigrationGeneratorCommand
{
/**
* The console command name.
*
* @var string
*/
protected $name = 'make:queue-table';
/**
* The console command name aliases.
*
* @var array
*/
protected $aliases = ['queue:table'];
/**
* The console command description.
*
* @var string
*/
protected $description = 'Create a migration for the queue jobs database table';
/**
* Get the migration table name.
*
* @return string
*/
protected function migrationTableName()
{
return $this->laravel['config']['queue.connections.database.table'];
}
/**
* Get the path to the migration stub file.
*
* @return string
*/
protected function migrationStubFile()
{
return __DIR__.'/stubs/jobs.stub';
}
/**
* Determine whether a migration for the table already exists.
*
* @param string $table
* @return bool
*/
protected function migrationExists($table)
{
if ($table !== 'jobs') {
return parent::migrationExists($table);
}
return count($this->files->glob(sprintf(
'{%s,%s}',
join_paths($this->laravel->databasePath('migrations'), '*_*_*_*_create_'.$table.'_table.php'),
join_paths($this->laravel->databasePath('migrations'), '0001_01_01_000002_create_jobs_table.php'),
))) !== 0;
}
}