Create migration repository if it's not available.

@return void
559294
protected function createMigrationRepository(): void
    {
        $repository = $this->migrator->getRepository();

        if (! $repository->repositoryExists()) {
            $repository->createRepository();
        }
    }
485802
void migrate() throws RepositoryException
   {
      try
      {
         LOG.info("Migration started.");

         moveOldStructure();
         service.createStructure();

         //Migration order is important due to removal of nodes.
         migrateGroups();
         migrateMembershipTypes();
         migrateUsers();
         migrateProfiles();
         migrateMemberships();

         removeOldStructure();

         LOG.info("Migration completed.");
      }
      catch (Exception e)//NOSONAR
      {
         throw new RepositoryException("Migration failed", e);
      }
   }
1125641
protected function createMigrationHistoryTable()
    {
        $tableName = $this->db->schema->getRawTableName($this->migrationTable);

        $this->db->createCommand()->createTable($this->migrationTable, [
            'version' => 'varchar(180) NOT NULL PRIMARY KEY',
            'apply_time' => 'integer',
        ])->execute();
        $this->db->createCommand()->insert($this->migrationTable, [
            'version' => self::BASE_MIGRATION,
            'apply_time' => time(),
        ])->execute();
    }
60803
def create_repository(self):
        
        schema = self.get_connection().get_schema_builder()

        with schema.create(self._table) as table:
            # The migrations table is responsible for keeping track of which of the
            # migrations have actually run for the application. We'll create the
            # table to hold the migration file's path as well as the batch ID.
            table.string("migration")
            table.integer("batch")
1335057
public function migrateUp()
    {
        $this->builder->create(
            $this->table,
            function ($table) {
                $table->bigIncrements('id');

                $table->string('sha1', 40)->index();
                $table->text('statement');
                $table->double('time')->index();
                $table->integer('connection_id')->unsigned();

                $table->timestamps();
                $table->index('created_at');
                $table->index('updated_at');
            }
        );
    }
106350
private function executeMigrations()
    {
        if ($this->migrator->needsToRun()) {
            $latestVersion = $this->migrator->migrate();
            $this->logger->info('Migrate all migrations up to version ' . $latestVersion . '.');
        }
    }
923745
protected function registerMakeCommand()
	{
		$this->app->bindShared('migration.creator', function($app)
		{
			return new MigrationCreator($app['files']);
		});

		$this->app->bindShared('command.migrate.make', function($app)
		{
			// Once we have the migration creator registered, we will create the command
			// and inject the creator. The creator is responsible for the actual file
			// creation of the migrations, and may be extended by these developers.
			$creator = $app['migration.creator'];

			$packagePath = $app['path.base'].'/vendor';

			return new MigrateMakeCommand($creator, $packagePath);
		});
	}
1195366
public function createMigration()
    {
        $migration = $this->laravel->path . '/database/migrations/' . date('Y_m_d_His') . '_drawbridge_migrations_tables.php';
        $view = $this->laravel->make('view')->make('drawbridge::migration')->render();

        if (! file_exists($migration))
        {
            $fs = fopen($migration, 'x');
            if ($fs)
            {
                fwrite($fs, $view);
                fclose($fs);
                return true;
            }
        }

        return false;
    }
1127076
protected function finalizeSetup()
    {
        // Run migrations if possible
        $attemptMigrate = false;

        if ($this->connection === 'sqlite') {
            $attemptMigrate = $this->createSqliteDatabase();
        } else {
            $attemptMigrate = $this->canConnectToDb();
        }

        sleep(1);

        if ($attemptMigrate) {
            // We need to reconnect using new settings if we're running SQLite
            if ($this->connection === 'sqlite') {
                app()['db']->reconnect();
            }

            $this->call('migrate', ['--force' => true]);

            // Mark as installer complete
            Storage::put('installer', '2');

            sleep(1);

            // Create the first user's account if we need to
            if (User::count() < 1) {
                $this->info("Now let's create your user account...");
                $this->call('network:user', ['--name' => $this->user_name]);
            }
        }

        // Make the symlinks we need
        $this->createSymlinks();

        sleep(1);

        if (! $this->hasError) {
            $this->alert("Great news, {$this->user_name}: your Network is set up! I hope you enjoy using Network.");
        } else {
            $this->warn("Sorry, {$this->user_name}, I couldn't complete your Network setup this time.");
            $this->warn("Please check the warning messages to see what you need to do and rerun `php artisan network:config`.");
        }
    }
631252
protected function doExecute()
    {
        if ($this->console->getMode() !== 'dev') {
            throw new \RuntimeException(
                '<error>STOP!</error> please run <info>' . $this->getEnvCmd() . '</info>.'
            );
        }

        $repository = $this->getRepository();

        if (!$this->getOption('no-backup')) {
            // backup
            $this->backup();
        }

        $repository['path'] = $this->console->get('migration.dir');

        try {
            $repository->migrate($this->getArgument(0, null));

            if ($this->getOption('seed') && (string) $this->getArgument(0) !== '0') {
                $io = clone $this->io;

                $io->setArguments(['seed', 'import']);
                $io->setOption('no-backup', true);

                $this->console->getRootCommand()->setIO($io)->execute();
            }
        } catch (\Exception $e) {
            $prompter = new BooleanPrompter();

            $this->out()->out('<error>An error occurred: ' . $e->getMessage() . '</error>');

            if ($prompter->ask('Do you want to restore to last backup? [Y/n] (Y): ', true)) {
                $this->getBackupRepository()->restoreLatest();
            }

            throw $e;
        }

        return true;
    }
521101
public function reloadFixtures()
    {
        if ( ! $this->useBackup) {
            $this->loadFixtures();

            return;
        }

        if ($this->hasBackup()) {
            $this->restoreBackup();

            $this->getReferenceRepository()
                 ->load($this->getBackupFile());

            return;
        }

        if ($this->migrations === null) {
            $this->dropDatabase();
            $this->createDatabase();
        }

        $this->loadFixtures();
        $this->createBackup();

        $this->getReferenceRepository()
             ->save($this->getBackupFile());
    }
764589
def create_migrations
      Dir["#{self.class.source_root}/migrations/*.rb"].sort.each do |filepath|
        name = File.basename(filepath)
        template "migrations/#{name}", "db/migrate/#{name}"
        sleep 1
      end
    end
1361062
public function installAction()
    {
        // Create database connection and load migrations
        $connection = ConnectionManager::create($_SESSION['db']);
        $this->loadMigrations();

        // Migrate the database.
        $m = new Migrator;
        $m->migrate('up');

        // Create admin account
        $admin = new User($_SESSION['admin'] + [
            'name'     => $_SESSION['admin']['username'],
            'group_id' => 1
        ]);
        $admin->save();

        // Set config file contents
        $this->set("config", $this->makeConfig());

        // Insert defaults
        $seeder = new Seeder;
        $seeder->seed();

        // Remove database and account details from the session.
        unset($_SESSION['db'], $_SESSION['admin']);

        $this->title("Complete");
        return $this->render("complete.phtml");
    }
822357
public function actionGenerate()
	{
		$tableName = Enter::display('Enter table name');
		$className = MigrationHelper::generateByTableName($tableName);
		Output::block($className, 'Migration created!');
	}
1299146
public function construct()
	{
		switch ($this->arguments->getOpt(4))
		{
			case 'for':
				$prefix = App::get('db')->getPrefix();
				$tables = App::get('db')->getTableList();

				if (!$table = $this->arguments->getOpt(5))
				{
					$this->output->error('Please specify the table for which a migration is being created');
				}
				else if (!in_array($table, $tables))
				{
					$this->output->error('Table does not exist');
				}

				$this->addReplacement('description', "creating table {$table}")
					 ->addReplacement('table_name', str_replace($prefix, '#__', $table))
					 ->addReplacement('up', '$^create.table^$')
					 ->addReplacement('down', '$^drop.table^$')
					 ->addReplacement('create_table', $this->showCreateTable($table));
				break;

			default:
				$this->addReplacement('description', '...')
					 ->addReplacement('up', '')
					 ->addReplacement('down', '');
				break;
		}

		// Determine our base path
		$base       = $this->arguments->getOpt('app') ? PATH_APP : PATH_CORE;
		$installDir = trim($this->arguments->getOpt('install-dir'));
		if ($installDir && strlen($installDir) > 0)
		{
			if (substr($installDir, 0, 1) == DS)
			{
				$base = rtrim($installDir, DS);
			}
			else
			{
				$base .= DS . trim($installDir, DS);
			}
		}

		// Install directory is migrations folder within base
		$installDir = $base . DS . 'migrations';

		// Extension
		$extension = null;
		if ($this->arguments->getOpt('e') || $this->arguments->getOpt('extension'))
		{
			$extension = ($this->arguments->getOpt('e')) ? $this->arguments->getOpt('e') : $this->arguments->getOpt('extension');

			if ($extension != 'core' && !$this->isValidExtension($extension, $base) && !$this->arguments->getOpt('i'))
			{
				$this->output->error("Error: the extension provided ({$extension}) does not appear to be valid.");
			}
		}
		else
		{
			$this->output->error("Error: an extension should be provided.");
		}

		// Editor
		$editor = null;
		if ($this->arguments->getOpt('editor'))
		{
			$editor = $this->arguments->getOpt('editor');
		}
		else
		{
			$editor = (getenv('EDITOR')) ? getenv('EDITOR') : 'vi';
		}

		// Create filename varient of extension
		$ext = '';
		if (!preg_match('/core/i', $extension))
		{
			$parts = explode('_', $extension);
			foreach ($parts as $part)
			{
				$ext .= ucfirst($part);
			}
		}
		else
		{
			$ext = 'Core';
		}

		// Craft file/classname
		$classname   = 'Migration' . with(new Date('now'))->format("YmdHis") . $ext;
		$destination = $installDir . DS . $classname . '.php';

		$this->addTemplateFile("{$this->getType()}.tmpl", $destination)
			 ->addReplacement('class_name', $classname)
			 ->make();

		// Open in editor
		system("{$editor} {$destination} > `tty`");
	}
117260
protected function ensureBaseMigrationHistory()
    {
        if ($this->baseMigrationEnsured) {
            return;
        }

        try {
            $this->db->getBucket($this->migrationBucket);
        }
        catch (Exception $e) {
            if (($e->getPrevious() instanceof \Couchbase\Exception) && ($e->getPrevious()->getCode() == 2)) {
                $this->db->createBucket($this->migrationBucket);
            }
            else {
                throw $e;
            }
        }

        $row = (new Query)->select(['version'])
            ->from($this->migrationBucket)
            ->andWhere(['version' => self::BASE_MIGRATION])
            ->limit(1)
            ->one($this->db);

        if (empty($row)) {
            $this->addMigrationHistory(self::BASE_MIGRATION);
        }

        $this->baseMigrationEnsured = true;
    }
385432
public function 
    {

        $count = $this->count();

        foreach ($this->migrations as $i => $mig) {
            if ($this->preCallback) {
                $callback = $this->preCallback;
                $callback($mig->getVersion(), $i, $count);
            }

            if ($this->direction == 'up') {
                $mig->up();
            } elseif ($this->direction == 'down') {
                $mig->down();
            }

            if ($this->postCallback) {
                $callback = $this->postCallback;
                $callback($mig->getVersion(), $i, $count);
            }
        }
    }