Skip to content

Commit

Permalink
Merge branch 'realpath-migrate' of https://github.com/crynobone/frame…
Browse files Browse the repository at this point in the history
…work into crynobone-realpath-migrate
  • Loading branch information
taylorotwell committed Jan 23, 2018
2 parents 8808758 + fc3deb5 commit 0671f31
Show file tree
Hide file tree
Showing 10 changed files with 93 additions and 4 deletions.
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');
}
}

0 comments on commit 0671f31

Please sign in to comment.