1
0
Fork 0
mirror of https://github.com/archtechx/tenancy.git synced 2025-12-12 12:44:02 +00:00

Cleanup commands

This commit is contained in:
Samuel Štancl 2019-02-09 00:40:52 +01:00
parent 8d382024a3
commit 33fcb8a936
6 changed files with 60 additions and 37 deletions

View file

@ -5,11 +5,15 @@ namespace Stancl\Tenancy\Commands;
use Illuminate\Console\Command; use Illuminate\Console\Command;
use Stancl\Tenancy\DatabaseManager; use Stancl\Tenancy\DatabaseManager;
use Illuminate\Database\Migrations\Migrator; use Illuminate\Database\Migrations\Migrator;
use Stancl\Tenancy\Traits\HasATenantsOption;
use Stancl\Tenancy\Traits\DealsWithMigrations;
use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Input\InputOption;
use Illuminate\Database\Console\Migrations\MigrateCommand; use Illuminate\Database\Console\Migrations\MigrateCommand;
class Migrate extends MigrateCommand class Migrate extends MigrateCommand
{ {
use HasATenantsOption, DealsWithMigrations;
protected $database; protected $database;
/** /**
@ -54,16 +58,4 @@ class Migrate extends MigrateCommand
parent::handle(); parent::handle();
}); });
} }
protected function getOptions()
{
return array_merge([
['tenants', null, InputOption::VALUE_IS_ARRAY | InputOption::VALUE_OPTIONAL, '', null]
], parent::getOptions());
}
protected function getMigrationPaths()
{
return [database_path('migrations/tenant')];
}
} }

View file

@ -5,11 +5,15 @@ namespace Stancl\Tenancy\Commands;
use Illuminate\Console\Command; use Illuminate\Console\Command;
use Stancl\Tenancy\DatabaseManager; use Stancl\Tenancy\DatabaseManager;
use Illuminate\Database\Migrations\Migrator; use Illuminate\Database\Migrations\Migrator;
use Stancl\Tenancy\Traits\HasATenantsOption;
use Stancl\Tenancy\Traits\DealsWithMigrations;
use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Input\InputOption;
use Illuminate\Database\Console\Migrations\RollbackCommand; use Illuminate\Database\Console\Migrations\RollbackCommand;
class Rollback extends RollbackCommand class Rollback extends RollbackCommand
{ {
use HasATenantsOption, DealsWithMigrations;
protected $database; protected $database;
/** /**
@ -54,16 +58,4 @@ class Rollback extends RollbackCommand
parent::handle(); parent::handle();
}); });
} }
protected function getOptions()
{
return array_merge([
['tenants', null, InputOption::VALUE_IS_ARRAY | InputOption::VALUE_OPTIONAL, '', null]
], parent::getOptions());
}
protected function getMigrationPaths()
{
return [database_path('migrations/tenant')];
}
} }

View file

@ -4,6 +4,7 @@ namespace Stancl\Tenancy\Commands;
use Illuminate\Console\Command; use Illuminate\Console\Command;
use Stancl\Tenancy\DatabaseManager; use Stancl\Tenancy\DatabaseManager;
use Stancl\Tenancy\Traits\HasATenantsOption;
use Illuminate\Database\Migrations\Migrator; use Illuminate\Database\Migrations\Migrator;
use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Input\InputOption;
use Illuminate\Database\Console\Seeds\SeedCommand; use Illuminate\Database\Console\Seeds\SeedCommand;
@ -11,6 +12,8 @@ use Illuminate\Database\ConnectionResolverInterface;
class Seed extends SeedCommand class Seed extends SeedCommand
{ {
use HasATenantsOption;
protected $database; protected $database;
/** /**
@ -51,20 +54,8 @@ class Seed extends SeedCommand
$this->line("Tenant: {$tenant['uuid']} ({$tenant['domain']})"); $this->line("Tenant: {$tenant['uuid']} ({$tenant['domain']})");
$this->database->connectToTenant($tenant); $this->database->connectToTenant($tenant);
// Migrate // Seed
parent::handle(); parent::handle();
}); });
} }
protected function getOptions()
{
return array_merge([
['tenants', null, InputOption::VALUE_IS_ARRAY | InputOption::VALUE_OPTIONAL, '', null]
], parent::getOptions());
}
protected function getMigrationPaths()
{
return [database_path('migrations/tenant')];
}
} }

View file

@ -0,0 +1,11 @@
<?php
namespace Stancl\Tenancy\Traits;
trait DealsWithMigrations
{
protected function getMigrationPaths()
{
return [database_path('migrations/tenant')];
}
}

View file

@ -0,0 +1,13 @@
<?php
namespace Stancl\Tenancy\Traits;
trait HasATenantsOption
{
protected function getOptions()
{
return array_merge([
['tenants', null, InputOption::VALUE_IS_ARRAY | InputOption::VALUE_OPTIONAL, '', null]
], parent::getOptions());
}
}

24
tests/CommandsTest.php Normal file
View file

@ -0,0 +1,24 @@
<?php
namespace Stancl\Tenancy\Tests;
class CommandsTest extends TestCase
{
/** @test */
public function migrate_command_works()
{
$this->markTestIncomplete();
}
/** @test */
public function rollback_command_works()
{
$this->markTestIncomplete();
}
/** @test */
public function seed_command_works()
{
$this->markTestIncomplete();
}
}