@param \xPDOQuery|array|null $criteria
@param string $server_type
@param string $name
@param bool $create_migration_file

@return array
495162
public function makeTemplateSeeds($criteria, $server_type = 'master', $name = null, $create_migration_file = true)
    {
        $keys = [];
        $collection = $this->modx->getCollection('modTemplate', $criteria);

        foreach ($collection as $template) {
            //exit();
            /** @var \LCI\Blend\Blendable\Template $blendTemplate */
            $blendTemplate = new Template($this->modx, $this->blender, $template->get('templatename'));
            $seed_key = $blendTemplate
                ->setSeedsDir($this->format->getMigrationName('template', $name))
                ->seed();
            $this->blender->out("Template ID: ".$template->get('id').' Key: '.$seed_key);
            $keys[] = $seed_key;
        }

        if ($create_migration_file) {
            /** @var MigrationsCreator $migrationCreator */
            $migrationCreator = new MigrationsCreator($this->blender->getUserInteractionHandler(), $keys);

            $migrationCreator
                ->setPathTimeStamp($this->format->getPathTimeStamp())
                ->setVerbose($this->blender->getVerbose())
                ->setName($name)
                ->setDescription('')
                ->setServerType($server_type)
                ->setMigrationsPath($this->blender->getMigrationPath())
                ->createTemplateMigrationClassFile();

            $this->logCreatedSeedMigration($migrationCreator->getLogData());
        }
        return $keys;
    }
34637
public function buildQuery($in_is_expanding = false, $criteria_name = "", $in_design_mode = false, $no_warnings = false)
    {

        if (!$criteria_name) {
            $this->setRequestColumns();
        }

        $execute_mode = $this->getExecuteMode();

        // Use raw user query in >= Version 2.5
        if ($this->sql_raw) {
            // Now if any of the criteria is an SQLCOMMAND then that should be used for the report data so
            // parse the users command and execute it
            if (!$in_is_expanding && !$criteria_name && !$in_design_mode) {
                foreach ($this->lookup_queries as $key => $col) {
                    if ($col->criteria_type == "SQLCOMMAND") {
                        $this->importSQL($col->column_value);
                    }

                }
            }

            $this->query_statement = $this->sql_raw;

            // Build in criteria items
            $critwhere = "";
            if ($execute_mode != "MAINTAIN") {
                foreach ($this->lookup_queries as $k => $col) {
                    if ($col->column_name) {
                        $critwhere .= $col->getCriteriaClause();
                    }
                }
            }

            // Add in any expand criteria
            $critwhere .= $this->buildWhereExtraList($in_is_expanding, $criteria_name);

            // If user has "Main query column" criteria then parse sql to find
            // where to insert them
            if ($critwhere) {
                $p = new SqlParser($this->query_statement);
                if ($p->parse()) {
                    if ($p->haswhere) {
                        $this->query_statement =
                        substr($this->query_statement, 0, $p->whereoffset) .
                        " 1 = 1" .
                        $critwhere .
                        " AND" .
                        substr($this->query_statement, $p->whereoffset);
                    } else {
                        $this->query_statement =
                        substr($this->query_statement, 0, $p->whereoffset) .
                        " WHERE 1 = 1 " .
                        $critwhere .
                        substr($this->query_statement, $p->whereoffset);
                    }
                }
            }

            // Dont add limits/offset if crtieria query of entering SQL in design mode
            if (!$criteria_name && !$in_design_mode) {
                if ($this->datasource->_conn_driver != "pdo_informix" && $this->datasource->_conn_driver != "informix") {
                    $this->query_statement .= $this->buildLimitOffset();
                }
            }

        } else {
            // Pre Version 2.5 - parts of SQL specified in XML
            $this->query_statement = "SELECT";

            // Dont add limits/offset if crtieria query of entering SQL in design mode
            if (!$criteria_name && !$in_design_mode) {
                if ($this->datasource->_conn_driver == "pdo_informix" || $this->datasource->_conn_driver == "informix") {
                    $this->query_statement .= $this->buildLimitOffset();
                }
            }

            if ($this->rowselection == "unique") {
                if ($this->datasource->_conn_driver == "pdo_informix" || $this->datasource->_conn_driver == "informix") {
                    $this->query_statement .= " UNIQUE";
                } else {
                    $this->query_statement .= " DISTINCT";
                }
            }

            $this->query_statement .= $this->buildColumnList();
            $this->query_statement .= $this->buildTableList();

            if ($execute_mode == "MAINTAIN") {
                $this->query_statement .= $this->buildWhereList(false);
            } else {
                $this->query_statement .= $this->buildWhereList(true);
            }

            $this->query_statement .= $this->buildWhereExtraList($in_is_expanding, $criteria_name);
            $this->query_statement .= $this->buildWhereCriteriaLink($in_is_expanding);
            $this->query_statement .= $this->buildOrderList($criteria_name);

            // Dont add limits/offset if crtieria query of entering SQL in design mode
            if (!$criteria_name && !$in_design_mode) {
                if ($this->datasource->_conn_driver != "pdo_informix" && $this->datasource->_conn_driver != "informix") {
                    $this->query_statement .= $this->buildLimitOffset();
                }
            }

        }

        if ($execute_mode != "MAINTAIN") {
            $this->query_statement = Assignment::reporticoMetaSqlCriteria($this->parent_query, $this->query_statement, false, $no_warnings, $execute_mode);
        }

    }
1106461
function (migrationName, scope, callback) {
    var executeCreateMigration = load('create-migration');
    if (typeof scope === 'function') {
      callback = scope;
    } else if (scope) {
      this.internals.migrationMode = scope;
      this.internals.matching = scope;
    }

    this.internals.argv._.push(migrationName);
    return Promise.fromCallback(
      function (callback) {
        executeCreateMigration(this.internals, this.config, callback);
      }.bind(this)
    ).asCallback(callback);
  }
616713
public function makePluginSeeds($criteria, $server_type = 'master', $name = null, $create_migration_file = true)
    {
        $keys = [];
        $collection = $this->modx->getCollection('modPlugin', $criteria);

        foreach ($collection as $plugin) {
            /** @var \LCI\Blend\Blendable\Plugin $blendPlugin */
            $blendPlugin = new Plugin($this->modx, $this->blender, $plugin->get('name'));
            $seed_key = $blendPlugin
                ->setSeedsDir($this->format->getMigrationName('plugin', $name))
                ->seed();
            $this->blender->out("Plugin: ".$plugin->get('name').' Key: '.$seed_key);
            $keys[] = $seed_key;
        }

        if ($create_migration_file) {
            /** @var MigrationsCreator $migrationCreator */
            $migrationCreator = new MigrationsCreator($this->blender->getUserInteractionHandler(), $keys);

            $migrationCreator
                ->setPathTimeStamp($this->format->getPathTimeStamp())
                ->setVerbose($this->blender->getVerbose())
                ->setName($name)
                ->setDescription('')
                ->setServerType($server_type)
                ->setMigrationsPath($this->blender->getMigrationPath())
                ->createPluginMigrationClassFile();

            $this->logCreatedSeedMigration($migrationCreator->getLogData());
        }
        return $keys;
    }
439683
protected function writeMigration($driver, $name, $table, $create)
    {
        $migrator = $this->tenant->driver($driver);
        $files = $this->creator->getFilesystem();
        $path = $migrator->getMigrationPaths();

        if (! $files->isDirectory($path)) {
            $files->makeDirectory($path, 0755, true);
        }

        if ($this->tenant->getConfig("{$driver}.shared", true) === true) {
            $table = Str::replace($migrator->getTablePrefix()."_{$table}", ['id' => '{$id}']);
        }

        $name = \implode('_', [$driver, 'tenant', $name]);

        $file = \pathinfo($this->creator->create($name, $path, $table, $create), PATHINFO_FILENAME);

        $this->line("<info>Created Migration:</info> $file");
    }
1128340
public function getBranch(Criteria $criteria = null, ConnectionInterface $con = null)
    {
        return ChildCategoryQuery::create(null, $criteria)
            ->branchOf($this)
            ->orderByBranch()
            ->find($con);
    }
812142
protected static function write_install($name, $type, $file)
	{
		// add the migration just run
		\DB::insert(static::$table)->set(array(
			'name' => $name,
			'type' => $type,
			'migration' => $file,
		))->execute(static::$connection);

		// add the file to the list of run migrations
		static::$migrations[$type][$name][] = $file;

		// make sure the migrations are in the correct order
		sort(static::$migrations[$type][$name]);

		// and save the update to the environment config file
		\Config::set('migrations.version.'.$type.'.'.$name, static::$migrations[$type][$name]);
		\Config::save(\Fuel::$env.DS.'migrations', 'migrations');
	}
1241448
public function copyMigration($name, $template)
    {
        $migrations = $this->getMigrations();

        // Check name not exists
        foreach ($migrations as $migration) {
            if (strtolower($name) == strtolower($migration['name'])) {
                throw new \RuntimeException(
                    'Migration: <info>' . $name . "</info> has exists. \nFile at: <info>" .
                    $migration['path'] . '</info>'
                );
            }
        }

        $date = gmdate('YmdHis');

        $file = $date . '_' . ucfirst($name) . '.php';

        $tmpl = file_get_contents($template);

        $tmpl = SimpleTemplate::render($tmpl, ['version' => $date, 'className' => ucfirst($name)]);

        // Get file path
        $filePath = $this->get('path') . '/' . $file;

        if (is_file($filePath)) {
            throw new \RuntimeException(sprintf('File already exists: %s', $filePath));
        }

        // Write it
        File::write($filePath, $tmpl);

        $this->out()->out('Migration version: <info>' . $file . '</info> created.');
        $this->out('File path: <info>' . realpath($filePath) . '</info>');
    }
552656
public function getSchemaExtension($name, ConnectionInterface $conn)
    {
        if (isset($this->extensions[$name])) {
            return call_user_func($this->extensions[$name], $conn);
        }

        return null;
    }
402960
private function migrateAll(string $migrationFile, string $name, string $action)
  {
    $title =  substr($migrationFile, 0, -4);
    $migration = Migration::where('title', $title)->first();

    if (strtolower($action == 'drop' ? 'down' : $action) == 'down') {
      if ($migration != null) {
        try {
          call_user_func([$name, 'down']);
        }
        catch (Exception $e) {
          Log::error($e);
          return '<error>Couldn\'t migrate. See log for more information</error>';
        }

        $migration->delete();
        return '<info>Migration was successful</info>';
      }
      else {
        return 0;
      }
    }
    else if (strtolower($action) == 'up'){
      if ($migration == null) {
        try {
          call_user_func([$name, 'up']);
        }
        catch (Exception $e) {
          Log::error($e);
          return '<error>Couldn\'t migrate. See log for more information</error>';
        }

        Migration::create([
          'title' => $title
        ]);

        return '<info>Migration was successful</info>';
      }
      else {
        return 0;
      }
    }
  }
820343
public function createField($fieldType, $name = null, $required = false)
    {
        $fieldPosition = $this->getActualFieldPosition();
        $name = ($name == null ? $fieldType : $name);
        $fieldCreateStruct = $this->contentTypeService->newFieldDefinitionCreateStruct(
            $name,
            $this->fieldTypeInternalIdentifier[$fieldType]
        );
        $fieldCreateStruct->names = array(self::DEFAULT_LANGUAGE => $name);
        $fieldCreateStruct->position = $fieldPosition;
        $fieldCreateStruct->isRequired = $required;
        $fieldCreateStruct->defaultValue = $this->defaultValues[$fieldType];
        $this->fieldConstructionObject['fieldType'] = $fieldCreateStruct;
        $this->fieldConstructionObject['objectState'] = self::FIELD_TYPE_CREATED;
    }
1097862
public static function hasMigrated(string $name){
        $res = DB::connection('default')->table('migrations')->where('name', $name)->first();
        return !is_null($res);
    }
231892
public function make(Connection $connection, $name = null)
    {
        if ($name && $this->config->has('migrations.' . $name)) {
            $config = new Repository($this->config->get('migrations.' . $name, []));
        } else {
            $config = new Repository($this->config->get('migrations.default', []));
        }

        $configuration = new Configuration($connection);
        $configuration->setName($config->get('name', 'Doctrine Migrations'));
        $configuration->setMigrationsNamespace($config->get('namespace', 'Database\\Migrations'));
        $configuration->setMigrationsTableName($config->get('table', 'migrations'));

        $configuration->getConnection()->getConfiguration()->setFilterSchemaAssetsExpression(
            $config->get('schema.filter', '/^(?).*$/')
        );

        $configuration->setNamingStrategy($this->container->make(
            $config->get('naming_strategy', DefaultNamingStrategy::class)
        ));

        $configuration->setMigrationsFinder($configuration->getNamingStrategy()->getFinder());

        $directory = $config->get('directory', database_path('migrations'));
        $configuration->setMigrationsDirectory($directory);
        $configuration->registerMigrationsFromDirectory($directory);

        return $configuration;
    }
1060601
public function findOneWhere($criteria, $returnType = Table::RETURN_MODEL) {
        $this->limit(1);
        $result = $this->findWhere($criteria, $returnType);
        if (is_array($result)) {
            $result = array_values($result);
            return ($returnType === Table::RETURN_JSON) ? json_encode($result[0])
                        : $result[0];
        }
        else if (is_object($result)) {
            return $result->first();
        }
    }
583955
public function createBlankMigrationClassFile($name, $server_type = 'master', $migration_path = null)
    {
        $migrationCreator = new MigrationsCreator($this->userInteractionHandler);

        if (empty($migration_path)) {
            $migration_path = $this->getMigrationPath();
        }

        $success = $migrationCreator
            ->setPathTimeStamp($this->getSeedsDir())
            ->setVerbose($this->getVerbose())
            ->setName($name)
            ->setDescription('')
            ->setServerType($server_type)
            ->setMigrationsPath($migration_path)
            ->createBlankMigrationClassFile();

        $this->logCreatedMigration($migrationCreator->getLogData());
        return $success;
    }
407493
public function forceInitialMigration($reference, $criteria = self::FORCEDMIGRATION_INCLUSIVE)
    {
        $reference = trim((string) $reference);
        if ($reference === '') {
            throw new Exception(t('Invalid initial migration reference.'));
        }
        if (!in_array($criteria, [static::FORCEDMIGRATION_INCLUSIVE, static::FORCEDMIGRATION_EXCLUSIVE], true)) {
            throw new Exception(t('Invalid initial migration criteria.'));
        }

        // Remove possible 'Version' prefix from the migration identifier.
        // This allows a user to also use VersionXXXXXXXXXXXX, which corresponds with the class name.
        $reference = str_replace('Version', '', $reference);

        $migration = $this->findInitialMigration($reference, $criteria);
        if ($migration === null) {
            throw new Exception(t('Unable to find a migration with identifier %s', $reference));
        }
        $this->forcedInitialMigration = $migration;
    }
572162
protected static function write_revert($name, $type, $file)
	{
		// remove the migration just run
		\DB::delete(static::$table)
			->where('name', $name)
			->where('type', $type)
			->where('migration', $file)
		->execute(static::$connection);

		// remove the file from the list of run migrations
		if (($key = array_search($file, static::$migrations[$type][$name])) !== false)
		{
			unset(static::$migrations[$type][$name][$key]);
		}

		// make sure the migrations are in the correct order
		sort(static::$migrations[$type][$name]);

		// and save the update to the config file
		\Config::set('migrations.version.'.$type.'.'.$name, static::$migrations[$type][$name]);
		\Config::save(\Fuel::$env.DS.'migrations', 'migrations');
	}