From b8373095fad88c284a6e0a6ee8a6ec69d7e5c1c0 Mon Sep 17 00:00:00 2001 From: Will Vincent Date: Fri, 20 Sep 2019 12:13:31 -0500 Subject: [PATCH] Prevent creation of duplicate migration file 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 --- src/commands/MigrationCommand.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/commands/MigrationCommand.php b/src/commands/MigrationCommand.php index ac166dc..a6912b3 100644 --- a/src/commands/MigrationCommand.php +++ b/src/commands/MigrationCommand.php @@ -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;