Skip to content

Commit

Permalink
migrations added to micro service provider (#36)
Browse files Browse the repository at this point in the history
  • Loading branch information
shavonn committed Jan 5, 2024
1 parent 279187b commit 2c263ea
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 4 deletions.
27 changes: 25 additions & 2 deletions src/Commands/ArtiMigrationCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,17 @@

namespace HandsomeBrown\Laraca\Commands;

use HandsomeBrown\Laraca\Commands\Traits\Directable;
use HandsomeBrown\Laraca\Commands\Traits\LaracaCommand;
use Illuminate\Database\Console\Migrations\MigrateMakeCommand;
use Illuminate\Database\Migrations\MigrationCreator;
use Illuminate\Support\Composer;
use Symfony\Component\Console\Attribute\AsCommand;

#[AsCommand(name: 'arti:migration')]
class ArtiMigrationCommand extends MigrateMakeCommand
{
use LaracaCommand;
use Directable, LaracaCommand;

/**
* signature
Expand All @@ -24,18 +27,38 @@ class ArtiMigrationCommand extends MigrateMakeCommand
{--realpath : Indicate any provided migration file paths are pre-resolved absolute paths}
{--fullpath : Output the full path of the migration (Deprecated)}';

/**
* Create a new migration install command instance.
*
* @return void
*/
public function __construct(MigrationCreator $creator, Composer $composer)
{
if (self::domainsEnabled()) {
$this->signature = $this->signature.' {--domain= : The name of the domain}';
}

if (self::microservicesEnabled()) {
$this->signature = $this->signature.' {--service= : The name of the service}';
}

parent::__construct($creator, $composer);
}

/**
* getMigrationPath
* Get migration path (either specified by '--path' option or default location).
*/
protected function getMigrationPath(): string
{
[$domain, $service] = $this->gatherPathAssets();

if (! is_null($targetPath = $this->input->getOption('path'))) {
return ! $this->usingRealPath()
? $this->laravel->basePath().'/'.$targetPath
: $targetPath;
}

return self::assembleFullPath('migration');
return self::assembleFullPath('migration', $domain, $service);
}
}
1 change: 1 addition & 0 deletions src/Commands/InitMicroserviceCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ protected function makeDirectories(): void
$elements = [
'channel',
'controller',
'migration',
'provider',
'route',
'test',
Expand Down
4 changes: 2 additions & 2 deletions src/Commands/stubs/serviceprovider.stub
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ class {{ service }}ServiceProvider extends ServiceProvider
$this->app->register(RouteServiceProvider::class);
$this->app->register(BroadcastServiceProvider::class);

View::addNamespace('{{ service }}', realpath(__DIR__.'/../resources/views'));
View::addNamespace('{{ service }}', realpath(__DIR__.'/resources/views'));
}

/**
* Bootstrap services.
*/
public function boot(): void
{
//
$this->loadMigrationsFrom(__DIR__.'/database/migrations');
}
}

0 comments on commit 2c263ea

Please sign in to comment.