예제 #1
0
 /**
  * Run migrations on a single module
  *
  * @param ModuleContainerInterface $module
  *
  * @return $this
  */
 public function migrateModule(ModuleContainerInterface $module)
 {
     $path = $module->getPath(['database', 'migrations']);
     $files = $this->migrator->getMigrationFiles($path);
     // Once we grab all of the migration files for the path, we will compare them
     // against the migrations that have already been run for this package then
     // run each of the outstanding migrations against a database connection.
     $ran = $this->migrator->getRepository()->getRan();
     $migrations = array_diff($files, $ran);
     $this->migrator->requireFiles($path, $migrations);
     foreach ($migrations as $migration) {
         $this->migrations[] = $migration;
     }
     return $this;
 }
 /**
  * Execute the console command.
  *
  * @return void
  */
 public function fire()
 {
     if (!$this->migrator->repositoryExists()) {
         return $this->error('No migrations found.');
     }
     $ran = $this->migrator->getRepository()->getRan();
     $migrations = [];
     foreach ($this->getAllMigrationFiles() as $migration) {
         $migrations[] = in_array($migration, $ran) ? ['<info>Y</info>', $migration] : ['<fg=red>N</fg=red>', $migration];
     }
     if (count($migrations) > 0) {
         $this->table(['Ran?', 'Migration'], $migrations);
     } else {
         $this->error('No migrations found');
     }
 }
예제 #3
0
 /**
  * Execute the console command.
  *
  * @return void
  */
 public function fire()
 {
     $this->migrator->setConnection($this->option('database'));
     if (!$this->migrator->repositoryExists()) {
         return $this->error('No migrations found.');
     }
     $ran = $this->migrator->getRepository()->getRan();
     $migrations = Collection::make($this->getAllMigrationFiles())->map(function ($migration) use($ran) {
         return in_array($this->migrator->getMigrationName($migration), $ran) ? ['<info>Y</info>', $this->migrator->getMigrationName($migration)] : ['<fg=red>N</fg=red>', $this->migrator->getMigrationName($migration)];
     });
     if (count($migrations) > 0) {
         $this->table(['Ran?', 'Migration'], $migrations);
     } else {
         $this->error('No migrations found');
     }
 }
 /**
  * Run migrations for the specified module.
  *
  * @param string $slug
  *
  * @return mixed
  */
 protected function migrate($slug = null)
 {
     $pretend = Arr::get($this->option(), 'pretend', false);
     if (!is_null($slug) && $this->module->exists($slug)) {
         $path = $this->getMigrationPath($slug);
         if (floatval(App::version()) > 5.1) {
             $pretend = ['pretend' => $pretend];
         }
         $this->migrator->run($path, $pretend);
         // 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) {
             if (!$this->option('quiet')) {
                 $this->line($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->option('seed')) {
             $this->call('module:seed', ['module' => $slug, '--force' => true]);
         }
     } else {
         $modules = $this->module->all();
         if (count($modules) == 0) {
             return $this->error("Your application doesn't have any modules.");
         }
         $migrationsAll = [];
         foreach ($modules as $module) {
             $path = $this->getMigrationPath($module['slug']);
             $files = $this->migrator->getMigrationFiles($path);
             $ran = $this->migrator->getRepository()->getRan();
             $migrations = array_diff($files, $ran);
             $this->migrator->requireFiles($path, $migrations);
             $migrationsAll = array_merge($migrationsAll, $migrations);
         }
         if (floatval(App::version()) > 5.1) {
             $pretend = ['pretend' => $pretend];
         }
         sort($migrationsAll);
         $this->migrator->runMigrationList($migrationsAll, $pretend);
         // 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) {
             if (!$this->option('quiet')) {
                 $this->line($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->option('seed')) {
             foreach ($modules as $module) {
                 $this->call('module:seed', ['module' => $module['slug'], '--force' => true]);
             }
         }
     }
 }
예제 #5
0
 /**
  * Execute the console command.
  *
  * @return void
  */
 public function fire()
 {
     if (!$this->migrator->repositoryExists()) {
         return $this->error('No migrations found.');
     }
     if (is_null($path = $this->input->getOption('path'))) {
         $path = $this->ask('Please enter the full path of the migration file, without file extension, in the following format: path/migration-file');
     }
     $this->migrator->setConnection($this->input->getOption('database'));
     $path = $this->laravel->basePath() . '/' . $path;
     $ran = $this->migrator->getRepository()->getRan();
     $migrations = [];
     foreach ($this->getAllMigrationFiles($path) as $migration) {
         $migrations[] = in_array($migration, $ran) ? ['<info>Y</info>', $migration] : ['<fg=red>N</fg=red>', $migration];
     }
     if (count($migrations) > 0) {
         $this->table(['Ran?', 'Migration'], $migrations);
     } else {
         $this->error('No migrations found');
     }
 }
예제 #6
0
 /**
  * Execute the console command.
  *
  * @return void
  */
 public function fire()
 {
     if (!$this->migrator->repositoryExists()) {
         return $this->error('No migrations found.');
     }
     $this->migrator->setConnection($this->input->getOption('database'));
     if (!is_null($path = $this->input->getOption('path'))) {
         $path = $this->laravel->basePath() . '/' . $path;
     } else {
         $path = $this->getMigrationPath();
     }
     $ran = $this->migrator->getRepository()->getRan();
     $migrations = [];
     foreach ($this->getAllMigrationFiles($path) as $migration) {
         $migrations[] = in_array($migration, $ran) ? ['<info>Y</info>', $migration] : ['<fg=red>N</fg=red>', $migration];
     }
     if (count($migrations) > 0) {
         $this->table(['Ran?', 'Migration'], $migrations);
     } else {
         $this->error('No migrations found');
     }
 }
예제 #7
0
 /**
  * Reset the migrations for the extension with an
  * optional customized path.
  *
  * @param  string  $path
  * @return void
  */
 protected function resetMigrations($path = null)
 {
     if (!isset(static::$migrator)) {
         return;
     }
     $path = $path ?: $this->getMigrationsPath();
     $files = static::$migrator->getMigrationFiles($path);
     $repository = static::$migrator->getRepository();
     // Get an array of migration names which will be
     // reset
     $migrations = array_intersect(array_reverse($repository->getRan()), $files);
     // Loop through the migrations we have to rollback
     foreach ($migrations as $migration) {
         // Let the migrator resolve the migration instance
         $instance = static::$migrator->resolve($migration);
         // And we'll call the down method on the migration
         $instance->down();
         // Now we need to manipulate what the migrator does to
         // delete a migration.
         $migrationClass = new \StdClass();
         $migrationClass->migration = $migration;
         $repository->delete($migrationClass);
     }
 }