/**
  * 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()
 {
     // specify columns and AttributeType
     $locale = array('locale' => ColumnType::Char);
     SproutSeoPlugin::log('Dropping `entryId` index on the sproutseo_overrides table...', LogLevel::Info, true);
     MigrationHelper::dropIndexIfExists('sproutseo_overrides', 'entryId');
     SproutSeoPlugin::log('Done dropping `entryId` index on the sproutseo_overrides table.', LogLevel::Info, true);
     $this->_addColumnsAfter($locale, 'entryId');
     // return true and let craft know its done
     return true;
 }
 /**
  * Any migration code in here is wrapped inside of a transaction.
  *
  * @return bool
  */
 public function safeUp()
 {
     $overridesTable = 'sproutseo_overrides';
     if (!craft()->db->columnExists($overridesTable, 'locale')) {
         $this->addColumnAfter($overridesTable, 'locale', array('column' => ColumnType::Locale, 'required' => true), 'entryId');
         SproutSeoPlugin::log("Created the column `locale` in `{$overridesTable}`.", LogLevel::Info, true);
     } else {
         SproutSeoPlugin::log("Column `locale` already existed in `{$overridesTable}`.", LogLevel::Info, true);
     }
     MigrationHelper::dropIndexIfExists($overridesTable, 'entryId');
     SproutSeoPlugin::log("Index `entryId` dropped from `{$overridesTable}`.", LogLevel::Info, true);
     craft()->db->createCommand()->createIndex($overridesTable, 'entryId, locale', array('entryId', 'locale'), true);
     SproutSeoPlugin::log("Composite index `localeAndEntryId` created on `{$overridesTable}`.", LogLevel::Info, true);
     return true;
 }
 /**
  * Any migration code in here is wrapped inside of a transaction.
  *
  * @return bool
  */
 public function safeUp()
 {
     Craft::log('Making tag titles translatable...', LogLevel::Info, true);
     // Select all of the tag names
     $tags = craft()->db->createCommand()->select('id, name')->from('tags')->queryAll();
     foreach ($tags as $tag) {
         $this->update('content', array('title' => $tag['name']), array('elementId' => $tag['id']));
     }
     $this->createIndex('tags', 'groupId');
     MigrationHelper::dropIndexIfExists('tags', array('name', 'groupId'), true);
     MigrationHelper::dropIndexIfExists('tags', array('groupId', 'name'), true);
     $this->dropColumn('tags', 'name');
     Craft::log('Done making tag titles translatable.', LogLevel::Info, true);
     return true;
 }
 public function safeUp()
 {
     MigrationHelper::dropForeignKeyIfExists('market_orders', ['typeId']);
     MigrationHelper::dropIndexIfExists('market_orders', ['typeId']);
     $this->dropColumn('market_orders', 'typeId');
     // find everything that is not 'order'
     $ids = craft()->db->createCommand()->select('id')->from('market_ordertypes')->where("handle != 'order'")->queryColumn();
     // delete 'em
     $this->delete('market_ordertypes', array('in', 'id', $ids));
     $table = MigrationHelper::getTable('market_ordertypes');
     MigrationHelper::dropAllForeignKeysOnTable($table);
     $this->renameTable('market_ordertypes', 'market_ordersettings');
     $this->addForeignKey('market_ordersettings', 'fieldLayoutId', 'fieldlayouts', 'id', 'SET NULL');
     $orderSettings = craft()->db->createCommand()->select('*')->from('market_ordersettings')->where("handle = 'order'")->queryScalar();
     if (!$orderSettings) {
         craft()->db->createCommand()->insert('market_ordersettings', ['name' => 'Order', 'handle' => 'order', 'fieldLayoutId' => null]);
     }
     return true;
 }
 public function safeup()
 {
     // The Table you wish to add. 'craft_' prefix will be added automatically.
     $oldTableName = 'sproutseo_templates';
     $newTableName = 'sproutseo_defaults';
     if (!craft()->db->tableExists($newTableName)) {
         SproutSeoPlugin::log("New table `{$newTableName}` doesn't exist.", LogLevel::Info, true);
         if (craft()->db->tableExists($oldTableName)) {
             MigrationHelper::dropIndexIfExists('sproutseo_templates', array('name', 'handle'), true);
             SproutSeoPlugin::log("Old table `{$oldTableName}` does exist.", LogLevel::Info, true);
             SproutSeoPlugin::log("Renaming the `{$oldTableName}` table.", LogLevel::Info, true);
             // Rename table
             $this->renameTable($oldTableName, $newTableName);
             $this->createIndex('sproutseo_defaults', 'name,handle', true);
             SproutSeoPlugin::log("`{$oldTableName}` table has been renamed to `{$newTableName}`.", LogLevel::Info, true);
         }
     }
     return true;
 }