BF migration publishing
This commit is contained in:
parent
4d0d354feb
commit
bfc6e729f5
|
|
@ -24,14 +24,9 @@ class ShopServiceProvider extends ServiceProvider
|
||||||
|
|
||||||
// Publish migrations
|
// Publish migrations
|
||||||
$this->publishes([
|
$this->publishes([
|
||||||
__DIR__ . '/../database/migrations' => database_path('migrations'),
|
__DIR__ . '/../database/migrations/create_blax_shop_tables.php.stub' => $this->getMigrationFileName('create_blax_shop_tables.php'),
|
||||||
], 'shop-migrations');
|
], 'shop-migrations');
|
||||||
|
|
||||||
// Load migrations
|
|
||||||
if ($this->app->runningInConsole()) {
|
|
||||||
$this->loadMigrationsFrom(__DIR__ . '/../database/migrations');
|
|
||||||
}
|
|
||||||
|
|
||||||
// Load routes if enabled (API only)
|
// Load routes if enabled (API only)
|
||||||
if (config('shop.routes.enabled', true)) {
|
if (config('shop.routes.enabled', true)) {
|
||||||
$this->loadRoutesFrom(__DIR__ . '/../routes/api.php');
|
$this->loadRoutesFrom(__DIR__ . '/../routes/api.php');
|
||||||
|
|
@ -52,4 +47,19 @@ class ShopServiceProvider extends ServiceProvider
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns existing migration file if found, else uses the current timestamp.
|
||||||
|
*/
|
||||||
|
protected function getMigrationFileName(string $migrationFileName): string
|
||||||
|
{
|
||||||
|
$timestamp = date('Y_m_d_His');
|
||||||
|
|
||||||
|
$filesystem = $this->app->make(\Illuminate\Filesystem\Filesystem::class);
|
||||||
|
|
||||||
|
return \Illuminate\Support\Collection::make([$this->app->databasePath() . DIRECTORY_SEPARATOR . 'migrations' . DIRECTORY_SEPARATOR])
|
||||||
|
->flatMap(fn($path) => $filesystem->glob($path . '*_' . $migrationFileName))
|
||||||
|
->push($this->app->databasePath() . "/migrations/{$timestamp}_{$migrationFileName}")
|
||||||
|
->first();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue