diff --git a/src/Illuminate/Session/Console/SessionTableCommand.php b/src/Illuminate/Session/Console/SessionTableCommand.php index 9b0c9b66b598..54c935a36516 100644 --- a/src/Illuminate/Session/Console/SessionTableCommand.php +++ b/src/Illuminate/Session/Console/SessionTableCommand.php @@ -60,6 +60,12 @@ public function __construct(Filesystem $files, Composer $composer) */ public function handle() { + if ($this->migrationExists()) { + $this->components->error('Migration already exists.'); + + return 1; + } + $fullPath = $this->createBaseMigration(); $this->files->put($fullPath, $this->files->get(__DIR__.'/stubs/database.stub')); @@ -80,4 +86,16 @@ protected function createBaseMigration() return $this->laravel['migration.creator']->create($name, $path); } + + /** + * Determine whether the session table migration already exists. + * + * @return bool + */ + protected function migrationExists() + { + return count($this->files->glob( + $this->laravel->joinPaths($this->laravel->databasePath('migrations'), '*_*_*_*_create_sessions_table.php') + )) !== 0; + } } diff --git a/tests/Session/SessionTableCommandTest.php b/tests/Session/SessionTableCommandTest.php index db7be0998ca3..f9aed6e571da 100644 --- a/tests/Session/SessionTableCommandTest.php +++ b/tests/Session/SessionTableCommandTest.php @@ -33,6 +33,7 @@ public function testCreateMakesMigration() $command->setLaravel($app); $path = __DIR__.'/migrations'; $creator->shouldReceive('create')->once()->with('create_sessions_table', $path)->andReturn($path); + $files->shouldReceive('glob')->once()->with($app->joinPaths($app->databasePath('migrations'), '*_*_*_*_create_sessions_table.php'))->andReturn([]); $files->shouldReceive('get')->once()->andReturn('foo'); $files->shouldReceive('put')->once()->with($path, 'foo');