Skip to content

Instantly share code, notes, and snippets.

@ericdowell
Created December 13, 2017 20:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ericdowell/fde4e22dadfdfd0b171b9889ed09c046 to your computer and use it in GitHub Desktop.
Save ericdowell/fde4e22dadfdfd0b171b9889ed09c046 to your computer and use it in GitHub Desktop.
Laravel Dusk - Migrate Database based on .env.dusk file
<?php
namespace Laravel\Dusk\Console\Migrations;
use Laravel\Dusk\Console\DuskCommand as Command;
class FreshCommand extends Command
{
/**
* The console command name.
*
* @var string
*/
protected $name = 'dusk:migrate:fresh';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Drop all tables and re-run all migrations based on env.dusk file configurations';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
return $this->withDuskEnvironment(function () {
$options = array_filter($this->options());
return $this->call('migrate:fresh', $options);
});
}
/**
* Get the console command options.
*
* @return array
*/
protected function getOptions()
{
return [
['database', null, InputOption::VALUE_OPTIONAL, 'The database connection to use.'],
['force', null, InputOption::VALUE_NONE, 'Force the operation to run when in production.'],
['path', null, InputOption::VALUE_OPTIONAL, 'The path of migrations files to be executed.'],
['seed', null, InputOption::VALUE_NONE, 'Indicates if the seed task should be re-run.'],
['seeder', null, InputOption::VALUE_OPTIONAL, 'The class name of the root seeder.'],
];
}
}
<?php
namespace Laravel\Dusk\Console\Migrations;
use Laravel\Dusk\Console\DuskCommand as Command;
class MigrateCommand extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'dusk:migrate {--database= : The database connection to use.}
{--force : Force the operation to run when in production.}
{--path= : The path of migrations files to be executed.}
{--pretend : Dump the SQL queries that would be run.}
{--seed : Indicates if the seed task should be re-run.}
{--step : Force the migrations to be run so they can be rolled back individually.}';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Run the database migrations based on env.dusk file configurations';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
return $this->withDuskEnvironment(function () {
$options = array_filter($this->options());
return $this->call('migrate', $options);
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment