Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[5.6] Enable developer to use --realpath option to migration commands #22852

Merged
merged 3 commits into from
Jan 23, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/Illuminate/Database/Console/Migrations/BaseCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,14 @@ class BaseCommand extends Command
*/
protected function getMigrationPaths()
{
$realpath = $this->input->hasOption('realpath') && $this->option('realpath');

// Here, we will check to see if a path option has been defined. If it has we will
// use the path relative to the root of the installation folder so our database
// migrations may be run for any customized path from within the application.
if ($this->input->hasOption('path') && $this->option('path')) {
return collect($this->option('path'))->map(function ($path) {
return $this->laravel->basePath().'/'.$path;
return collect($this->option('path'))->map(function ($path) use ($realpath) {
return $realpath ? $path : $this->laravel->basePath().'/'.$path;
})->all();
}

Expand Down
2 changes: 2 additions & 0 deletions src/Illuminate/Database/Console/Migrations/FreshCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,8 @@ protected function getOptions()

['path', null, InputOption::VALUE_OPTIONAL, 'The path of migrations files to be executed.'],

['realpath', null, InputOption::VALUE_NONE, 'Mark the given migration path(s) as realpath.'],

['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.'],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class MigrateCommand extends BaseCommand
protected $signature = '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.}
{--realpath : Mark the given migration path(s) as realpath.}
{--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.}';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ class MigrateMakeCommand extends BaseCommand
protected $signature = 'make:migration {name : The name of the migration.}
{--create= : The table to be created.}
{--table= : The table to migrate.}
{--path= : The location where the migration file should be created.}';
{--path= : The location where the migration file should be created.}
{--realpath : Mark the given migration path as realpath.}';

/**
* The console command description.
Expand Down Expand Up @@ -123,7 +124,9 @@ protected function writeMigration($name, $table, $create)
protected function getMigrationPath()
{
if (! is_null($targetPath = $this->input->getOption('path'))) {
return $this->laravel->basePath().'/'.$targetPath;
$realpath = $this->input->hasOption('realpath') && $this->option('realpath');

return $realpath ? $targetPath : $this->laravel->basePath().'/'.$targetPath;
}

return parent::getMigrationPath();
Expand Down
2 changes: 2 additions & 0 deletions src/Illuminate/Database/Console/Migrations/RefreshCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,8 @@ protected function getOptions()

['path', null, InputOption::VALUE_OPTIONAL, 'The path of migrations files to be executed.'],

['realpath', null, InputOption::VALUE_NONE, 'Mark the given migration path(s) as realpath.'],

['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.'],
Expand Down
2 changes: 2 additions & 0 deletions src/Illuminate/Database/Console/Migrations/ResetCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ protected function getOptions()

['path', null, InputOption::VALUE_OPTIONAL | InputOption::VALUE_IS_ARRAY, 'The path(s) of migrations files to be executed.'],

['realpath', null, InputOption::VALUE_NONE, 'Mark the given migration path(s) as realpath.'],

['pretend', null, InputOption::VALUE_NONE, 'Dump the SQL queries that would be run.'],
];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ protected function getOptions()

['path', null, InputOption::VALUE_OPTIONAL, 'The path of migrations files to be executed.'],

['realpath', null, InputOption::VALUE_NONE, 'Mark the given migration path(s) as realpath.'],

['pretend', null, InputOption::VALUE_NONE, 'Dump the SQL queries that would be run.'],

['step', null, InputOption::VALUE_OPTIONAL, 'The number of migrations to be reverted.'],
Expand Down
2 changes: 2 additions & 0 deletions src/Illuminate/Database/Console/Migrations/StatusCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,8 @@ protected function getOptions()
['database', null, InputOption::VALUE_OPTIONAL, 'The database connection to use.'],

['path', null, InputOption::VALUE_OPTIONAL, 'The path of migrations files to use.'],

['realpath', null, InputOption::VALUE_NONE, 'Mark the given migration path(s) as realpath.'],
];
}
}
38 changes: 38 additions & 0 deletions tests/Integration/Database/MigrateWithRealpathTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php

namespace Illuminate\Tests\Integration\Database;

use Illuminate\Support\Facades\Schema;

class MigrateWithRealpathTest extends DatabaseTestCase
{
protected function setUp()
{
parent::setUp();

$options = [
'--path' => realpath(__DIR__.'/stubs/'),
'--realpath' => true,
];

$this->artisan('migrate', $options);

$this->beforeApplicationDestroyed(function () use ($options) {
$this->artisan('migrate:rollback', $options);
});
}

public function test_realpath_migration_has_properly_executed()
{
$this->assertTrue(Schema::hasTable('members'));
}

public function test_migrations_has_the_migrated_table()
{
$this->assertDatabaseHas('migrations', [
'id' => 1,
'migration' => '2014_10_12_000000_create_members_table',
'batch' => 1,
]);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateMembersTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('members', function (Blueprint $table) {
$table->increments('id');
$table->string('name');
$table->string('email')->unique();
$table->string('password');
$table->rememberToken();
$table->timestamps();
});
}

/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::drop('members');
}
}