/** * @return bool */ public function apply_users_pass() { $migrate = new Tables(); $migrate->useTable('users'); // kill any indexes based on pass column $indexes = $migrate->getTableIndexes('users'); foreach ($indexes as $name => $def) { if (preg_match('/\\b(pass)\\b/', $def['columns'])) { $migrate->dropIndex($name, 'users'); } } $migrate->alterColumn('users', 'pass', "varchar(255) NOT NULL DEFAULT ''"); return $migrate->executeQueue(true); }
/** * Build any DDL required to synchronize an existing table to match the target schema * * @param string $tableName table to synchronize * * @return void */ protected function synchronizeTable($tableName) { foreach ($this->targetDefinitions[$tableName]['columns'] as $column) { $attributes = $this->tableHandler->getColumnAttributes($tableName, $column['name']); if ($attributes === false) { $this->tableHandler->addColumn($tableName, $column['name'], $column['attributes']); } elseif ($column['attributes'] !== $attributes) { $this->tableHandler->alterColumn($tableName, $column['name'], $column['attributes']); } } $tableDef = $this->tableHandler->dumpTables(); if (isset($tableDef[$tableName])) { foreach ($tableDef[$tableName]['columns'] as $columnData) { if (!$this->targetHasColumn($tableName, $columnData['name'])) { $this->tableHandler->dropColumn($tableName, $columnData['name']); } } } $existingIndexes = $this->tableHandler->getTableIndexes($tableName); if (isset($this->targetDefinitions[$tableName]['keys'])) { foreach ($this->targetDefinitions[$tableName]['keys'] as $key => $keyData) { if ($key === 'PRIMARY') { if (!isset($existingIndexes[$key])) { $this->tableHandler->addPrimaryKey($tableName, $keyData['columns']); } elseif ($existingIndexes[$key]['columns'] !== $keyData['columns']) { $this->tableHandler->dropPrimaryKey($tableName); $this->tableHandler->addPrimaryKey($tableName, $keyData['columns']); } } else { if (!isset($existingIndexes[$key])) { $this->tableHandler->addIndex($key, $tableName, $keyData['columns'], $keyData['unique']); } elseif ($existingIndexes[$key]['unique'] !== $keyData['unique'] || $existingIndexes[$key]['columns'] !== $keyData['columns']) { $this->tableHandler->dropIndex($key, $tableName); $this->tableHandler->addIndex($key, $tableName, $keyData['columns'], $keyData['unique']); } } } } if (false !== $existingIndexes) { foreach ($existingIndexes as $key => $keyData) { if (!isset($this->targetDefinitions[$tableName]['keys'][$key])) { $this->tableHandler->dropIndex($key, $tableName); } } } }