public function testBag() { $queries = new QueryBag(); $queries->addPreQuery('query1'); $queries->addPreQuery('query2'); $queries->addPostQuery('query3'); $queries->addQuery('query4'); $this->assertEquals(['query1', 'query2'], $queries->getPreQueries()); $this->assertEquals(['query3', 'query4'], $queries->getPostQueries()); $queries->clear(); $this->assertCount(0, $queries->getPreQueries()); $this->assertCount(0, $queries->getPostQueries()); }
/** * {@inheritdoc} */ public function up(Schema $schema, QueryBag $queries) { /** Update Email Origin Name */ $queries->addPreQuery(new ParametrizedSqlMigrationQuery('UPDATE oro_email_origin SET name = :new_name WHERE name = :old_name', ['new_name' => 'useremailorigin', 'old_name' => 'imapemailorigin'], ['new_name' => Type::STRING, 'old_name' => Type::STRING])); /** Tables generation **/ self::addSmtpFieldsToOroEmailOriginTable($schema); }
/** * {@inheritdoc} */ public function up(Schema $schema, QueryBag $queries) { $queries->addPreQuery(new ParametrizedSqlMigrationQuery('UPDATE orocrm_call SET created_at = :date, updated_at = :date', ['date' => new \DateTime('now', new \DateTimeZone('UTC'))], ['date' => Type::DATETIME])); $table = $schema->getTable('orocrm_call'); $table->getColumn('created_at')->setOptions(['notnull' => true]); $table->getColumn('updated_at')->setOptions(['notnull' => true]); }
/** * @param Schema $schema * @param QueryBag $queries * @param string $tableName * @param string $columnName * @param string $type * * @throws \Exception */ public function changePrimaryKeyType(Schema $schema, QueryBag $queries, $tableName, $columnName, $type) { $targetColumn = $schema->getTable($tableName)->getColumn($columnName); $type = Type::getType($type); if ($targetColumn->getType() === $type) { return; } /** @var ForeignKeyConstraint[] $foreignKeys */ $foreignKeys = []; foreach ($schema->getTables() as $table) { /** @var ForeignKeyConstraint[] $tableForeignKeys */ $tableForeignKeys = array_filter($table->getForeignKeys(), function (ForeignKeyConstraint $tableForeignKey) use($tableName, $columnName) { if ($tableForeignKey->getForeignTableName() !== $tableName) { return false; } return $tableForeignKey->getForeignColumns() === [$columnName]; }); foreach ($tableForeignKeys as $tableForeignKey) { $foreignKeys[$tableForeignKey->getName()] = $tableForeignKey; $foreignKeyTableName = $tableForeignKey->getLocalTable()->getName(); $foreignKeyColumnNames = $tableForeignKey->getLocalColumns(); $queries->addPreQuery($this->platform->getDropForeignKeySQL($tableForeignKey, $foreignKeyTableName)); $column = $schema->getTable($foreignKeyTableName)->getColumn(reset($foreignKeyColumnNames)); if ($column instanceof ExtendColumn) { $column->disableExtendOptions()->setType($type)->enableExtendOptions(); } else { $column->setType($type); } } } $targetColumn->setType($type); foreach ($foreignKeys as $foreignKey) { $queries->addPostQuery($this->platform->getCreateForeignKeySQL($foreignKey, $foreignKey->getLocalTable())); } }
/** * {@inheritdoc} */ public function up(Schema $schema, QueryBag $queries) { // fill createdAt and updatedAt $queries->addPreQuery(new ParametrizedSqlMigrationQuery('UPDATE oro_calendar_event SET created_at = :date, updated_at = :date', ['date' => new \DateTime('now', new \DateTimeZone('UTC'))], ['date' => Type::DATETIME])); // copy title to description if needed $queries->addPreQuery(new ParametrizedSqlMigrationQuery(sprintf('UPDATE oro_calendar_event SET description = title WHERE %s > 255 OR title LIKE :new_line', $this->platform->getLengthExpression('title')), ['new_line' => '%\\n%'], ['new_line' => Type::STRING])); // trim title $locateExpr = $this->platform->getLocateExpression('title', ':lf'); $queries->addPreQuery(new ParametrizedSqlMigrationQuery(sprintf('UPDATE oro_calendar_event SET title = %s WHERE %s > 0', $this->platform->getSubstringExpression(sprintf('REPLACE(%s, :cr, :empty)', $this->platform->getSubstringExpression('title', 1, $locateExpr)), 1, 255), $locateExpr), ['lf' => '\\n', 'cr' => '\\r', 'empty' => ''], ['lf' => Type::STRING, 'cr' => Type::STRING, 'empty' => Type::STRING])); $queries->addPreQuery(sprintf('UPDATE oro_calendar_event SET title = %s WHERE %s > 255', $this->platform->getSubstringExpression('title', 1, 255), $this->platform->getLengthExpression('title'))); $table = $schema->getTable('oro_calendar_event'); $table->getColumn('title')->setType(Type::getType(Type::STRING))->setOptions(['length' => 255]); $table->getColumn('created_at')->setOptions(['notnull' => true]); $table->getColumn('updated_at')->setOptions(['notnull' => true]); $this->enableDataAudit($table); }
/** * {@inheritdoc} */ public function up(Schema $schema, QueryBag $queries) { // fill empty updatedAt of orocrm_case_comment $queries->addPreQuery('UPDATE orocrm_case_comment SET updatedAt = createdAt WHERE updatedAt IS NULL'); // make updatedAt NOT NULL $table = $schema->getTable('orocrm_case_comment'); $table->changeColumn('updatedAt', ['notnull' => true]); }
/** * {@inheritdoc} */ public function up(Schema $schema, QueryBag $queries) { // copy user's IMAP email origins to new table $queries->addPreQuery('INSERT INTO oro_user_email_origin (user_id, origin_id) ' . 'SELECT id, imap_configuration_id FROM oro_user WHERE imap_configuration_id IS NOT NULL'); // drop old FK for IMAP email origins $table = $schema->getTable('oro_user'); $table->dropIndex('UNIQ_F82840BC678BF607'); $table->removeForeignKey('FK_F82840BC678BF607'); $table->dropColumn('imap_configuration_id'); }
/** * @inheritdoc */ public function up(Schema $schema, QueryBag $queries) { $queries->addPreQuery($this->getRemoveObsoleteValuesSql()); $table = $schema->getTable('oro_entity_config_value'); $table->dropColumn('serializable'); $table->getColumn('value')->setType(Type::getType(Type::STRING)); $table->addIndex(['scope', 'code', 'value', 'entity_id'], 'idx_entity_config_index_entity'); $table->addIndex(['scope', 'code', 'value', 'field_id'], 'idx_entity_config_index_field'); $this->renameExtension->renameTable($schema, $queries, 'oro_entity_config_value', 'oro_entity_config_index_value'); }
/** * {@inheritdoc} */ public function up(Schema $schema, QueryBag $queries) { // Copy values from VAT to temp auxiliary column with correction $query = 'UPDATE orocrm_magento_customer ' . 'SET vat_temp = ROUND(vat * 100.0) ' . 'WHERE vat IS NOT NULL'; $queries->addPreQuery($query); // Change data type of the VAT column $schema->getTable('orocrm_magento_customer')->getColumn('vat')->setType(Type::getType(Type::STRING)); // Copy values back to VAT column $query = 'UPDATE orocrm_magento_customer ' . 'SET vat = vat_temp ' . 'WHERE vat IS NOT NULL'; $queries->addPostQuery($query); }
/** * @inheritdoc */ public function up(Schema $schema, QueryBag $queries) { $table = $schema->getTable('oro_windows_state'); $column = $table->getColumn('data'); if ($this->platform instanceof PostgreSqlPlatform) { $queries->addPreQuery('ALTER TABLE oro_windows_state ALTER COLUMN data TYPE JSON USING data::JSON'); } else { $column->setType(Type::getType(Type::JSON_ARRAY)); } $column->setOptions(['comment' => '(DC2Type:json_array)']); }
/** * {@inheritdoc} */ public function up(Schema $schema, QueryBag $queries) { $queries->addPreQuery($this->getFillUserActivityQuery()); $queries->addPreQuery($this->getFillAccountActivityQuery()); $queries->addPreQuery($this->getFillContactActivityQuery()); $queries->addPreQuery($this->getFillPhoneQuery()); $callTable = $schema->getTable('orocrm_call'); // relation with account $callTable->removeForeignKey('FK_1FBD1A2411A6570A'); $callTable->dropColumn('related_account_id'); $queries->addPostQuery($this->getDropEntityConfigManyToOneRelationQuery('relatedAccount')); // relation with contact $callTable->removeForeignKey('FK_1FBD1A246D6C2DFA'); $callTable->dropColumn('related_contact_id'); $queries->addPostQuery($this->getDropEntityConfigManyToOneRelationQuery('relatedContact')); // relation with contact phone $callTable->removeForeignKey('FK_1FBD1A24A156BF5C'); $callTable->dropColumn('contact_phone_id'); $queries->addPostQuery($this->getDropEntityConfigManyToOneRelationQuery('contactPhoneNumber')); }
/** * {@inheritdoc} */ public function up(Schema $schema, QueryBag $queries) { // update data in accordance with new column requirement $queries->addPreQuery(sprintf("UPDATE oro_email SET message_id = CONCAT('id.', REPLACE(%s, '-',''), '%s') WHERE message_id IS NULL", $this->platform->getGuidExpression(), '@bap.migration.generated')); self::oroEmailToFolderRelationTable($schema); // make message_id not null & add index $table = $schema->getTable('oro_email'); $table->changeColumn('message_id', ['notnull' => true]); $table->addIndex(['message_id'], 'IDX_email_message_id', []); // migrate existing email-folder relations $queries->addPostQuery("INSERT INTO oro_email_to_folder (email_id, emailfolder_id) SELECT id, folder_id FROM oro_email"); }
/** * {@inheritdoc} */ public function up(Schema $schema, QueryBag $queries) { $queries->addPreQuery($this->getFillAccountActivityQuery()); $queries->addPreQuery($this->getFillContactActivityQuery()); // fill empty updatedAt of orocrm_task $queries->addPreQuery('UPDATE orocrm_task SET updatedAt = createdAt WHERE updatedAt IS NULL'); $taskTable = $schema->getTable('orocrm_task'); $this->enableDataAudit($taskTable); // relation with account $taskTable->removeForeignKey('FK_814DEE3F11A6570A'); $taskTable->dropColumn('related_account_id'); $queries->addPostQuery($this->getDropEntityConfigManyToOneRelationQuery('relatedAccount')); // relation with contact $taskTable->removeForeignKey('FK_814DEE3F6D6C2DFA'); $taskTable->dropColumn('related_contact_id'); $queries->addPostQuery($this->getDropEntityConfigManyToOneRelationQuery('relatedContact')); // reporter $taskTable->removeForeignKey('fk_orocrm_task_reporter_id'); $taskTable->dropColumn('reporter_id'); $queries->addPostQuery($this->getDropEntityConfigManyToOneRelationQuery('reporter')); // make updatedAt NOT NULL $taskTable->getColumn('updatedAt')->setOptions(['notnull' => true]); }
/** * {@inheritdoc} */ public function up(Schema $schema, QueryBag $queries) { $queries->addPreQuery(new UpdateEmailUserQuery()); }
/** * {@inheritdoc} */ public function up(Schema $schema, QueryBag $queries) { if ($this->container->hasParameter('installed') && $this->container->getParameter('installed')) { $queries->addPreQuery(new UpdateActivityButtonConfigQuery()); } }
/** * @param QueryBag $queries */ protected function fillActivityListTables(QueryBag $queries) { // Fill activitylists tables $queries->addPreQuery(new ParametrizedSqlMigrationQuery($this->getFillCartEmailActivityListQuery(), ['class' => 'Oro\\Bundle\\EmailBundle\\Entity\\Email'], ['class' => Type::STRING])); $queries->addPreQuery(new ParametrizedSqlMigrationQuery($this->getFillCartCallActivityListQuery(), ['class' => 'OroCRM\\Bundle\\CallBundle\\Entity\\Call'], ['class' => Type::STRING])); $queries->addPreQuery(new ParametrizedSqlMigrationQuery($this->getFillOrderEmailActivityListQuery(), ['class' => 'Oro\\Bundle\\EmailBundle\\Entity\\Email'], ['class' => Type::STRING])); $queries->addPreQuery(new ParametrizedSqlMigrationQuery($this->getFillOrderCallActivityListQuery(), ['class' => 'OroCRM\\Bundle\\CallBundle\\Entity\\Call'], ['class' => Type::STRING])); }
/** * {@inheritdoc} */ public function up(Schema $schema, QueryBag $queries) { $queries->addPreQuery(new ParametrizedSqlMigrationQuery('UPDATE oro_audit SET type = :type', ['type' => 'audit'], ['type' => Type::STRING])); }
/** * @inheritdoc */ public function up(Schema $schema, QueryBag $queries) { $queries->addPreQuery("UPDATE oro_email_origin SET imap_ssl='tls' WHERE imap_ssl='tsl';"); }
/** * {@inheritDoc} */ public function up(Schema $schema, QueryBag $queries) { $queries->addPreQuery(new UpdateEmailOriginTableQuery()); $queries->addPostQuery(new FillEmailUserTableQuery()); self::addOwnerToOroEmail($schema); }