/** * Any migration code in here is wrapped inside of a transaction. * * @return bool */ public function safeUp() { if (!craft()->db->tableExists('searchindex')) { // Taking the scenic route here so we can get to MysqlSchema's $engine argument $table = DbHelper::addTablePrefix('searchindex'); $columns = array('elementId' => DbHelper::generateColumnDefinition(array('column' => ColumnType::Int, 'null' => false)), 'attribute' => DbHelper::generateColumnDefinition(array('column' => ColumnType::Varchar, 'maxLength' => 25, 'null' => false)), 'fieldId' => DbHelper::generateColumnDefinition(array('column' => ColumnType::Int, 'null' => false)), 'locale' => DbHelper::generateColumnDefinition(array('column' => ColumnType::Locale, 'null' => false)), 'keywords' => DbHelper::generateColumnDefinition(array('column' => ColumnType::Text, 'null' => false))); $this->execute(craft()->db->getSchema()->createTable($table, $columns, null, 'MyISAM')); // Give it a composite primary key $this->addPrimaryKey('searchindex', 'elementId,attribute,fieldId,locale'); // Add the FULLTEXT index on `keywords` $this->execute('CREATE FULLTEXT INDEX ' . craft()->db->quoteTableName(DbHelper::getIndexName('searchindex', 'keywords')) . ' ON ' . craft()->db->quoteTableName($table) . ' ' . '(' . craft()->db->quoteColumnName('keywords') . ')'); Craft::log('Successfully added the `searchindex` table with a fulltext index on `keywords`.', LogLevel::Info, true); } else { Craft::log('Tried to add the `searchindex` table, but it already exists.', LogLevel::Warning, true); } return true; }
/** * @param $table * @param $column * @param $type * @param null $newName * @param null $after * * @return int */ public function alterColumn($table, $column, $type, $newName = null, $after = null) { $table = $this->getConnection()->addTablePrefix($table); $type = DbHelper::generateColumnDefinition($type); return $this->setText($this->getConnection()->getSchema()->alterColumn($table, $column, $type, $newName, $after))->execute(); }
/** * Creates the searchindex table. * * @return null */ private function _createSearchIndexTable() { Craft::log('Creating the searchindex table.'); // Taking the scenic route here so we can get to MysqlSchema's $engine argument $table = craft()->db->addTablePrefix('searchindex'); $columns = array('elementId' => DbHelper::generateColumnDefinition(array('column' => ColumnType::Int, 'null' => false)), 'attribute' => DbHelper::generateColumnDefinition(array('column' => ColumnType::Varchar, 'maxLength' => 25, 'null' => false)), 'fieldId' => DbHelper::generateColumnDefinition(array('column' => ColumnType::Int, 'null' => false)), 'locale' => DbHelper::generateColumnDefinition(array('column' => ColumnType::Locale, 'null' => false)), 'keywords' => DbHelper::generateColumnDefinition(array('column' => ColumnType::Text, 'null' => false))); craft()->db->createCommand()->setText(craft()->db->getSchema()->createTable($table, $columns, null, 'MyISAM'))->execute(); // Give it a composite primary key craft()->db->createCommand()->addPrimaryKey('searchindex', 'elementId,attribute,fieldId,locale'); // Add the FULLTEXT index on `keywords` craft()->db->createCommand()->setText('CREATE FULLTEXT INDEX ' . craft()->db->quoteTableName(craft()->db->getIndexName('searchindex', 'keywords')) . ' ON ' . craft()->db->quoteTableName($table) . ' ' . '(' . craft()->db->quoteColumnName('keywords') . ')')->execute(); Craft::log('Finished creating the searchindex table.'); }