@param array $migrationsToRun

@return bool
@throws \CDbException
484149
public function runMigrations($migrationNames = [])
    {
        // This might take a while
        App::maxPowerCaptain();

        if (empty($migrationNames)) {
            $migrationNames = $this->getNewMigrations();
        }

        $total = count($migrationNames);
        $n = count($migrationNames);

        if ($n === $total) {
            $logMessage = "Total $n new ".($n === 1 ? 'migration' : 'migrations').' to be applied:';
        } else {
            $logMessage = "Total $n out of $total new ".($total === 1 ? 'migration' : 'migrations').' to be applied:';
        }

        foreach ($migrationNames as $migrationName) {
            $logMessage .= "\n\t$migrationName";
        }

        foreach ($migrationNames as $migrationName) {
             try {
                $migrator = Craft::$app->getContentMigrator();
                $migrator->migrateUp($migrationName);
            } catch (MigrationException $e) {
                Craft::error('Migration failed. The rest of the migrations are cancelled.', __METHOD__);
                //throw $e;
                return false;
            }
        }

        return true;
    }
721609
public function unmigrate($migrationName) {
		$this->createTable();
		$this->db->dal()->from('_migrations')->where('name', $migrationName)->delete();
	}
1217319
protected function markMigration($migrationName, $fileName)
    {
        $this->getOutput()->writeln('Mark migration');

        /* @var Adapter\AdapterInterface $adapter */
        $adapter = $this->settings['adapter'];

        /* @var $manager Manager */
        $manager = $this->settings['manager'];

        $envName = $this->settings['environment'];

        /* @var $env Environment */
        $env = $manager->getEnvironment($envName);
        $schemaTableName = $env->getSchemaTableName();

        /* @var $pdo \PDO */
        $pdo = $this->settings['adapter'];

        // Get version from filename prefix
        $version = explode('_', $fileName)[0];

        // Record it in the database
        $time = time();
        $startTime = date('Y-m-d H:i:s', $time);
        $endTime = date('Y-m-d H:i:s', $time);
        $breakpoint = 0;

        $sql = sprintf(
            "INSERT INTO %s (%s, %s, %s, %s, %s) VALUES ('%s', '%s', '%s', '%s', %s);",
            $schemaTableName,
            $adapter->quoteColumnName('version'),
            $adapter->quoteColumnName('migration_name'),
            $adapter->quoteColumnName('start_time'),
            $adapter->quoteColumnName('end_time'),
            $adapter->quoteColumnName('breakpoint'),
            $version,
            substr($migrationName, 0, 100),
            $startTime,
            $endTime,
            $breakpoint
        );

        $pdo->query($sql);
    }
444473
public static function isMigrationFileExists($className)
    {
        $fileTail = snake_case($className) . '.php';
        $files = glob(database_path('migrations/*'));
        foreach ($files as $file) {
            if ($fileTail === substr(basename($file), 18)) {
                return $file;
            }
        }
        return false;
    }
1188535
public function check(array $config): bool
    {
        try {
            Artisan::call('migrate', ['--pretend' => 'true', '--force' => 'true']);
            $output = Artisan::output();
            return strstr($output, 'Nothing to migrate.');
        } catch (\PDOException $e) {
            $this->databaseError = $e->getMessage();
        }
        return false;
    }
1226887
protected function recordMigration(AbstractMigration $migration)
    {
        $query = 'INSERT INTO `app_migrations` (`timestamp`, `description`) VALUES ("%s", "%s")';
        $query = sprintf($query, $migration->getTimestamp(), $migration->getDescription());

        $this->db->query($query, DbAdapter::QUERY_MODE_EXECUTE);
    }
1181659
protected function runMigration($migration, $method)
    {
        $connection = $this->resolveConnection(
            $migration->getConnection()
        );

        $callback = function () use ($migration, $method) {
            if (method_exists($migration, $method)) {
                $migration->{$method}();
            }
        };

        $this->getSchemaGrammar($connection)->supportsSchemaTransactions()
            && $migration->withinTransaction
                    ? $connection->transaction($callback)
                    : $callback();
    }
1045038
protected function mark($versionName, $all = false)
    {
        if (!$this->configuration->hasVersion($versionName)) {
            throw MigrationException::unknownMigrationVersion($versionName);
        }

        $version = $this->configuration->getVersion($versionName);

        if ($this->markMigrated && $this->configuration->hasVersionMigrated($version)) {
            $marked = true;
            if (!$all) {
                throw new InvalidArgumentException(sprintf('The version "%s" already exists in the version table.',
                    $version));
            }
        }

        if (!$this->markMigrated && !$this->configuration->hasVersionMigrated($version)) {
            $marked = false;
            if (!$all) {
                throw new InvalidArgumentException(sprintf('The version "%s" does not exists in the version table.',
                    $version));
            }
        }

        if (!isset($marked)) {
            $filename = $this->configuration->getNamingStrategy()->getFilename($versionName);
            if ($this->markMigrated) {
                $version->markMigrated();
                $this->info('<info>Added version to table:</info> ' . $filename);
            } else {
                $version->markNotMigrated();
                $this->info('<info>Removed version from table:</info> ' . $filename);
            }
        }
    }
1088709
public function deleteMigration(APIMigration $migration)
    {
        $this->createTableIfNeeded();
        $conn = $this->getConnection();
        $conn->delete($this->tableName, array('migration' => $migration->name));
    }
889012
public function moveToBottom(ConnectionInterface $con = null)
    {
        if ($this->isLast($con)) {
            return false;
        }
        if (null === $con) {
            $con = Propel::getServiceContainer()->getWriteConnection(CustomerGroupTableMap::DATABASE_NAME);
        }
        $con->beginTransaction();
        try {
            $bottom = ChildCustomerGroupQuery::create()->getMaxRankArray($con);
            $res = $this->moveToRank($bottom, $con);
            $con->commit();

            return $res;
        } catch (Exception $e) {
            $con->rollback();
            throw $e;
        }
    }
701535
public function migrationHasSoftDelete()
    {
        $hasSoftDelete = false;

        foreach ($this->getMigrations() as $migration) {

            if ($this->isCurrentMigration($migration->name) && !$migration->isMigrated()) {
                // At this point we know the migration is the current one
                // and has not been migrated, so ignore it
                continue;
            }

            if ($hasSoftDelete && !$migration->withSoftDelete) {
                // At this point we know that the migration had soft-delete
                // previously, but it was dropped
                $hasSoftDelete = false;
            }
            if ($migration->withSoftDelete) {
                // At this point we know that the migraton has soft-delete
                $hasSoftDelete = true;
            }
        }

        return $hasSoftDelete;
    }
10913
public function migrate($migrationName) {
		$this->createTable();
		$this->db->dal()->into('_migrations')->insert(['name'=>$migrationName, 'migrated'=>date('Y-m-d H:i:s')]);
	}
307222
private static function validateFileds($cdn)
    {
        if (!isset($cdn['cdn_domains'])) {
            throw new ConfigurationException(sprintf('Missing "cdn_domains" for configuration %s', serialize($cdn)));
        }

        if (!is_array($cdn['cdn_domains'])) {
            throw new ConfigurationException(
                sprintf('Array value expected for "cdn_domains" for configuration %s', serialize($cdn))
            );
        }

        if (isset($cdn['path_patterns']) && !is_array($cdn['path_patterns'])) {
            throw new ConfigurationException(
                sprintf('Array value expected for "path_patterns" for configuration %s', serialize($cdn))
            );
        }

        if (isset($cdn['path_patterns'])) {
            foreach ($cdn['path_patterns'] as $pattern) {
                if (!self::isValidRegex($pattern)) {
                    throw new ConfigurationException(sprintf('Invalid regex pattern: %s', $pattern));
                }
            }
        }

        if (isset($cdn['sign_key']) && !is_string($cdn['sign_key'])) {
            throw new ConfigurationException(
                sprintf('String value expected for "sign_key" for configuration %s', serialize($cdn))
            );
        }

        if (isset($cdn['shard_strategy']) && (!is_string($cdn['shard_strategy'])
                || !in_array($cdn['shard_strategy'], ['crc', 'cycle'])
            )) {
            throw new ConfigurationException(
                sprintf('Allowed values for "shard_strategy" are "crc" or "cycle" in configuration %s', serialize($cdn))
            );
        }

        if (isset($cdn['default_query_params']) && (!is_array($cdn['default_query_params']))) {
            throw new ConfigurationException(
                sprintf('Array value expected for "default_query_params" are "crc" or "cycle" in configuration %s', serialize($cdn))
            );
        }

        if (isset($cdn['default_query_params']) && Utils::isMatrix($cdn['default_query_params'])) {
            throw new ConfigurationException(
                sprintf('Monodimensional array expected, matrix given as "default_query_parameters" in configuration: %s', serialize($cdn))
            );
        }

        if (isset($cdn['generate_filter_params']) && !is_bool($cdn['generate_filter_params'])) {
            throw new ConfigurationException(
                sprintf('Boolean expected for "generate_filter_params" in configuration: %s', serialize($cdn))
            );
        }
    }
741852
protected function processMigration(&$index, array $migrations, Migration $migration)
    {
        if (in_array($migration->getStatus(), [Migration::STATUS_MIGRATED, Migration::STATUS_RECURSIVE_FOREIGN_KEY], true)) {
            return;
        }
        $migration->setStatus(Migration::STATUS_IN_PROGRESS);

        // Check foreign keys
        $tableNames = $migration->getTable()->getForeignTableNames();
        foreach ($tableNames as $tableName) {
            if ($migration->getTable()->getTableName() === $tableName) {
                continue;
            }

            // Check recursive foreign key
            if (isset($migrations[$tableName]) && $migrations[$tableName]->getStatus() === Migration::STATUS_IN_PROGRESS) {
                $migration->setStatus(Migration::STATUS_RECURSIVE_FOREIGN_KEY);
                continue;
            }

            $this->processMigration($index, $migrations, $migrations[$tableName]);
        }

        $migration->writeTableOut($index, $this->output, $this->option('force'));

        if ($migration->getStatus() !== Migration::STATUS_RECURSIVE_FOREIGN_KEY) {
            $migration->setStatus(Migration::STATUS_MIGRATED);
        }

        $index++;
    }
20011
protected function doExecute()
    {
        $repository = $this->getRepository();

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

        $migrations = $repository->getMigrations();

        if (!count($migrations)) {
            throw new \RuntimeException('No migrations found.');
        }

        $this->out();
        $this->out(' Status  Version         Migration Name ');
        $this->out('-----------------------------------------');

        $versions = $repository->getVersions();

        $migrations->ksort();

        foreach ($migrations as $migration) {
            $status = (in_array($migration['id'], $versions)) ? '    <info>up</info>' : '  <error>down</error>';

            $info = sprintf(
                '%s   %14.0f  %s',
                $status,
                $migration['id'],
                '<comment>' . $migration['name'] . '</comment>'
            );

            $this->out($info);

            // Remove printed versions
            $index = array_search($migration['id'], $versions);

            unset($versions[$index]);
        }

        foreach ($versions as $version) {
            $info = sprintf(
                '%s   %14.0f  %s',
                '    <info>up</info>',
                $version,
                '** Missing **'
            );

            $this->out($info);
        }

        $this->out();

        return true;
    }
465128
protected function validateMigrationPaths($migrationPaths)
    {
        foreach ($migrationPaths as $migrationPath) {
            $path = \Yii::getAlias($migrationPath, false);
            if ($path === false) {
                throw new ExtensionException(
                  __CLASS__,
                  "Invalid path alias: $migrationPath"
                );
            }

            if (!file_exists($path)) {
                throw new ExtensionException(
                  __CLASS__,
                  "The migration path does not exist: " . realpath($this->getRootDir() . $path)
                );
            }
        }
    }
653984
public function add(MigrationTrackerCapsule $capsule, MigrationCapsule $migration = null)
    {
        $capsules = $this->all();

        if (!is_null($migration)) {
            $capsule->addMigration($migration);
        }

        $capsules[] = $capsule;

        $this->write($capsules);

        return $capsules;
    }