示例#1
0
 public function fire()
 {
     // fallback to default behaviour if we're not talking about multi tenancy
     if (!$this->option('tenant')) {
         return parent::fire();
     }
     if (!$this->confirmToProceed()) {
         return;
     }
     if ($this->option('tenant') == 'all') {
         $websites = $this->website->all();
     } else {
         $websites = $this->website->queryBuilder()->whereIn('id', explode(',', $this->option('tenant')))->get();
     }
     // forces database to tenant
     if (!$this->option('database')) {
         $this->input->setOption('database', 'tenant');
     }
     foreach ($websites as $website) {
         $this->info("Migrating for {$website->id}: {$website->present()->name}");
         $website->database->setCurrent();
         $this->prepareDatabase($website->database->name);
         // The pretend option can be used for "simulating" the migration and grabbing
         // the SQL queries that would fire if the migration were to be run against
         // a database for real, which is helpful for double checking migrations.
         $pretend = $this->input->getOption('pretend');
         // 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.
         if (!is_null($path = $this->input->getOption('path'))) {
             $path = $this->laravel->basePath() . '/' . $path;
         } else {
             $path = $this->getMigrationPath();
         }
         try {
             $this->migrator->run($path, $pretend);
         } catch (PDOException $e) {
             if (str_contains($e->getMessage(), ['Base table or view already exists'])) {
                 $this->comment("Migration failed for existing table; probably a system migration: {$e->getMessage()}");
                 continue;
             }
         }
         // Once the migrator has run we will grab the note output and send it out to
         // the console screen, since the migrator itself functions without having
         // any instances of the OutputInterface contract passed into the class.
         foreach ($this->migrator->getNotes() as $note) {
             $this->output->writeln($note);
         }
         // Finally, if the "seed" option has been given, we will re-run the database
         // seed task to re-populate the database, which is convenient when adding
         // a migration and a seed at the same time, as it is only this command.
         if ($this->input->getOption('seed')) {
             $this->call('db:seed', ['--force' => true]);
         }
     }
 }
 /**
  * Execute the console command.
  */
 public function fire()
 {
     if ($this->input->getOption('streams')) {
         return $this->dispatch(new MigrateStreams($this));
     }
     if ($this->input->getOption('all-addons')) {
         return $this->dispatch(new MigrateAllAddons($this));
     }
     $this->dispatch(new ConfigureMigrator($this, $this->input, $this->migrator));
     parent::fire();
 }
 /**
  * Execute the console command.
  *
  * @return void
  */
 public function fire()
 {
     if (!$this->input->getOption('no-addons') && !$this->input->getOption('path')) {
         $this->prepareDatabase();
         $addons = app('Anomaly\\Streams\\Platform\\Addon\\AddonCollection');
         if ($namespaces = $this->input->getOption('addon')) {
             $namespaces = explode(',', $namespaces);
             $addons = $addons->filter(function (Addon $addon) use($namespaces) {
                 return in_array($addon->getNamespace(), $namespaces) || in_array($addon->getSlug(), $namespaces);
             });
         }
         // The pretend option can be used for "simulating" the migration and grabbing
         // the SQL queries that would fire if the migration were to be run against
         // a database for real, which is helpful for double checking migrations.
         $pretend = $this->input->getOption('pretend');
         /** @var Addon $addon */
         foreach ($addons as $addon) {
             $this->migrator->setNamespace($addon->getNamespace())->run($addon->getPath('migrations'), $pretend);
             // Finally, if the "seed" option has been given, we will re-run the database
             // seed task to re-populate the database, which is convenient when adding
             // a migration and a seed at the same time, as it is only this command.
             if ($this->input->getOption('seed')) {
                 $this->call('db:seed', ['--addon' => $addon->getNamespace(), '--force' => true]);
             }
             // Once the migrator has run we will grab the note output and send it out to
             // the console screen, since the migrator itself functions without having
             // any instances of the OutputInterface contract passed into the class.
             foreach ($this->migrator->getNotes() as $note) {
                 $this->output->writeln($note);
             }
         }
     } else {
         $this->migrator->setNamespace('laravel');
         parent::fire();
     }
 }