Skip to content

Commit

Permalink
Only prepends a datetime if it is not already set.
Browse files Browse the repository at this point in the history
  • Loading branch information
philipsorensen committed Jan 15, 2025
1 parent 036e965 commit 55382a4
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/PackageServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,12 @@ public static function generateMigrationName(string $migrationFileName, Carbon $
}
}

return database_path($migrationsPath . $now->format('Y_m_d_His') . '_' . Str::of($migrationFileName)->snake()->finish('.php'));
$filename = Str::of($migrationFileName)->snake()->finish('.php');
if (!self::startsWithDatetime($filename)) {
$filename = $now->format('Y_m_d_His') . '_' . $filename;
}

return database_path($migrationsPath . $filename);
}

public function registeringPackage()
Expand Down Expand Up @@ -248,4 +253,9 @@ protected function discoverMigrations(): void
}
}
}

private static function startsWithDatetime(string $string): bool {
$pattern = '/^\d{4}_\d{2}_\d{2}_\d{6}_/'; // Y_M_D_HIS_
return preg_match($pattern, $string) === 1;
}
}

0 comments on commit 55382a4

Please sign in to comment.