Update database table via schema.

@param string $table  real table name to update
@param type   $schema
@param type   $parse

@return type
975587
public function applyTable($table, $schema, $parse = true)
    {
        // retrive queries
        $queries = $this->diffTable($table, $schema, $parse);

        // execute queries
        if ($queries && count($queries) > 0) {
            // loop throu all queries calculated and execute it
            foreach ($queries as $sql) {
                // execute each queries
                $this->execute($sql);
            }
        }

        return $queries;
    }
1113488
public function addSchema(string $schema) : void
    {
        $work = $schema;
        if ($work{0} != '/') {
            $work = getcwd()."/$work";
        }
        if (!file_exists($work)) {
            $this->notice("`\"$schema\"` for `{$this->database}` not found, skipping.");
            return;
        }
        $this->schemas[] = file_get_contents($work);
        $this->success("Loaded $schema.");
    }
376876
protected function parseSchemaAndTable($table)
    {
        $table = explode('.', $table);

        if (is_array($schema = $this->connection->getConfig('schema'))) {
            if (in_array($table[0], $schema)) {
                return [array_shift($table), implode('.', $table)];
            }

            $schema = head($schema);
        }

        return [$schema ?: 'public', implode('.', $table)];
    }
85449
private function diffTableQueries($table, &$schema)
    {
        // first order queries used as output array
        $foQueries = [];

        // second order queries used as output array
        $soQueries = [];

        // describe table get current table description
        $fields = $this->descTable($table);

        // test field definition
        foreach ($schema as $field => &$attributes) {
            $this->diffTableField(
                $table,
                $field,
                $attributes,
                $fields,
                $foQueries,
                $soQueries
            );
        }

        return $this->diffTableMergeQueries(
            $table,
            $fields,
            $foQueries,
            $soQueries
        );
    }
1328303
public final static function updateSchemaModel()
    {
        $model = new static();

        if (MbMigration::schema()->hasTable($model->getTable())) {
            MbMigration::schema()->table($model->getTable(), function (Blueprint $table) use ($model) {
                $table->engine = 'InnoDB';
                $model->updateSchema($table);
            });
        } else {
            throw new \Exception("Schema {$model->getTable()} was not found");
        }
    }
1313092
public function setSchema(Schema $schema)
    {
        $this->schema = $schema;

        if (!$this->getSchema()->hasTable($this->getName())) {
            $this->getSchema()->addTable($this);
        }
    }
1057238
public function upgradeSchema(Schema $schema)
    {
        // add new multilingual tables.
        if (!$schema->hasTable('MultilingualPageRelations')) {
            $mpr = $schema->createTable('MultilingualPageRelations');
            $mpr->addColumn('mpRelationID', 'integer', ['notnull' => true, 'unsigned' => true, 'default' => 0]);
            $mpr->addColumn('cID', 'integer', ['notnull' => true, 'unsigned' => true, 'default' => 0]);
            $mpr->addColumn('mpLanguage', 'string', ['notnull' => true, 'default' => '']);
            $mpr->addColumn('mpLocale', 'string', ['notnull' => true]);
            $mpr->setPrimaryKey(['mpRelationID', 'cID', 'mpLocale']);
        }
        if (!$schema->hasTable('MultilingualSections')) {
            $mus = $schema->createTable('MultilingualSections');
            $mus->addColumn('cID', 'integer', ['notnull' => true, 'unsigned' => true, 'default' => 0]);
            $mus->addColumn('msLanguage', 'string', ['notnull' => true, 'default' => '']);
            $mus->addColumn('msCountry', 'string', ['notnull' => true, 'default' => '']);
            $mus->setPrimaryKey(['cID']);
        }
        if (!$schema->hasTable('MultilingualTranslations')) {
            $mts = $schema->createTable('MultilingualTranslations');
            $mts->addColumn('mtID', 'integer', ['autoincrement' => true, 'unsigned' => true]);
            $mts->addColumn('mtSectionID', 'integer', ['unsigned' => true, 'notnull' => true, 'default' => 0]);
            $mts->addColumn('msgid', 'text', ['notnull' => false]);
            $mts->addColumn('msgstr', 'text', ['notnull' => false]);
            $mts->addColumn('context', 'text', ['notnull' => false]);
            $mts->addColumn('comments', 'text', ['notnull' => false]);
            $mts->addColumn('reference', 'text', ['notnull' => false]);
            $mts->addColumn('flags', 'text', ['notnull' => false]);
            $mts->addColumn('updated', 'datetime', ['notnull' => false]);
            $mts->setPrimaryKey(['mtID']);
        }
    }
188004
public function upgradeSchema(Schema $schema)
    {
        $this->version->getConfiguration()->getOutputWriter()->write(t('Adding fields to workflow and select tables...'));
        if (!$schema->getTable('Workflows')->hasColumn('pkgID')) {
            $schema->getTable('Workflows')->addColumn('pkgID', 'integer', [
                'unsigned' => true, 'notnull' => true, 'default' => 0,
            ]);
        }
        if (!$schema->getTable('atSelectOptions')->hasColumn('isDeleted')) {
            $schema->getTable('atSelectOptions')->addColumn('isDeleted', 'boolean', [
                'default' => 0,
            ]);
        }
    }
1296254
public static function execute($table)
	{
		// The implications method is responsible for finding any fluently
		// defined indexes on the schema table and adding the explicit
		// commands that are needed for the schema instance.
		static::implications($table);

		foreach ($table->commands as $command) {

			$grammar = static::grammar($connection);

			// Each grammar has a function that corresponds to the command type and
			// is for building that command's SQL. This lets the SQL syntax builds
			// stay granular across various database systems.
			if (method_exists($grammar, $method = $command->type)) {
				$statements = $grammar->$method($table, $command);

				// Once we have the statements, we will cast them to an array even
				// though not all of the commands return an array just in case it
				// needs multiple queries to complete.
				foreach ((array) $statements as $statement) {
					$connection->query($statement);
				}
			}
		}
	}
1266350
public function update($table = null)
    {
        if (!$table) {
            /** @var \Cake\ORM\Table $repository */
            $repository = $this->getRepository();
            $table = $repository->getTable();
        }

        return parent::update($table);
    }
1264318
public function update($table = null)
    {
        $this->type = self::TYPE_UPDATE;
        if ($table) {
            $this->table($table);
        }

        return $this;
    }
843737
public function upgradeSchema(Schema $schema)
    {
        $pp = $schema->getTable('PagePaths');
        if (!$pp->hasColumn('ppGeneratedFromURLSlugs')) {
            $pp->addColumn('ppGeneratedFromURLSlugs', 'boolean', ['notnull' => true, 'unsigned' => true, 'default' => 0]);
        }

        $ms = $schema->getTable('MultilingualSections');
        if (!$ms->hasColumn('msNumPlurals')) {
            $ms->addColumn('msNumPlurals', 'integer', ['notnull' => true, 'unsigned' => true, 'default' => 2]);
            $this->updateSectionPlurals = true;
        }
        if (!$ms->hasColumn('msPluralRule')) {
            $ms->addColumn('msPluralRule', 'string', ['notnull' => true, 'length' => 400, 'default' => '(n != 1)']);
            $this->updateSectionPlurals = true;
        }
        if (!$ms->hasColumn('msPluralCases')) {
            $ms->addColumn('msPluralCases', 'string', ['notnull' => true, 'length' => 1000, 'default' => "one@1\nother@0, 2~16, 100, 1000, 10000, 100000, 1000000, …"]);
            $this->updateSectionPlurals = true;
        }
        $mt = $schema->getTable('MultilingualTranslations');
        if (!$mt->hasColumn('msgidPlural')) {
            $mt->addColumn('msgidPlural', 'text', ['notnull' => false]);
            $this->updateMultilingualTranslations = true;
        }
        if (!$mt->hasColumn('msgstrPlurals')) {
            $mt->addColumn('msgstrPlurals', 'text', ['notnull' => false]);
            $this->updateMultilingualTranslations = true;
        }

        $cms = $schema->getTable('ConversationMessages');
        if (!$cms->hasColumn('cnvMessageAuthorName')) {
            $cms->addColumn('cnvMessageAuthorName', 'string', ['notnull' => false, 'length' => 255]);
        }
        if (!$cms->hasColumn('cnvMessageAuthorEmail')) {
            $cms->addColumn('cnvMessageAuthorEmail', 'string', ['notnull' => false, 'length' => 255]);
        }
        if (!$cms->hasColumn('cnvMessageAuthorWebsite')) {
            $cms->addColumn('cnvMessageAuthorWebsite', 'string', ['notnull' => false, 'length' => 255]);
        }
    }
1061003
public function replace($table, array $updateFields)
    {
        $this->queryTypeProcess(self::QUERYTYPE_REPLACE, $table, $updateFields);
        //$this->fields = $updateFields;
        return $this;
    }
417189
public function setSchema($schema) {
        if(!$this->setModified('schema', $schema)->isModified()) {
            return $this;
        }
		$this->schema = $schema;
		return $this;
    }
539747
public function transAlterIndex($table, $index, $schema)
    {
        $this->transInitTable($table);
        $this->schemaUpdateTransaction[$table]['alteredIndexes'][$index] = $schema;
    }
56312
protected function _addTable(Table $table)
    {
        $namespaceName = $table->getNamespaceName();
        $tableName     = $table->getFullQualifiedName($this->getName());

        if (isset($this->_tables[$tableName])) {
            throw SchemaException::tableAlreadyExists($tableName);
        }

        if ($namespaceName !== null
            && ! $table->isInDefaultNamespace($this->getName())
            && ! $this->hasNamespace($namespaceName)) {
            $this->createNamespace($namespaceName);
        }

        $this->_tables[$tableName] = $table;
        $table->setSchemaConfig($this->_schemaConfig);
    }
34806
public function schemaUpdate($callback)
    {
        // Begin schema update
        $this->schemaIsUpdating = true;

        // Update table list
        $this->tableList = array();
        $tables = $this->tableList();
        foreach ($tables as $table) {
            $this->tableList[strtolower($table)] = $table;
        }

        // Clear update list for client code to mess around with
        $this->schemaUpdateTransaction = array();

        /** @var Exception $error */
        $error = null;
        try {
            // Yield control to client code
            $callback();

            // If the client code has cancelled the update then abort
            if (!$this->isSchemaUpdating()) {
                return;
            }

            // End schema update
            foreach ($this->schemaUpdateTransaction as $tableName => $changes) {
                $advancedOptions = isset($changes['advancedOptions']) ? $changes['advancedOptions'] : null;
                switch ($changes['command']) {
                    case 'create':
                        $this->createTable(
                            $tableName,
                            $changes['newFields'],
                            $changes['newIndexes'],
                            $changes['options'],
                            $advancedOptions
                        );
                        break;

                    case 'alter':
                        $this->alterTable(
                            $tableName,
                            $changes['newFields'],
                            $changes['newIndexes'],
                            $changes['alteredFields'],
                            $changes['alteredIndexes'],
                            $changes['alteredOptions'],
                            $advancedOptions
                        );
                        break;
                }
            }
        } finally {
            $this->schemaUpdateTransaction = null;
            $this->schemaIsUpdating = false;
        }
    }