Exemplo n.º 1
0
 /**
  * Execute the console command.
  *
  * @return void
  */
 public function fire()
 {
     $this->migrator->setConnection($this->input->getOption('database'));
     $pretend = $this->input->getOption('pretend');
     while ($this->migrator->rollback($this->output, $pretend)) {
     }
 }
 /**
  * Prepare the migration database for running.
  *
  * @return void
  */
 protected function prepareDatabase()
 {
     $this->migrator->setConnection($this->input->getOption('database'));
     if (!$this->migrator->repositoryExists()) {
         $options = ['--database' => $this->input->getOption('database')];
         $this->call('migrate:install', $options);
     }
 }
Exemplo n.º 3
0
 /**
  * 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);
 }
Exemplo n.º 4
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()
 {
     $this->migrator->setConnection($this->input->getOption('database'));
     $pretend = $this->input->getOption('pretend');
     $this->migrator->rollback($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);
     }
 }
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function fire()
 {
     if (!$this->confirmToProceed()) {
         return;
     }
     $this->migrator->setConnection($this->option('database'));
     $paths = $this->getMigrationPaths();
     $this->migrator->rollback($paths, ['pretend' => $this->option('pretend'), 'step' => (int) $this->option('step')]);
     foreach ($this->migrator->getNotes() as $note) {
         $this->output->writeln($note);
     }
 }
 /**
  * Execute the console command.
  *
  * @return void
  */
 public function fire()
 {
     if (!$this->confirmToProceed()) {
         return;
     }
     $this->migrator->setConnection($this->option('database'));
     $this->migrator->rollback($this->getMigrationPaths(), ['pretend' => $this->option('pretend'), 'step' => (int) $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);
     }
 }
Exemplo n.º 8
0
 public function resolve($file)
 {
     /* @var $class \Consolet\Migrator\Migration */
     $class = parent::resolve($file);
     $class::setSchemaOnce($this->resolveConnection(null)->getSchemaBuilder());
     return $class;
 }
Exemplo n.º 9
0
 /**
  * Returns a new TenantMigrator instance.
  * 
  * @param MigrationRepositoryInterface $repository
  * @param Resolver                     $resolver
  * @param Filesystem                   $files
  * @param TenantManager                $manager
  */
 public function __construct(MigrationRepositoryInterface $repository, Resolver $resolver, Filesystem $files, TenantManager $manager)
 {
     $this->manager = $manager;
     // There is nothing special about the TenantMigrationResolver class, so let's just new up one.
     $this->tenantMigrationResolver = new TenantMigrationResolver();
     parent::__construct($repository, $resolver, $files);
 }
Exemplo n.º 10
0
 /**
  * Run "down" a migration instance. (Overridden)
  *
  * @param  object $migration
  * @param  bool   $pretend
  * @return void
  */
 protected function runDown($migration, $pretend)
 {
     $migrations = [$migration->migration];
     // Retrieve migration path and throw exception if it doesn't exist
     $path = $this->getMigrationPath(true);
     $this->requireFiles($path, $migrations);
     parent::runDown($migration, $pretend);
 }
Exemplo n.º 11
0
 /**
  * Prepare the migration database for running.
  */
 private function prepareDatabase()
 {
     if ($database = $this->getStringOption('database')) {
         $this->migrator->setConnection($database);
     }
     if (!$this->migrator->repositoryExists()) {
         $this->call('migrate:install', ['--database' => $database]);
     }
 }
 /**
  * Run the migration reset for the specified module.
  *
  * @param  string $slug
  * @return mixed
  */
 protected function reset($slug)
 {
     $this->migrator->setconnection($this->input->getOption('database'));
     $pretend = $this->input->getOption('pretend');
     $migrationPath = $this->getMigrationPath($slug);
     $migrations = $this->migrator->getMigrationFiles($migrationPath);
     if (count($migrations) == 0) {
         return $this->error('Nothing to rollback.');
     }
     // We need to reverse these migrations so that they are "downed" in reverse
     // to what they run on "up". It lets us backtrack through the migrations
     // and properly reverse the entire database schema operation that originally
     // ran.
     foreach ($migrations as $migration) {
         $this->info('Migration: ' . $migration);
         $this->runDown($slug, $migration, $pretend);
     }
 }
Exemplo n.º 13
0
 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();
 }
Exemplo n.º 14
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();
 }
Exemplo n.º 15
0
 /**
  * Execute the console command.
  *
  * @return void
  */
 public function fire()
 {
     if (!$this->confirmToProceed()) {
         return;
     }
     $this->migrator->setConnection($this->input->getOption('database'));
     if (!$this->migrator->repositoryExists()) {
         $this->output->writeln('<comment>Migration table not found.</comment>');
         return;
     }
     $pretend = $this->input->getOption('pretend');
     $this->migrator->reset($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);
     }
 }
Exemplo n.º 16
0
 /**
  * Execute the console command.
  *
  * @return void
  */
 public function fire()
 {
     if (!$this->confirmToProceed()) {
         return;
     }
     $this->migrator->setConnection($this->option('database'));
     // First, we'll make sure that the migration table actually exists before we
     // start trying to rollback and re-run all of the migrations. If it's not
     // present we will just bail out with a info message for the developer.
     if (!$this->migrator->repositoryExists()) {
         return $this->comment('Migration table not found.');
     }
     $this->migrator->reset($this->getMigrationPaths(), $this->option('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);
     }
 }
Exemplo n.º 17
0
 /**
  * @return $this
  */
 public function rollbackModules()
 {
     while (true) {
         $count = $this->migrator->rollback();
         foreach ($this->migrator->getNotes() as $note) {
             $this->output($note);
         }
         if ($count == 0) {
             break;
         }
     }
     return $this;
 }
Exemplo n.º 18
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!');
 }
Exemplo n.º 19
0
 /**
  * Execute the console command.
  *
  * @return void
  */
 public function fire()
 {
     if ($this->manager->getMigrationBehavior() == 'only') {
         foreach ($this->manager->getTenantMigrations() as $migrationName) {
             $this->info($migrationName);
         }
     } else {
         // This bit of code will get all of the migrations from the file system and load them into
         // an array. After the migration files are in the array, we will get the actual class name
         // from the migration file.
         $path = $this->getMigrationPath();
         $files = $this->migrator->getMigrationFiles($path);
         $migrations = array();
         foreach ($files as $file) {
             $migrations[] = $this->tenantMigrationResolver->resolveMigrationName($file);
         }
         $migrations = array_diff($migrations, $this->manager->getTenantMigrations());
         foreach ($migrations as $migrationName) {
             $this->info($migrationName);
         }
     }
 }
 /**
  * Run the migration reset for the specified module.
  *
  * Migrations should be reset in the reverse order that they were
  * migrated up as. This ensures the database is properly reversed
  * without conflict.
  *
  * @param  string $slug
  * @return mixed
  */
 protected function reset($slug)
 {
     $this->migrator->setconnection($this->input->getOption('database'));
     $pretend = $this->input->getOption('pretend');
     $migrationPath = $this->getMigrationPath($slug);
     $migrations = array_reverse($this->migrator->getMigrationFiles($migrationPath));
     if (count($migrations) == 0) {
         return $this->error('Nothing to rollback.');
     }
     foreach ($migrations as $migration) {
         $this->info('Migration: ' . $migration);
         $this->runDown($slug, $migration, $pretend);
     }
 }
 /**
  * Get all of the migration paths.
  *
  * @return array
  */
 protected function getMigrationPaths()
 {
     // Here, 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 ($this->input->hasOption('path') && $this->option('path')) {
         return [$this->laravel->basePath() . '/' . $this->option('path')];
     }
     $modules = config('module');
     foreach ($modules as $modulePath) {
         $migrationFilePath = $modulePath . DIRECTORY_SEPARATOR . 'database' . DIRECTORY_SEPARATOR . 'migrations';
         $this->migrator->path($migrationFilePath);
     }
     return $this->migrator->paths();
 }
Exemplo n.º 22
0
 /**
  * Run the migration reset for the specified module.
  *
  * Migrations should be reset in the reverse order that they were
  * migrated up as. This ensures the database is properly reversed
  * without conflict.
  *
  * @param  string  $slug
  */
 protected function reset($slug)
 {
     if ($this->getStringOption('database')) {
         $this->migrator->setconnection($this->getStringOption('database'));
     }
     $pretend = $this->getBooleanOption('pretend');
     $migrationPath = $this->getMigrationPath($slug);
     $migrations = array_reverse($this->migrator->getMigrationFiles($migrationPath));
     if (count($migrations)) {
         foreach ($migrations as $migration) {
             $this->info('Migration: ' . $migration);
             $this->runDown($slug, $migration, $pretend);
         }
     } else {
         $this->error('Nothing to rollback.');
     }
 }
Exemplo n.º 23
0
 /**
  * Create a new migrator instance.
  *
  * @param \Jlapp\SmartSeeder\SmartSeederRepository         $repository
  * @param \Illuminate\Database\ConnectionResolverInterface $resolver
  * @param \Illuminate\Filesystem\Filesystem                $files
  */
 public function __construct(SmartSeederRepository $repository, Resolver $resolver, Filesystem $files)
 {
     parent::__construct($repository, $resolver, $files);
 }
Exemplo n.º 24
0
 /**
  * Merge migrator operation notes.
  *
  * @param  \Illuminate\Database\Migrations\Migrator  $migrator
  *
  * @return void
  */
 protected function mergeMigratorNotes(BaseMigrator $migrator)
 {
     $this->notes = array_merge($this->notes, $migrator->getNotes());
 }
Exemplo n.º 25
0
 /**
  * Get all of the migration files.
  *
  * @return array
  */
 protected function getAllMigrationFiles()
 {
     return $this->migrator->getMigrationFiles($this->getMigrationPath());
 }
Exemplo n.º 26
0
 /**
  * Construct an instance of a NamespacedMigrator.
  *
  * @param MigrationRepositoryInterface $repository
  * @param Resolver $resolver
  * @param Filesystem $files
  * @param string $namespace
  */
 public function __construct(MigrationRepositoryInterface $repository, Resolver $resolver, Filesystem $files, $namespace = '')
 {
     parent::__construct($repository, $resolver, $files);
     $this->namespace = $namespace;
 }
Exemplo n.º 27
0
 /**
  * Migrator constructor.
  *
  * @param \Illuminate\Container\Container                              $container
  * @param \Illuminate\Database\Migrations\MigrationRepositoryInterface $repository
  * @param \Illuminate\Database\ConnectionResolverInterface             $resolver
  * @param \Illuminate\Filesystem\Filesystem                            $files
  */
 public function __construct(Container $container, MigrationRepositoryInterface $repository, Resolver $resolver, Filesystem $files)
 {
     $this->container = $container;
     parent::__construct($repository, $resolver, $files);
 }
Exemplo n.º 28
0
 /**
  * Get all of the migration files.
  *
  * @return array
  */
 protected function getAllMigrationFiles()
 {
     return $this->migrator->getMigrationFiles($this->laravel['path.database'] . '/migrations');
 }
Exemplo n.º 29
0
 /**
  * Get all of the migration files.
  *
  * @param  string  $path
  * @return array
  */
 protected function getAllMigrationFiles($path)
 {
     return $this->migrator->getMigrationFiles($path);
 }
Exemplo n.º 30
0
 /**
  * Resolve a migration instance from a file.
  *
  * @param  string $file
  *
  * @return Migration
  */
 public function resolve($file)
 {
     $this->requireOnce($file);
     if (!str_is('*.*.*', $file)) {
         return parent::resolve($file);
     }
     return app($this->dispatch(new TransformMigrationNameToClass($this->removeDatePrefix($file))));
 }