Skip to content

Commit

Permalink
Adjust migration offsets
Browse files Browse the repository at this point in the history
  • Loading branch information
kyoungportable committed Oct 18, 2024
1 parent 3fb7798 commit dc2faad
Showing 1 changed file with 15 additions and 9 deletions.
24 changes: 15 additions & 9 deletions src/Providers/FilaCmsServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -223,13 +223,16 @@ public function register()
__DIR__ . '/../../config/fila-cms.php' => config_path('fila-cms.php'),
], 'fila-cms-config');

// Get all the migration stubs and publish them
$filePath = __DIR__.'/../../stubs/database/migrations/auto*.stub';
$files = glob($filePath);
foreach ($files as $file) {
$this->publishes([
$file => $this->getMigrationFileName(basename($file, '.stub') . '.php'),
], 'fila-cms-migrations');
// Only publish migrations if we're running inthe cli
if ($this->app->runningInConsole()) {
// Get all the migration stubs and publish them
$filePath = __DIR__.'/../../stubs/database/migrations/auto*.stub';
$files = glob($filePath);
foreach ($files as $file) {
$this->publishes([
$file => $this->getMigrationFileName(basename($file, '.stub') . '.php'),
], 'fila-cms-migrations');
}
}

// use the vendor configuration file as fallback
Expand Down Expand Up @@ -516,10 +519,13 @@ 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 dc2faad

Please sign in to comment.