diff --git a/src/Illuminate/Database/Console/Migrations/BaseCommand.php b/src/Illuminate/Database/Console/Migrations/BaseCommand.php index 81ca3cc75e6d..ba48921eb41e 100755 --- a/src/Illuminate/Database/Console/Migrations/BaseCommand.php +++ b/src/Illuminate/Database/Console/Migrations/BaseCommand.php @@ -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(); } diff --git a/src/Illuminate/Database/Console/Migrations/FreshCommand.php b/src/Illuminate/Database/Console/Migrations/FreshCommand.php index a9779a795f39..2def1c0d6311 100644 --- a/src/Illuminate/Database/Console/Migrations/FreshCommand.php +++ b/src/Illuminate/Database/Console/Migrations/FreshCommand.php @@ -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.'], diff --git a/src/Illuminate/Database/Console/Migrations/MigrateCommand.php b/src/Illuminate/Database/Console/Migrations/MigrateCommand.php index 12fe90af9911..ebf16855a3eb 100755 --- a/src/Illuminate/Database/Console/Migrations/MigrateCommand.php +++ b/src/Illuminate/Database/Console/Migrations/MigrateCommand.php @@ -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.}'; diff --git a/src/Illuminate/Database/Console/Migrations/MigrateMakeCommand.php b/src/Illuminate/Database/Console/Migrations/MigrateMakeCommand.php index 03995de99d2e..23b0651dbf6f 100644 --- a/src/Illuminate/Database/Console/Migrations/MigrateMakeCommand.php +++ b/src/Illuminate/Database/Console/Migrations/MigrateMakeCommand.php @@ -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. @@ -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(); diff --git a/src/Illuminate/Database/Console/Migrations/RefreshCommand.php b/src/Illuminate/Database/Console/Migrations/RefreshCommand.php index dc89091c1eba..c8ae9b341661 100755 --- a/src/Illuminate/Database/Console/Migrations/RefreshCommand.php +++ b/src/Illuminate/Database/Console/Migrations/RefreshCommand.php @@ -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.'], diff --git a/src/Illuminate/Database/Console/Migrations/ResetCommand.php b/src/Illuminate/Database/Console/Migrations/ResetCommand.php index c2efdfa68954..82e79bffdeb1 100755 --- a/src/Illuminate/Database/Console/Migrations/ResetCommand.php +++ b/src/Illuminate/Database/Console/Migrations/ResetCommand.php @@ -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.'], ]; } diff --git a/src/Illuminate/Database/Console/Migrations/RollbackCommand.php b/src/Illuminate/Database/Console/Migrations/RollbackCommand.php index 3315d643a898..d86d5db711e2 100755 --- a/src/Illuminate/Database/Console/Migrations/RollbackCommand.php +++ b/src/Illuminate/Database/Console/Migrations/RollbackCommand.php @@ -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.'], diff --git a/src/Illuminate/Database/Console/Migrations/StatusCommand.php b/src/Illuminate/Database/Console/Migrations/StatusCommand.php index d5f2fe425dc7..e8612f1578e2 100644 --- a/src/Illuminate/Database/Console/Migrations/StatusCommand.php +++ b/src/Illuminate/Database/Console/Migrations/StatusCommand.php @@ -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.'], ]; } } diff --git a/tests/Integration/Database/MigrateWithRealpathTest.php b/tests/Integration/Database/MigrateWithRealpathTest.php new file mode 100644 index 000000000000..e3b95cdfaa68 --- /dev/null +++ b/tests/Integration/Database/MigrateWithRealpathTest.php @@ -0,0 +1,38 @@ + 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, + ]); + } +} diff --git a/tests/Integration/Database/stubs/2014_10_12_000000_create_members_table.php b/tests/Integration/Database/stubs/2014_10_12_000000_create_members_table.php new file mode 100644 index 000000000000..cbc59827d9d9 --- /dev/null +++ b/tests/Integration/Database/stubs/2014_10_12_000000_create_members_table.php @@ -0,0 +1,35 @@ +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'); + } +}