/**
  * 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]);
             }
         }
     }
 }
 /**
  * Execute the console command.
  *
  */
 public function fire()
 {
     if (!$this->confirmToProceed()) {
         return;
     }
     $this->prepareDatabase();
     // 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');
     $path = $this->getMigrationPath();
     $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) {
         $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.
  *
  * @return void
  */
 public function fire()
 {
     if (!$this->confirmToProceed()) {
         return;
     }
     $this->prepareDatabase();
     // 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();
     }
     $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) {
         $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]);
     }
 }
Example #4
0
 /**
  * Execute the console command.
  *
  * @return void
  */
 public function fire()
 {
     if (!$this->confirmToProceed()) {
         return;
     }
     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->prepareDatabase();
     // 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');
     // diff from original
     $path = $this->laravel->basePath() . '/' . $path;
     $this->migrator->run($path, ['pretend' => $pretend, 'step' => $this->input->getOption('step')]);
     // 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]);
     }
 }
 /**
  * Run migrations for the specified module.
  *
  * @param  string $slug
  * @return mixed
  */
 protected function migrate($slug)
 {
     $moduleName = Str::studly($slug);
     if ($this->module->exists($slug)) {
         $pretend = $this->option('pretend');
         $path = $this->getMigrationPath($slug);
         $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->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->option('seed')) {
             $this->call('module:seed', ['module' => $slug, '--force' => true]);
         }
     } else {
         return $this->error("Module [{$moduleName}] does not exist.");
     }
 }
 /**
  * Run migrations on a single module
  *
  * @param ModuleContainer $module
  * @return $this
  */
 public function migrateModule(ModuleContainer $module)
 {
     $this->_migrator->run($module->getPath(['database', 'migrations']));
     $this->output($module->getName());
     foreach ($this->_migrator->getNotes() as $note) {
         $this->output(' - ' . $note);
     }
     return $this;
 }
 /**
  * Execute the console command.
  *
  * @return void
  */
 public function fire()
 {
     $this->migrator->setConnection($this->input->getOption('database'));
     $package = $this->input->getOption('package') ?: 'application';
     // 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');
     $path = $this->getMigrationPath();
     $this->migrator->run($this->output, $package, $path, $pretend);
 }
Example #8
0
 /**
  * Run migrations for the specified module.
  *
  * @param string $slug
  *
  * @return mixed
  */
 protected function migrate($slug)
 {
     if ($this->module->exists($slug)) {
         $module = $this->module->where('slug', $slug);
         $pretend = Arr::get($this->option(), 'pretend', false);
         $path = $this->getMigrationPath($slug);
         if (floatval(App::version()) > 5.1) {
             $pretend = ['pretend' => $pretend];
         }
         $this->migrator->run($path, $pretend);
         event($slug . '.module.migrated', [$module, $this->option()]);
         // 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 {
         return $this->error('Module does not exist.');
     }
 }
 /**
  * Execute the console command.
  *
  * @return void
  */
 public function fire()
 {
     $this->prepareDatabase();
     // 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');
     $path = $this->getMigrationPath();
     $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) {
         $this->output->writeln($note);
     }
 }
 public function run($path, $pretend = false)
 {
     parent::run($path, $pretend);
     $key = Config::get('database.default');
     $database = Config::get('database.connections.' . $key . '.database');
     $this->note('<info>Generating schema for: ' . $database . '</info>');
     $builder = new Builder();
     $builder->convert($database);
     $builder->write();
 }
Example #11
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $capsule = app('capsule');
     $connectionResolver = $capsule->getDatabaseManager();
     $repository = new DatabaseMigrationRepository($connectionResolver, 'migrations');
     if (!$repository->repositoryExists()) {
         $repository->createRepository();
     }
     $migrator = new Migrator($repository, $connectionResolver, new Filesystem());
     return $migrator->run(__DIR__ . '/../database/migrations');
 }
 /**
  * Execute the console command.
  *
  * @return void
  */
 public function fire()
 {
     if (!$this->confirmToProceed()) {
         return;
     }
     $this->prepareDatabase();
     // 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($this->getMigrationPaths(), ['pretend' => $this->option('pretend'), 'step' => $this->option('step')]);
     // 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->option('seed')) {
         $this->call('db:seed', ['--force' => true]);
     }
 }
Example #13
0
 public static function setUpBeforeClass()
 {
     parent::setUpBeforeClass();
     $config = (require __DIR__ . '/../config.php');
     $capsule = new Manager();
     $capsule->addConnection($config);
     $capsule->bootEloquent();
     Schema::setConnection($capsule->getConnection('default'));
     DB::setConnection($capsule->getConnection('default'));
     // run the migrations
     $migration_repo = new DatabaseMigrationRepository(Model::getConnectionResolver(), 'migrations');
     if (!$migration_repo->repositoryExists()) {
         $migration_repo->createRepository();
     }
     $migrator = new Migrator($migration_repo, Model::getConnectionResolver(), new Filesystem());
     $migrator->rollback();
     $migrator->run(__DIR__ . '/../../src/migrations');
     static::loadFixtures();
 }
Example #14
0
 public function execute(InputInterface $input, OutputInterface $output)
 {
     $migrationsPath = APP_ROOT . 'db/migrations/';
     $c = $this->app->container();
     $migrationsTableName = 'migrations';
     $dbResolver = $c['database.manager']->getDatabaseManager();
     $filesystem = new Filesystem();
     // Get the database migrations repository (create if not existant)
     $repository = new MigrationRepo($dbResolver, $migrationsTableName);
     if (!$repository->repositoryExists()) {
         $repository->createRepository();
     }
     // Run!
     $migrator = new Migrator($repository, $dbResolver, $filesystem);
     $migrator->run($migrationsPath);
     // Show notes
     foreach ($migrator->getNotes() as $note) {
         $output->writeln(preg_replace('(<[a-zA-Z/]+>)', '', $note));
     }
     $output->writeln('');
     $output->writeln('Migrated!');
 }
 /**
  * Run the outstanding migrations at a given path.
  *
  * @param  string  $path
  * @param  bool    $pretend
  * @return void
  */
 public function run($path, $pretend = false)
 {
     $this->path = $path;
     parent::run($path, $pretend);
 }
Example #16
0
 public function run($path, $pretend = false, $output = null)
 {
     $this->consoleOutput = $output;
     parent::run($path, $pretend);
 }
Example #17
0
 /**
  * Migrate the extension with an optional customized path.
  *
  * @param  string  $path
  * @return void
  */
 protected function migrate($path = null)
 {
     if (!isset(static::$migrator)) {
         return;
     }
     $path = $path ?: $this->getMigrationsPath();
     static::$migrator->run($path);
 }