<commit_before><?php

namespace EJLab\Laravel\MultiTenant\Commands\Migrate;

use App\Tenant;
use EJLab\Laravel\MultiTenant\DatabaseManager;
use DB;
use Illuminate\Database\Console\Migrations\MigrateCommand as BaseMigrateCommand;

class MigrateCommand extends BaseMigrateCommand
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = "migrate {--database= : The database connection to use.}
                {--force : Force the operation to run when in production.}
                {--path= : The path of migrations files to be executed.}
                {--pretend : Dump the SQL queries that would be run.}
                {--seed : Indicates if the seed task should be re-run.}
                {--step : Force the migrations to be run so they can be rolled back individually.}
                {--T|tenant : Run migrations for tenant. '--database' option will be ignored. use '--domain' instead.}
                {--domain= : The domain for tenant. 'all' or null value for all tenants.}";
    
    /**
     * Execute the console command.
     *
     * @return void
     */
    public function fire()
    {
        if (! $this->confirmToProceed()) {
            return;
        }

        if ($this->input->getOption('tenant')) {

            $domain = $this->input->getOption('domain') ?: 'all';

            $manager = new DatabaseManager();
            DB::setDefaultConnection($manager->systemConnectionName);
            
            if ($domain == 'all') $tenants = Tenant::all();
            else $tenants = Tenant::where('domain', $domain)->get();

            $drawBar = (count($tenants) > 1);

            if ($drawBar) $bar = $this->output->createProgressBar(count($tenants));

            $paths = [];
            foreach ($this->getMigrationPaths() as $path) {
                $paths[] = $path.DIRECTORY_SEPARATOR.'tenant';
            }

            foreach ($tenants as $tenant) {
                
                $manager->setConnection($tenant);
                $this->migrator->setConnection($manager->tenantConnectionName);

                if (! $this->migrator->repositoryExists()) {
                    $this->call('migrate:install', ['--tenant' => TRUE, '--domain' => $tenant->domain]);
                    DB::setDefaultConnection($manager->tenantConnectionName);
                }

                // Next, we will check to see if a path option has been defined. If it has
                // we will use the path relative to the root of this installation folder
                // so that migrations may be run for any path within the applications.
                $this->migrator->run($paths, [
                    'pretend' => $this->option('pretend'),
                    'step' => $this->option('step'),
                ]);<commit_msg>migrate 명령어 정보표시 개선<commit_after><?php

namespace EJLab\Laravel\MultiTenant\Commands\Migrate;

use App\Tenant;
use EJLab\Laravel\MultiTenant\DatabaseManager;
use DB;
use Illuminate\Database\Console\Migrations\MigrateCommand as BaseMigrateCommand;

class MigrateCommand extends BaseMigrateCommand
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = "migrate {--database= : The database connection to use.}
                {--force : Force the operation to run when in production.}
                {--path= : The path of migrations files to be executed.}
                {--pretend : Dump the SQL queries that would be run.}
                {--seed : Indicates if the seed task should be re-run.}
                {--step : Force the migrations to be run so they can be rolled back individually.}
                {--T|tenant : Run migrations for tenant. '--database' option will be ignored. use '--domain' instead.}
                {--domain= : The domain for tenant. 'all' or null value for all tenants.}";
    
    /**
     * Execute the console command.
     *
     * @return void
     */
    public function fire()
    {
        if (! $this->confirmToProceed()) {
            return;
        }

        if ($this->input->getOption('tenant')) {

            $domain = $this->input->getOption('domain') ?: 'all';

            $manager = new DatabaseManager();
            DB::setDefaultConnection($manager->systemConnectionName);
            
            if ($domain == 'all') $tenants = Tenant::all();
            else $tenants = Tenant::where('domain', $domain)->get();

            $drawBar = (count($tenants) > 1);

            if ($drawBar) $bar = $this->output->createProgressBar(count($tenants));

            $paths = [];
            foreach ($this->getMigrationPaths() as $path) {
                $paths[] = $path.DIRECTORY_SEPARATOR.'tenant';
            }

            foreach ($tenants as $tenant) {
                
                $manager->setConnection($tenant);
                $this->migrator->setConnection($manager->tenantConnectionName);

                $this->info('');
                $this->info("Migrating for '{$tenant->name}'...");

                if (! $this->migrator->repositoryExists()) {
                    $this->call('migrate:install', ['--tenant' => TRUE, '--domain' => $tenant->domain]);
                    DB::setDefaultConnection($manager->tenantConnectionName);
                }

                // Next, we will check to see if a path option has been defined. If it has
                // we will use the path relative to the root of this installation folder
                // so that migrations may be run for any path within the applications.
                $this->migrator->run($paths, [
                    'pretend' => $this->option('pretend'),
                    'step' => $this->option('step'),
                ]);
{'fraction_non_alphanumeric': 0.13056277056277057, 'fraction_numerical': 0.0003463203463203463, 'mean_word_length': 1.877927254608869, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 62, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6705767', 'n_tokens_mistral': 1532, 'n_tokens_neox': 1514, 'n_words': 437}