Gets the created columns according to the old/new tables.

@param \Fridge\DBAL\Schema\Table $oldTable The old table.
@param \Fridge\DBAL\Schema\Table $newTable The new tabme.

@return array The created columns.
13057
private function getCreatedColumns(Table $oldTable, Table $newTable)
    {
        $createdColumns = array();

        foreach ($newTable->getColumns() as $column) {
            if (!$oldTable->hasColumn($column->getName())) {
                $createdColumns[] = $column;
            }
        }

        return $createdColumns;
    }
1351524
protected function newTable($table = null)
    {
        return new Table(
            static::$dbManager,
            $this->connectionName,
            $table ? : $this->tableName,
            static::$dbManager->getStructure($this->connectionName)
        );
    }
773973
protected function renameDatabaseTableField($table, $oldFieldName, $newFieldName)
    {
        $title = 'Renaming "' . $table . ':' . $oldFieldName . '" to "' . $table . ':' . $newFieldName . '": ';

        $currentTableFields = $this->databaseConnection->admin_get_fields($table);

        if ($currentTableFields[$newFieldName]) {
            $message = 'Field ' . $table . ':' . $newFieldName . ' already existing.';
            $status = FlashMessage::OK;
        } else {
            if (!$currentTableFields[$oldFieldName]) {
                $message = 'Field ' . $table . ':' . $oldFieldName . ' not existing';
                $status = FlashMessage::ERROR;
            } else {
                $sql = 'ALTER TABLE ' . $table . ' CHANGE COLUMN ' . $oldFieldName . ' ' . $newFieldName . ' ' .
                    $currentTableFields[$oldFieldName]['Type'];

                if ($this->databaseConnection->admin_query($sql) === false) {
                    $message = ' SQL ERROR: ' . $this->databaseConnection->sql_error();
                    $status = FlashMessage::ERROR;
                } else {
                    $message = 'OK!';
                    $status = FlashMessage::OK;
                }
            }
        }

        $this->addMessage($status, $title, $message);

        return $status;
    }
633676
protected function getTableColumns()
    {
        if (0 === count(self::$tableColumns)) {
            $table = $this->getTable();
            $connect = $this->getConnection();
            $builder = $connect->getSchemaBuilder();
            $columns = $builder->getColumnListing($table);

            self::$tableColumns = (array)$columns;
        }
        return self::$tableColumns;
    }
864560
protected function getAlterTableInfo($table)
    {
        $columns = $table->getColumns();
        $indexes = $table->getIndexes();
        $name    = $table->getName();

        $databaseService = new DatabaseService($this->config, $this->files);
        $upMigrations    = [
            'columns' => [
                'add'  => [],
                'drop' => [],
            ],
            'indexes' => [
                'add'  => [],
                'drop' => [],
            ],
        ];
        $downMigrations  = [
            'columns' => [
                'add'  => [],
                'drop' => [],
            ],
            'indexes' => [
                'add'  => [],
                'drop' => [],
            ],
        ];

        $updated = false;

        $currentColumns = $databaseService->getTableColumns($name);
        $newColumnNames = array_map(function ($column) {
            return $column->getName();
        }, $columns);
        $oldColumnNames = array_map(function ($column) {
            return $column->getName();
        }, $currentColumns);

        $mustHaveColumns = ['created_at', 'updated_at'];
        foreach ($mustHaveColumns as $column) {
            if (!in_array($column, $newColumnNames)) {
                $newColumnNames[] = $column;
            }
            if (!in_array($column, $oldColumnNames)) {
                $oldColumnNames[] = $column;
            }
        }

        $addedColumns   = array_diff($newColumnNames, $oldColumnNames);
        $removedColumns = array_diff($oldColumnNames, $newColumnNames);

        $previousColumnName = '';
        foreach ($columns as $column) {
            if (in_array($column->getName(), $addedColumns)) {
                $columnObject = new Column($column);

                $upMigrations['columns']['add'][]    = $columnObject->generateAddMigration($previousColumnName).';';
                $downMigrations['columns']['drop'][] = $columnObject->generateDropMigration().';';
                $updated                             = true;
            }
            $previousColumnName = $column->getName();
        }

        $previousColumnName = '';
        foreach ($currentColumns as $column) {
            if (in_array($column->getName(), $removedColumns)) {
                $columnObject = new Column($column);

                $upMigrations['columns']['drop'][]  = $columnObject->generateDropMigration().';';
                $downMigrations['columns']['add'][] = $columnObject->generateAddMigration($previousColumnName).';';
                $updated                            = true;
            }
            $previousColumnName = $column->getName();
        }

        $currentIndexes = $databaseService->getTableIndexes($name);
        $newIndexNames  = array_map(function ($index) {
            return $index->getName();
        }, $indexes);
        $oldIndexNames  = array_map(function ($index) {
            return $index->getName();
        }, $currentIndexes);

        $addedIndexes   = array_diff($newIndexNames, $oldIndexNames);
        $removedIndexes = array_diff($oldIndexNames, $newIndexNames);

        foreach ($indexes as $index) {
            if (in_array($index->getName(), $addedIndexes)) {
                $indexObject = new Index($index);

                $upMigrations['indexes']['add'][]    = $indexObject->generateAddMigration().';';
                $downMigrations['indexes']['drop'][] = $indexObject->generateDropMigration().';';
                $updated                             = true;
            }
        }

        foreach ($currentIndexes as $index) {
            if (in_array($index->getName(), $removedIndexes)) {
                $indexObject = new Index($index);

                $upMigrations['indexes']['drop'][]  = $indexObject->generateDropMigration().';';
                $downMigrations['indexes']['add'][] = $indexObject->generateAddMigration().';';
                $updated                            = true;
            }
        }

        if (!$updated) {
            return false;
        }

        return [
            'upMigrations'   => $upMigrations,
            'downMigrations' => $downMigrations,
        ];
    }
663045
protected function getTableMigrationTables(array $output, array $new, array $old): array
    {
        if (empty($new['tables'])) {
            return $output;
        }

        foreach ($new['tables'] as $tableName => $table) {
            if ($tableName === $this->options['default_migration_table']) {
                continue;
            }

            $output[] = $this->getTableVariable($table, $tableName);

            // To add or modify
            $output = $this->getTableMigrationNewTablesColumns($output, $table, $tableName, $new, $old);
            $output = $this->getTableMigrationOldTablesColumns($output, $tableName, $new, $old);
            $output = $this->getTableMigrationIndexes($output, $table, $tableName, $new, $old);

            if (!empty($this->options['foreign_keys'])) {
                $output = $this->getForeignKeysMigrations($output, $tableName, $new, $old);
            }

            if (isset($old['tables'][$tableName])) {
                // Update existing table
                $output[] = sprintf('%s->save();', $this->ind3);
            } else {
                // Create new table
                $output[] = sprintf('%s->create();', $this->ind3);
            }
        }

        // To remove
        $output = $this->getTableMigrationDropTables($output, $new, $old);

        return $output;
    }
1251925
public function columns($table)
	{
		$columns = array();
		$sth = $this->queryColumnInfo($table);

		while (($row = $sth->fetch())) {
			$c = $this->createColumn($row);
			$columns[$c->name] = $c;
		}
		return $columns;
	}
39755
private function getCreatedChecks(Table $oldTable, Table $newTable)
    {
        $createdChecks = array();

        foreach ($newTable->getChecks() as $check) {
            if (!$oldTable->hasCheck($check->getName())
                || $this->compareChecks($oldTable->getCheck($check->getName()), $check)) {
                $createdChecks[] = $check;
            }
        }

        return $createdChecks;
    }
562484
protected function getTableColumns()
    {
        if (!$this->model->getConnection()->isDoctrineAvailable()) {
            throw new \Exception(
                'You need to require doctrine/dbal: ~2.3 in your own composer.json to get database columns. '
            );
        }

        $table = $this->model->getConnection()->getTablePrefix().$this->model->getTable();
        /** @var \Doctrine\DBAL\Schema\MySqlSchemaManager $schema */
        $schema = $this->model->getConnection()->getDoctrineSchemaManager($table);

        // custom mapping the types that doctrine/dbal does not support
        $databasePlatform = $schema->getDatabasePlatform();

        foreach ($this->doctrineTypeMapping as $doctrineType => $dbTypes) {
            foreach ($dbTypes as $dbType) {
                $databasePlatform->registerDoctrineTypeMapping($dbType, $doctrineType);
            }
        }

        $database = null;
        if (strpos($table, '.')) {
            list($database, $table) = explode('.', $table);
        }

        return $schema->listTableColumns($table, $database);
    }
671193
public function getTableColumns(string $table): array {
		$query = <<<QUERY
			SELECT COLUMN_NAME
			FROM INFORMATION_SCHEMA.COLUMNS
			WHERE TABLE_SCHEMA = :database
			AND TABLE_NAME = :table
QUERY;
		
		$params = [
			"database" => $this->database,
			"table"    => $table,
		];
		
		try {
			$results = $this->getCol($query, $params);
			return is_array($results) ? $results : [];
		} catch (\PDOException $databaseException) {
			throw $this->prepareDatabaseException($databaseException, $query, $params);
		}
	}
615610
private function getSearchableColumnNames(TableMetadata $tableMetadata): array
    {
        $columnNameList = [];
        foreach ($tableMetadata->getAllColumnMetadata() as $columnMetadata) {
            if ($columnMetadata->isStringType()) {
                $columnNameList[] = $columnMetadata->getColumnName();
            }
        }
        return $columnNameList;
    }
900887
protected function columns(Table $table)
		{
			$columns = array();

			foreach ($table->columns as $column) {
				// Each of the data type's have their own definition creation method,
				// which is responsible for creating the SQL for the type. This lets
				// us to keep the syntax easy and fluent, while translating the
				// types to the correct types.
				$sql = $this->wrap($column) . ' ' . $this->type($column);

				$elements = array('nullable', 'defaults', 'incrementer');

				foreach ($elements as $element) {
					$sql .= $this->$element($table, $column);
				}

				$columns[] = $sql;
			}

			return $columns;
		}
1136023
public function getTable($tableName)
    {
        $table = new Table($tableName);

        $columns = $this->_getColumns($tableName);
        foreach ($columns as $col) {
            $table->addColumn($this->_createColumn($col));
        }

        $constraints = $this->_getConstraints($tableName);
        foreach ($constraints as $constraint) {
            $object = $this->_createConstraint($constraint);
            if ($object) {
                $table->addConstraint($object);
            }
        }

        return $table;
    }
574308
private function getDroppedForeignKeys(Table $oldTable, Table $newTable)
    {
        $droppedForeignKeys = array();

        foreach ($oldTable->getForeignKeys() as $foreignKey) {
            if (!$newTable->hasForeignKey($foreignKey->getName())
                || $this->compareForeignKeys($foreignKey, $newTable->getForeignKey($foreignKey->getName()))) {
                $droppedForeignKeys[] = $foreignKey;
            }
        }

        return $droppedForeignKeys;
    }
1225141
public function getTableColumns($table, $typeOnly = true)
	{
		$result = array();

		$table_temp = $this->replacePrefix((string) $table);

		// Set the query to get the table fields statement.
		$this->setQuery(
			'SELECT column_name as Field, data_type as Type, is_nullable as \'Null\', column_default as \'Default\'' .
			' FROM information_schema.columns' . ' WHERE table_name = ' . $this->quote($table_temp)
		);
		$fields = $this->loadObjectList();

		// If we only want the type as the value add just that to the list.
		if ($typeOnly)
		{
			foreach ($fields as $field)
			{
				$result[$field->Field] = preg_replace("/[(0-9)]/", '', $field->Type);
			}
		}
		else
		// If we want the whole field data object add that to the list.
		{
			foreach ($fields as $field)
			{
				$result[$field->Field] = $field;
			}
		}

		return $result;
	}
1127213
public function getTableColumns($table, $allColumns = false)
    {
        $tableColumns = Schema::getColumnListing($table);

        $tableTypeColumns = [];
        $badColumns = ['id', 'created_at', 'updated_at'];

        if ($allColumns) {
            $badColumns = [];
        }

        foreach ($tableColumns as $column) {
            if (!in_array($column, $badColumns)) {
                $type = DB::connection()->getDoctrineColumn($table, $column)->getType()->getName();
                $tableTypeColumns[$column]['type'] = $type;
            }
        }

        return $tableTypeColumns;
    }
993819
protected function exportableColumns(): array
    {
        if (method_exists($this->module, 'exportableColumns')) {
            return $this->module->exportableColumns();
        }

        /**
         * @var Model
         */
        $model = $this->module->model();

        return collect($model->getFillable())
            ->prepend('id')
            ->diff($model->getHidden())
            ->map(function ($column) use ($model) {
                return "{$model->getTable()}.{$column}";
            })
            ->when($model instanceof Translatable, function (Collection $collection) use ($model) {
                return $collection->merge(
                    collect($model->getTranslatedAttributes())
                        ->map(function ($column) use ($model) {
                            return "tt.{$column}";
                        })
                );
            })
            ->all();
    }