Gets the created sequences according to the old/new schemas.

@param \Fridge\DBAL\Schema\Schema $oldSchema The old schema.
@param \Fridge\DBAL\Schema\Schema $newSchema The new schema.

@return array The created sequences.
164249
private function getCreatedSequences(Schema $oldSchema, Schema $newSchema)
    {
        $createdSequences = array();

        foreach ($newSchema->getSequences() as $sequence) {
            if (!$oldSchema->hasSequence($sequence->getName())
                || $this->compareSequences($oldSchema->getSequence($sequence->getName()), $sequence)) {
                $createdSequences[] = $sequence;
            }
        }

        return $createdSequences;
    }
721652
public function compare(Schema $oldSchema, Schema $newSchema)
    {
        $createdTables = $this->getCreatedTables($oldSchema, $newSchema);
        $alteredTables = $this->getAlteredTables($oldSchema, $newSchema);
        $droppedTables = $this->getDroppedTables($oldSchema, $newSchema);

        $this->detectRenamedTables($createdTables, $droppedTables, $alteredTables);

        return new SchemaDiff(
            $oldSchema,
            $newSchema,
            $createdTables,
            $alteredTables,
            $droppedTables,
            $this->getCreatedSequences($oldSchema, $newSchema),
            $this->getDroppedSequences($oldSchema, $newSchema),
            $this->getCreatedViews($oldSchema, $newSchema),
            $this->getDroppedViews($oldSchema, $newSchema)
        );
    }
104330
protected function getParentSchemaObject(array $objectSchema, $schemaName)
    {
        if (isset($objectSchema['extends_default'])) {
            $parent = $this->getExtendedDefaultSchemaObject($objectSchema);
        } elseif (isset($objectSchema['extends']) && is_string($objectSchema['extends'])) {
            $parent = $this->getObjectFromSchema($this->schemas[$this->schemaFolder][$schemaName], $objectSchema['extends']);
        } elseif (isset($objectSchema['extends']) && is_array($objectSchema['extends']) && 2 == count($objectSchema['extends'])) {
            $name = reset($objectSchema['extends']);
            $type = $objectSchema['extends'][1];
            $this->parseAll($name);
            $parent = $this->getObjectFromSchema($this->schemas[$this->schemaFolder][$name], $type);
        } else {
            throw new SchemaParserException('The directive "extends" must be a string or array with exactly 2 values.');
        }

        return $parent;
    }
905660
protected function processSchemas(\Doctrine\DBAL\Schema\Schema $newSchema, \Doctrine\DBAL\Schema\Schema $oldSchema) {
		$comparator = new \Doctrine\DBAL\Schema\Comparator;
		$schemaDiff = $comparator->compare($oldSchema, $newSchema);

		$platform = $this->dataMapper->getDB()->getConn()->getDatabasePlatform();

		$queries = $schemaDiff->toSql($platform);
		foreach($queries as $query)
			$this->dataMapper->getDB()->query($query);
	}
1137287
private function getAlteredTables(Schema $oldSchema, Schema $newSchema)
    {
        $alteredTables = array();

        foreach ($newSchema->getTables() as $table) {
            if ($oldSchema->hasTable($table->getName())) {
                $tableDiff = $this->tableComparator->compare($oldSchema->getTable($table->getName()), $table);

                if ($tableDiff->hasDifference()) {
                    $alteredTables[] = $tableDiff;
                }
            }
        }

        return $alteredTables;
    }
1166113
private function findTableSchemas($schema = null)
    {
        $tableNames = $this->getTableNames($schema, true);

        if (is_callable($this->tableNameFilter)) {
            $tableNames = array_filter($tableNames,
                function($tableName) use ($schema) {
                    return call_user_func($this->tableNameFilter, $tableName, $schema);
                }
            );
        }

        $tableSchemas = array_map(
            function($tableName) use ($schema) {
                $tableSchema = new TableSchema();
                $tableNameFull = $schema === null ? $tableName : "$schema.$tableName";
                $this->resolveTableNames($tableSchema, $tableNameFull);
                return $tableSchema;
            },
            $tableNames);

        return $tableSchemas;
    }
1276775
public function getSchema()
    {
        if (!isset($this->schema)) {
            $class = '\\Wslim\\Db\\Schema\\' . $this->options['adapter'] . 'Schema';
            if (class_exists($class)) {
                $this->schema = new $class($this->getAdapter());
            } else {
                throw new DbException('Schema is not exist:' . $class);
            }
        }
        return $this->schema;
    }
288581
private function oldUpsert($table, $insertColumns, $updateColumns, &$params)
    {
        /**
 * @var Constraint[] $constraints 
*/
        list($uniqueNames, $insertNames, $updateNames) = $this->prepareUpsertColumns($table, $insertColumns, $updateColumns, $constraints);
        if (empty($uniqueNames)) {
            return $this->insert($table, $insertColumns, $params);
        }

        /**
 * @var Schema $schema 
*/
        $schema = $this->db->getSchema();
        if (!$insertColumns instanceof Query) {
            $tableSchema = $schema->getTableSchema($table);
            $columnSchemas = $tableSchema !== null ? $tableSchema->columns : [];
            foreach ($insertColumns as $name => $value) {
                // NULLs and numeric values must be type hinted in order to be used in SET assigments
                // NVM, let's cast them all
                if (isset($columnSchemas[$name])) {
                    $phName = self::PARAM_PREFIX . count($params);
                    $params[$phName] = $value;
                    $insertColumns[$name] = new Expression("CAST($phName AS {$columnSchemas[$name]->dbType})");
                }
            }
        }
        list(, $placeholders, $values, $params) = $this->prepareInsertValues($table, $insertColumns, $params);
        $updateCondition = ['or'];
        $insertCondition = ['or'];
        $quotedTableName = $schema->quoteTableName($table);
        foreach ($constraints as $constraint) {
            $constraintUpdateCondition = ['and'];
            $constraintInsertCondition = ['and'];
            foreach ($constraint->columnNames as $name) {
                $quotedName = $schema->quoteColumnName($name);
                $constraintUpdateCondition[] = "$quotedTableName.$quotedName=\"EXCLUDED\".$quotedName";
                $constraintInsertCondition[] = "\"upsert\".$quotedName=\"EXCLUDED\".$quotedName";
            }
            $updateCondition[] = $constraintUpdateCondition;
            $insertCondition[] = $constraintInsertCondition;
        }
        $withSql = 'WITH "EXCLUDED" (' . implode(', ', $insertNames)
            . ') AS (' . (!empty($placeholders) ? 'VALUES (' . implode(', ', $placeholders) . ')' : ltrim($values, ' ')) . ')';
        if ($updateColumns === false) {
            $selectSubQuery = (new Query())
                ->select(new Expression('1'))
                ->from($table)
                ->where($updateCondition);
            $insertSelectSubQuery = (new Query())
                ->select($insertNames)
                ->from('EXCLUDED')
                ->where(['not exists', $selectSubQuery]);
            $insertSql = $this->insert($table, $insertSelectSubQuery, $params);
            return "$withSql $insertSql";
        }

        if ($updateColumns === true) {
            $updateColumns = [];
            foreach ($updateNames as $name) {
                $quotedName = $this->db->quoteColumnName($name);
                if (strrpos($quotedName, '.') === false) {
                    $quotedName = '"EXCLUDED".' . $quotedName;
                }
                $updateColumns[$name] = new Expression($quotedName);
            }
        }
        list($updates, $params) = $this->prepareUpdateSets($table, $updateColumns, $params);
        $updateSql = 'UPDATE ' . $this->db->quoteTableName($table) . ' SET ' . implode(', ', $updates)
            . ' FROM "EXCLUDED" ' . $this->buildWhere($updateCondition, $params)
            . ' RETURNING ' . $this->db->quoteTableName($table) .'.*';
        $selectUpsertSubQuery = (new Query())
            ->select(new Expression('1'))
            ->from('upsert')
            ->where($insertCondition);
        $insertSelectSubQuery = (new Query())
            ->select($insertNames)
            ->from('EXCLUDED')
            ->where(['not exists', $selectUpsertSubQuery]);
        $insertSql = $this->insert($table, $insertSelectSubQuery, $params);
        return "$withSql, \"upsert\" AS ($updateSql) $insertSql";
    }
725718
public function renameForeignKey($oldName, $newName)
    {
        if (!$this->hasForeignKey($oldName)) {
            throw SchemaException::tableForeignKeyDoesNotExist($this->getName(), $oldName);
        }

        if ($this->hasForeignKey($newName)) {
            throw SchemaException::tableForeignKeyAlreadyExists($this->getName(), $newName);
        }

        $this->foreignKeys[$oldName]->setName($newName);
        $this->foreignKeys[$newName] = $this->foreignKeys[$oldName];
        unset($this->foreignKeys[$oldName]);
    }
98133
public function getSchemaDataDefaults()
    {
        $schema = parent::getSchemaDataDefaults();
        $schema['data'] = array_merge($schema['data'], [
            'showLinkText' => $this->getShowLinkText(),
            'linkedPage' => $this->getLinkPage() ? $this->getLinkPage()->toMap() : [],
            'title' => $this->Title(),
        ]);
        return $schema;
    }
503012
private function getDroppedTables(Schema $oldSchema, Schema $newSchema)
    {
        $droppedTables = array();

        foreach ($oldSchema->getTables() as $table) {
            if (!$newSchema->hasTable($table->getName())) {
                $droppedTables[] = $table;
            }
        }

        return $droppedTables;
    }
1042424
protected function getForeignKeysMigrations($new = [], $old = [])
    {
        if (empty($new['tables'])) {
            return [];
        }
        $output = [];
        foreach ($new['tables'] as $tableId => $newTable) {
            if ($newTable['table']['table_name'] === $this->options['default_migration_table']) {
                continue;
            }
            $oldTable = $old['tables'][$tableId];

            if (!empty($oldTable['foreign_keys'])) {
                foreach ($oldTable['foreign_keys'] as $fkName => $fkData) {
                    if (!isset($newTable['foreign_keys'][$fkName])) {
                        $output[] = $this->getForeignKeyRemove($tableId, $fkName);
                    }
                }
            }
            if (!empty($newTable['foreign_keys'])) {
                foreach ($newTable['foreign_keys'] as $fkName => $fkData) {
                    if (!isset($oldTable['foreign_keys'][$fkName])) {
                        $output[] = $this->getForeignKeyCreate($tableId, $fkName);
                    }
                }
            }
        }

        return $output;
    }
74595
public function getOldTable(): TableStructure
    {
        if ($this->_oldTable === null) {
            $this->_oldTable = new TableStructure([
                'schema' => get_class($this->db->schema),
                'generalSchema' => $this->generalSchema,
                'usePrefix' => $this->useTablePrefix,
                'dbPrefix' => $this->db->tablePrefix,
            ]);

            $this->_oldTable->applyChanges(array_reverse($this->_appliedChanges));
        }

        return $this->_oldTable;
    }
152630
public function getTableSchema(): ?TableSchema
    {
        if ($this->_tableSchema === null) {
            $this->_tableSchema = $this->db->getTableSchema($this->tableName);
        }

        return $this->_tableSchema;
    }
196522
public function cloneNode( $sourceNode, $sourceSchema = null )
    {
        return $this->sql()
                    ->paragraph_clone( ( (string) $sourceSchema ) ?: null,
                                       (int)      $sourceNode );
    }
824938
protected function applyExtensions(array $extensions, FormInterface $form, array $schema)
    {
        $newSchema = $schema;
        foreach ($extensions as $extension) {
            $newSchema = $extension->apply($form, $newSchema);
        }

        return $newSchema;
    }
1093198
public function merge(array $bundleSchemaCollection): array
    {
        $result = [];
        $collectionToMerge = [];

        foreach ($bundleSchemaCollection as $schemaFilename => $bundleSchemaData) {
            foreach ($bundleSchemaData as $path => $bundlesSchemaFiles) {
                foreach ($bundlesSchemaFiles as $name => $bundleSchemaFile) {
                    $collectionToMerge[$name][] = $bundleSchemaFile;
                }
            }
        }

        foreach ($collectionToMerge as $name => $data) {
            $schemaFiles = $this->sortByBundleSchema($data);
            $bundleSchema = \array_shift($schemaFiles);
            $this->schemaValidator->assertIsBundleSchema($bundleSchema);

            $mergedProperties = $this->mergeProperties($bundleSchema, $schemaFiles);
            $mergedBundleSchema = $this->schemaBuilder->buildBundleSchemaWithProperties($bundleSchema, $mergedProperties);

            $result[$mergedBundleSchema->getSchema()->getName()] = $mergedBundleSchema;
        }

        return $result;
    }