/** * @param bool $pretend * * @return $this */ public function migrateModules($pretend = false) { $this->output('Starting process of migration...'); foreach ($this->modules as $module) { $this->migrateModule($module); } sort($this->migrations); $this->migrator->runMigrationList(array_unique($this->migrations), $pretend); foreach ($this->migrator->getNotes() as $note) { $this->output(' - ' . $note); } return $this; }
/** * 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]); } } } }
/** * Gets a filtered list of migrations and runs them * * @param array $migrations * @param bool $pretend */ public function runMigrationList($migrations, array $options = []) { $this->note("Running " . ($this->migrationType == "default" ? "default" : "custom") . " migrations for DB " . $this->connection); $migrations = array_filter($migrations, array($this, "filterMigrations")); parent::runMigrationList($migrations, $options); }