/** * Any migration code in here is wrapped inside of a transaction. * * @return bool */ public function safeUp() { if (!craft()->db->columnExists('elements_i18n', 'slug')) { Craft::log('Creating an elements_i18n.slug column.', LogLevel::Info, true); $this->addColumnAfter('elements_i18n', 'slug', ColumnType::Varchar, 'locale'); } if (craft()->db->tableExists('entries_i18n')) { Craft::log('Copying the slugs from entries_i18n into elements_i18n.', LogLevel::Info, true); $rows = craft()->db->createCommand()->select('entryId, locale, slug')->from('entries_i18n')->queryAll(); foreach ($rows as $row) { $this->update('elements_i18n', array('slug' => $row['slug']), array('elementId' => $row['entryId'], 'locale' => $row['locale'])); } Craft::log('Dropping the entries_i18n table.'); $this->dropTable('entries_i18n'); } if (!craft()->db->columnExists('elements_i18n', 'enabled')) { Craft::log('Creating an elements_i18n.enabled column.', LogLevel::Info, true); $this->addColumnAfter('elements_i18n', 'enabled', array('column' => ColumnType::Bool, 'default' => true), 'uri'); } MigrationHelper::refresh(); MigrationHelper::dropIndexIfExists('elements_i18n', array('slug', 'locale')); MigrationHelper::dropIndexIfExists('elements_i18n', array('enabled')); $this->createIndex('elements_i18n', 'slug,locale'); $this->createIndex('elements_i18n', 'enabled'); return true; }
/** * Any migration code in here is wrapped inside of a transaction. * * @return bool */ public function safeUp() { MigrationHelper::refresh(); Craft::log('Dropping FK if it exists.', LogLevel::Info, true); MigrationHelper::dropForeignKeyIfExists('emailmessages', array('locale')); Craft::log('Adding FK to emailmessages table.', LogLevel::Info, true); $this->addForeignKey('emailmessages', 'locale', 'locales', 'locale', 'CASCADE', 'CASCADE'); return true; }
/** * Any migration code in here is wrapped inside of a transaction. * * @return bool */ public function safeUp() { MigrationHelper::refresh(); $addFkBack = false; if (craft()->db->tableExists('tagsets')) { // A couple people have had failed updates that resulted in tagsets *and* taggroups tables lying around // causing a MySQL error if trying to rename the tagsets table // so let's make sure it's gone first. if (craft()->db->tableExists('taggroups')) { MigrationHelper::dropForeignKeyIfExists('taggroups', array('fieldLayoutId')); if (craft()->db->columnExists('tags', 'groupId')) { MigrationHelper::dropForeignKeyIfExists('tags', array('groupId')); MigrationHelper::renameColumn('tags', 'groupId', 'setId'); $addFkBack = true; } $this->dropTable('taggroups'); // ...and refresh the schema cache craft()->db->getSchema()->refresh(); } Craft::log('Renaming the tagsets table to taggroups.', LogLevel::Info, true); MigrationHelper::renameTable('tagsets', 'taggroups'); } if (craft()->db->columnExists('tags', 'setId')) { Craft::log('Renaming the tags.setId column to groupId.', LogLevel::Info, true); MigrationHelper::renameColumn('tags', 'setId', 'groupId'); } if ($addFkBack) { $this->addForeignKey('tags', 'groupId', 'taggroups', 'id', null, 'CASCADE'); } Craft::log('Updating the Tags fields\' settings.', LogLevel::Info, true); $fields = craft()->db->createCommand()->select('id, settings')->from('fields')->where('type="Tags"')->queryAll(); foreach ($fields as $field) { $settings = JsonHelper::decode($field['settings']); if (isset($settings['source']) && strncmp($settings['source'], 'tagset:', 7) === 0) { $settings['source'] = 'taggroup:' . substr($settings['source'], 7); $this->update('fields', array('settings' => JsonHelper::encode($settings)), array('id' => $field['id'])); } } return true; }