Skip to content

Commit

Permalink
Prevent creation of duplicate migration file
Browse files Browse the repository at this point in the history
In the event of a user erroneously running the rateable:migration command multiple times, prevent creation if the file already exists with a different timestamp
  • Loading branch information
willvincent committed Sep 20, 2019
1 parent 010bcbf commit b837309
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/commands/MigrationCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,9 @@ protected function createMigration()
{
$migration_file = database_path('migrations').'/'.date('Y_m_d_His').'_create_ratings_table.php';

if (! file_exists($migration_file) && $fs = fopen($migration_file, 'x')) {
$existing = glob(database_path('migrations').'/*_create_ratings_table.php');

if (empty($existing) && $fs = fopen($migration_file, 'x')) {
fwrite($fs, file_get_contents(__DIR__.'/../migrations/create_ratings_table.php'));
fclose($fs);
return true;
Expand Down

0 comments on commit b837309

Please sign in to comment.