Install migrations.

@param  string|null  $database
@param  mixed|null  $id

@return void
172138
public function install(?string $database, $id = null): void
    {
        if (! \is_null($id)) {
            $this->executeFor($id, function ($entity) use ($database) {
                $this->runInstall($entity, $database);
            });

            return;
        }

        $this->executeForEach(function ($entity) use ($database) {
            $this->runInstall($entity, $database);
        });
    }
1186594
public function runUp(Model $entity, ?string $database, bool $pretend = false): void
    {
        $database = $this->asConnection($entity, $database);
        $table = $this->resolveMigrationTableName($entity);
        $migrator = $this->resolveMigratorWithNotes($table);

        $migrator->setConnection($database);
        $migrator->setEntity($entity);

        $migrator->run($this->getMigrationPaths($entity), ['pretend' => (bool) $pretend]);
        $migrator->resetConnection();
    }
987442
private function installShopData($database, $demoDataRequired = 0)
    {
        $baseSqlDir = $this->getUtilitiesInstance()->getSqlDirectory(EditionSelector::COMMUNITY);

        try {
            // If demo data files are provided.
            if ($demoDataRequired && $this->getUtilitiesInstance()->isDemodataPrepared()) {
                $this->getUtilitiesInstance()->executeExternalDatabaseMigrationCommand();

                // Install demo data.
                $database->queryFile($this->getUtilitiesInstance()->getActiveEditionDemodataPackageSqlFilePath());
                // Copy demo data files.
                $this->getUtilitiesInstance()->executeExternalDemodataAssetsInstallCommand();
            } else {
                $database->queryFile("$baseSqlDir/initial_data.sql");

                $this->getUtilitiesInstance()->executeExternalDatabaseMigrationCommand();
            }
        } catch (Exception $exception) {
            $commandException = new CommandExecutionFailedException('Migration', $exception->getCode(), $exception);
            $commandException->setCommandOutput([$exception->getMessage()]);

            $this->handleCommandExecutionFailedException($commandException);

            throw new SetupControllerExitException();
        }
    }
223944
public function initialize($id, $alias = null)
    {
        $this->id    = $id;
        $this->alias = $alias;
    }
835722
public static function install($persistence)
    {
        $migration = new \oat\ltiDeliveryProvider\scripts\dbMigrations\LtiResultAliasStorage_v1();
        $migration->apply($persistence);
    }
1360626
public function restoreDatabase(): void
    {
        $currentDirectory = getcwd();
        $installer = $this->getInstallerService();
        $this->findDirectoryToRunScripts();
        $installer->setOutput(new NullOutput());
        $installer->importSchema();
        $installer->importData();
        chdir($currentDirectory);
    }
1116491
public static function prepareMigrationTable(App $app): void{
        $migration = new class($app) extends Migration{

            /**
             * Create the migration table if it does not exist yet
             */
            public function up(): void{
                $schema = $this->getSchema('default');
                if (!$schema->hasTable('migrations')) {
                    $schema->create('migrations', function (Blueprint $table){
                        $table->increments('id');
                        $table->string('name', 255);
                    });
                }
            }

            /**
             * Is not needed, but add it nevertheless
             */
            public function down(): void{
                $this->getSchema('default')->drop('migrations');
            }
        };
        $migration->up();
    }
1242759
public function migrateUp( $levels = NULL )
    {
        if ( NULL !== $levels )
        {
            $this->levels = $levels;
        }
        
        $newMigrations = $this->getNewMigrations( );
        
        $i = 0;
        
        if ( self::MIGRATE_ALL === $this->levels || $this->levels > count( $newMigrations ) )
        {
            $this->levels = count( $newMigrations );
        }
        
        while ( $i < $this->levels )
        {
            $class = $this->migrationNamespace . '\\' . $newMigrations[ $i ];
            
            if ( !class_exists( $class ) )
            {
                if ( !array_search( 'RawPHP\\RawMigrator\\Migrations\\', $this->namespaces, TRUE ) )
                {
                    $this->namespaces[] = 'RawPHP\\RawMigrator\\Migrations\\';
                }
                
                foreach( $this->namespaces as $ns )
                {
                    $cls = $ns . $newMigrations[ $i ];
                    
                    if ( class_exists( $cls ) )
                    {
                        $class = $cls;
                        
                        break;
                    }
                }
                
                if ( NULL === $class )
                {
                    throw new MigrationException( 'Migration class: ' . $class . ' - not found' );
                }
            }
            
            $migration = new $class( );
            
            $method = new \ReflectionMethod( $class, 'migrateUp' );
            
            // run migrateUp
            if ( $class === $method->getdeclaringClass()->name )
            {
                $migration->migrateUp( $this->db );
                
                $this->_addMigrationRecord( $class );
            }
            else
            {
                $method = new \ReflectionMethod( $class, 'safeMigrateUp' );
                
                if ( $class === $method->getDeclaringClass()->name )
                {
                    try
                    {
                        $this->db->startTransaction( );
                        
                        // turn off auto commit
                        $this->db->setTransactionAutocommit( FALSE );
                        
                        // run safeMigrateUp
                        $migration->safeMigrateUp( $this->db );
                        
                        // update migrations table with the new applied migration
                        $this->_addMigrationRecord( $class );
                        
                        // commit transaction
                        $this->db->commitTransaction( );
                    }
                    catch ( Exception $e )
                    {
                        // roleback transaction
                        $this->db->rollbackTransaction( );
                        
                        throw $e;
                    }
                }
            }
            
            $i++;
            
            if ( $this->levels === $i )
            {
                $this->doAction( self::ON_MIGRATE_UP_ACTION );
                
                return;
            }
        }
    }
175929
protected function loadLaravelMigrations($database = []): void
    {
        $options = \is_array($database) ? $database : ['--database' => $database];

        $options['--path'] = 'migrations';

        $migrator = new MigrateProcessor($this, $options);

        $migrator->up();

        $this->app[ConsoleKernel::class]->setArtisan(null);

        $this->beforeApplicationDestroyed(function () use ($migrator) {
            $migrator->rollback();
        });
    }
447021
protected function runRollback($database, $path, $step, $force)
    {
        $this->call('migrate:rollback', [
            '--database' => $database,
            '--path'     => $path,
            '--step'     => $step,
            '--force'    => $force,
        ]);
    }
1118034
public function up() {
		$db = Database::get();

		$database = $db->get_one('SELECT DATABASE()');

		$indexes = ['completed', 'frozen', 'failed'];

		foreach ($indexes as $index) {
			if ($db->get_one('SELECT 1 FROM INFORMATION_SCHEMA.STATISTICS WHERE 1 AND TABLE_SCHEMA = "' . $database . '" AND TABLE_NAME="transaction" AND INDEX_NAME="' . $index . '"') === null) {
				$db->query('ALTER TABLE `transaction` ADD INDEX `' . $index . '` (`' . $index . '`)');
			}
		}
	}
191146
public function up()
    {
        $this->create('migrations', function ($table) {
            // Place table rows here
            $table->increments('id');
            $table->string('migration');
            $table->integer('migrated');
            $table->timestamps();
        });
    }
1217588
public function setDatabase(Database $database)
    {
        $this->database = $database;
        $identity = $database->identity();
        $this->cacheKey = sprintf(
            self::CACHE_KEY_TEMPLATE,
            $identity['projectId'],
            $identity['instance'],
            $identity['database']
        );

        if (!isset($this->config['lock'])) {
            $this->config['lock'] = $this->getDefaultLock();
        }
    }
125842
protected function migrate()
    {
        if (! $this->container['migrator']->repositoryExists()) {
            throw new Exception('Migration table not found.');
        }

        $this->container['migrator']->run($this->getAttribute('path').'/database/migrations');
    }
1024895
public function migrate($environment, $version = NULL)
	{
		foreach ($this->migrationConfigurations as $migrationConfiguration) {
			$this->getPhinxManager()->setConfig($migrationConfiguration);
			$this->getPhinxManager()->migrate($environment, $version);
		}
	}
783739
public function deleteRow ($id)
		{
			$this->database->createQuery()
				->delete()
				->from($this->table)
				->where(
					$this->database->createCondition()
						->equal($this->getPrimaryKey(), $id)
				)
				->execute();
		}
835863
public function initialize($alias, Database $database)
    {
        $this['raikiri'] = $this->raikiri();

        $this['paths'] = [
            'migrations' => $this->loader->findFirst($this->application->config('directory.database.migration')) . DS . $alias
        ];
        $this['environments'] = [
            'default_database' => 'development',
            'default_migration_table' => 'samurai_migration_log',
        ];

        $environment = $this->application->getEnv();
        $this['environments'] = [
            $environment => [
                'raikiri' => $this->raikiri(),
                'alias' => $alias,
                'adapter' => $this->toPhinxAdapterName($database->getDriver()),
                'host' => $database->getHostName(),
                'user' => $database->getUser(),
                'pass' => $database->getPassword(),
                'port' => $database->getPort(),
                'charset' => $database->getCharset(),
                'name' => $database->getDatabaseName(),
                'memory' => $this->toPhinxSqliteMemory($database->getDriver(), $database->getDatabaseName()),
            ]
        ];
    }