Skip to content

Commit

Permalink
Fix migration publishing order on install
Browse files Browse the repository at this point in the history
  • Loading branch information
ifox committed Aug 21, 2019
1 parent 1031272 commit 97cb478
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/TwillServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ class TwillServiceProvider extends ServiceProvider
ActivitylogServiceProvider::class,
];

private $migrationsCounter = 0;

/**
* Bootstraps the package services.
*
Expand Down Expand Up @@ -260,12 +262,14 @@ private function publishMigrations()
private function publishMigration($migration, $publishKey = null)
{
$files = new Filesystem;
$this->migrationsCounter += 1;

if (!class_exists($migration)) {
// Verify that migration doesn't exist
$migration_file = database_path('migrations/*_' . snake_case($migration) . '.php');
if (empty($files->glob($migration_file))) {
$timestamp = date('Y_m_d_His', time());
$timestamp = date('Y_m_d_', time()) . (30000 + $this->migrationsCounter);

$this->publishes([
__DIR__ . '/../migrations/' . snake_case($migration) . '.php' => database_path('migrations/' . $timestamp . '_' . snake_case($migration) . '.php'),
], ['migrations'] + (is_null($publishKey) ? [] : [$publishKey]));
Expand Down

0 comments on commit 97cb478

Please sign in to comment.