mirror of
https://github.com/archtechx/tenancy.git
synced 2025-12-12 12:54:05 +00:00
Cleanup commands
This commit is contained in:
parent
8d382024a3
commit
33fcb8a936
6 changed files with 60 additions and 37 deletions
|
|
@ -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')];
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -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')];
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -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')];
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
11
src/Traits/DealsWithMigrations.php
Normal file
11
src/Traits/DealsWithMigrations.php
Normal file
|
|
@ -0,0 +1,11 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Stancl\Tenancy\Traits;
|
||||||
|
|
||||||
|
trait DealsWithMigrations
|
||||||
|
{
|
||||||
|
protected function getMigrationPaths()
|
||||||
|
{
|
||||||
|
return [database_path('migrations/tenant')];
|
||||||
|
}
|
||||||
|
}
|
||||||
13
src/Traits/HasATenantsOption.php
Normal file
13
src/Traits/HasATenantsOption.php
Normal 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
24
tests/CommandsTest.php
Normal 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();
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue