Skip to content

Commit

Permalink
Merge pull request #193 from PortableStudios/fix/migrations
Browse files Browse the repository at this point in the history
Adjust migration offsets
  • Loading branch information
kyoungportable authored Oct 18, 2024
2 parents a51c365 + b27826d commit ab40a65
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions src/Providers/FilaCmsServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -226,11 +226,11 @@ public function register()
// Get all the migration stubs and publish them
$filePath = __DIR__.'/../../stubs/database/migrations/auto*.stub';
$files = glob($filePath);
$publishedFiles = [];
foreach ($files as $file) {
$this->publishes([
$file => $this->getMigrationFileName(basename($file, '.stub') . '.php'),
], 'fila-cms-migrations');
$publishedFiles[$file] = $this->getMigrationFileName(basename($file, '.stub') . '.php');
}
$this->publishes($publishedFiles, 'fila-cms-migrations');

// use the vendor configuration file as fallback
$this->mergeConfigFrom(
Expand Down Expand Up @@ -516,10 +516,12 @@ protected function registerHealthChecks()
*/
protected function getMigrationFileName(string $migrationFileName): string
{
$timestamp = date('Y_m_d_His');
// Offset the timestamp by the migration order, to make sure everything stays sequential
$offset = preg_match("/auto\_([0-9]+)\_/", $migrationFileName, $matches) ? $matches[1] : 0;
$timestamp = date('Y_m_d_His', strtotime("+$offset seconds"));

// Remove the auto_ prefix from the migration file name
$migrationFileName = preg_replace("/auto\_[0-9]+\_/", "", $migrationFileName);
$migrationFileName = preg_replace("/auto\_([0-9])+\_/", "", $migrationFileName);

$filesystem = $this->app->make(Filesystem::class);

Expand Down

0 comments on commit ab40a65

Please sign in to comment.