/** * Generate table oro_reminder * * @param Schema $schema */ public static function oroReminderTable(Schema $schema) { /** Generate table oro_reminder **/ $table = $schema->createTable('oro_reminder'); $table->addColumn('id', 'integer', ['autoincrement' => true]); $table->addColumn('recipient_id', 'integer', ['notnull' => false]); $table->addColumn('subject', 'string', ['length' => 32]); $table->addColumn('start_at', 'datetime', []); $table->addColumn('expire_at', 'datetime', []); $table->addColumn('method', 'string', ['length' => 255]); $table->addColumn('interval_number', 'integer', []); $table->addColumn('interval_unit', 'string', ['length' => 1]); $table->addColumn('state', 'string', ['length' => 32]); $table->addColumn('related_entity_id', 'integer', []); $table->addColumn('related_entity_classname', 'string', ['length' => 255]); $table->addColumn('created_at', 'datetime', []); $table->addColumn('updated_at', 'datetime', ['notnull' => false]); $table->addColumn('sent_at', 'datetime', ['notnull' => false]); $table->addColumn('failure_exception', 'array', ['notnull' => false, 'comment' => '(DC2Type:array)']); $table->setPrimaryKey(['id']); $table->addIndex(['recipient_id'], 'IDX_2F4F9F57E92F8F78', []); $table->addIndex(['state'], 'reminder_state_idx', []); /** End of generate table oro_reminder **/ /** Generate foreign keys for table oro_reminder **/ $table->addForeignKeyConstraint($schema->getTable('oro_user'), ['recipient_id'], ['id'], ['onDelete' => 'CASCADE', 'onUpdate' => null]); /** End of generate foreign keys for table oro_reminder **/ }
/** * @param Schema $schema */ private function createAuditField(Schema $schema) { $oroAuditFieldTable = $schema->createTable('oro_audit_field'); $oroAuditFieldTable->addColumn('id', 'integer', ['autoincrement' => true]); $oroAuditFieldTable->addColumn('audit_id', 'integer', []); $oroAuditFieldTable->addColumn('field', 'string', ['length' => 255]); $oroAuditFieldTable->addColumn('data_type', 'string', ['length' => 255]); $oroAuditFieldTable->addColumn('old_integer', 'bigint', ['notnull' => false]); $oroAuditFieldTable->addColumn('old_float', 'float', ['notnull' => false]); $oroAuditFieldTable->addColumn('old_boolean', 'boolean', ['notnull' => false]); $oroAuditFieldTable->addColumn('old_text', 'text', ['notnull' => false]); $oroAuditFieldTable->addColumn('old_date', 'date', ['notnull' => false]); $oroAuditFieldTable->addColumn('old_time', 'time', ['notnull' => false]); $oroAuditFieldTable->addColumn('old_datetime', 'datetime', ['notnull' => false]); $oroAuditFieldTable->addColumn('new_integer', 'bigint', ['notnull' => false]); $oroAuditFieldTable->addColumn('new_float', 'float', ['notnull' => false]); $oroAuditFieldTable->addColumn('new_boolean', 'boolean', ['notnull' => false]); $oroAuditFieldTable->addColumn('new_text', 'text', ['notnull' => false]); $oroAuditFieldTable->addColumn('new_date', 'date', ['notnull' => false]); $oroAuditFieldTable->addColumn('new_time', 'time', ['notnull' => false]); $oroAuditFieldTable->addColumn('new_datetime', 'datetime', ['notnull' => false]); $oroAuditFieldTable->setPrimaryKey(['id']); $oroAuditFieldTable->addIndex(['audit_id'], 'IDX_9A31A824BD29F359', []); $oroAuditFieldTable->addForeignKeyConstraint($schema->getTable('oro_audit'), ['audit_id'], ['id'], ['onDelete' => 'CASCADE', 'onUpdate' => null]); }
/** * @param Schema $schema * * @throws SkipMigrationException * @throws \Doctrine\DBAL\Schema\SchemaException */ public function preUp(Schema $schema) { $pageHitTable = $schema->getTable($this->prefix . 'users'); if ($pageHitTable->hasColumn('signature')) { throw new SkipMigrationException('Schema includes this migration'); } }
/** * Change oro_integration_channel table * * @param Schema $schema */ public static function modifyChannelTable(Schema $schema) { $table = $schema->getTable('oro_integration_channel'); $table->addColumn('default_user_owner_id', 'integer', ['notnull' => false]); $table->addIndex(['default_user_owner_id'], 'IDX_55B9B9C5A89019EA', []); $table->addForeignKeyConstraint($schema->getTable('oro_user'), ['default_user_owner_id'], ['id'], ['onDelete' => 'SET NULL', 'onUpdate' => null], 'FK_55B9B9C5A89019EA'); }
/** * Add orob2b_shopping_list_line_item foreign keys. * * @param Schema $schema */ protected function addOrob2BShoppingListLineItemForeignKeys(Schema $schema) { $table = $schema->getTable('orob2b_shopping_list_line_item'); $table->addForeignKeyConstraint($schema->getTable('orob2b_shopping_list'), ['shopping_list_id'], ['id'], ['onDelete' => 'CASCADE', 'onUpdate' => null]); $table->addForeignKeyConstraint($schema->getTable('orob2b_product'), ['product_id'], ['id'], ['onDelete' => 'CASCADE', 'onUpdate' => null]); $table->addForeignKeyConstraint($schema->getTable('orob2b_product_unit'), ['unit_code'], ['code'], ['onDelete' => 'CASCADE', 'onUpdate' => null]); }
/** * @param Schema $schema * * @throws \Doctrine\DBAL\Schema\SchemaException */ public static function addAttachmentRelation(Schema $schema) { $table = $schema->getTable('oro_email_attachment'); $table->addColumn('file_id', 'integer', ['notnull' => false]); $table->addUniqueIndex(['file_id'], 'UNIQ_F4427F2393CB796C'); $table->addForeignKeyConstraint($schema->getTable('oro_attachment_file'), ['file_id'], ['id'], ['onDelete' => 'SET NULL'], 'FK_F4427F2393CB796C'); }
/** * {@inheritdoc} */ public function up(Schema $schema, QueryBag $queries) { $table = $schema->getTable('oro_calendar_event'); $table->dropColumn('reminder'); $table->dropColumn('remind_at'); $table->dropColumn('reminded'); }
public function down(Schema $schema) { // remove website creationmode and ismarkedfordeletion column $schema->getTable('website')->dropColumn('share'); $schema->getTable('website')->dropColumn('creationmode'); $schema->getTable('website')->dropColumn('ismarkedfordeletion'); }
/** * @param Schema $schema * @param string $table * @throws \Doctrine\DBAL\Schema\SchemaException */ public static function addToSchema(Schema $schema, $table) { if ($schema->hasTable($table)) { $table = $schema->getTable($table); } else { $table = $schema->createTable($table); } if (!$table->hasColumn('event_id')) { $id = $table->addColumn('event_id', 'integer', ['unsigned' => true]); $id->setAutoincrement(true); $table->setPrimaryKey(['event_id']); } if (!$table->hasColumn('aggregate_id')) { $table->addColumn('aggregate_id', 'string', ['length' => 50]); } if (!$table->hasColumn('version')) { $table->addColumn('version', 'integer'); } if (!$table->hasColumn('type')) { $table->addColumn('type', 'string', ['length' => 100]); } if (!$table->hasColumn('payload')) { $table->addColumn('payload', 'text'); } if (!$table->hasColumn('recorded_on')) { $table->addColumn('recorded_on', 'string', ['length' => 50]); } $table->addUniqueIndex(['aggregate_id', 'version']); }
/** * @param Schema $fromSchema * @param Schema $toSchema * * @return string[] */ public function getSqlDiffToMigrate(Schema $fromSchema, Schema $toSchema) { if ($toSchema instanceof LazyLoadingInterface && !$toSchema->isProxyInitialized()) { return []; } return $this->originalSchemaManipulator->getSqlDiffToMigrate($fromSchema, $toSchema); }
/** * Adds owner_id field * * @param Schema $schema */ public static function addOwner(Schema $schema) { $table = $schema->getTable('oro_embedded_form'); $table->addColumn('owner_id', 'integer', ['notnull' => false]); $table->addIndex(['owner_id'], 'IDX_F7A34C17E3C61F9', []); $table->addForeignKeyConstraint($schema->getTable('oro_organization'), ['owner_id'], ['id'], ['onDelete' => 'SET NULL', 'onUpdate' => null]); }
public function testRunActivityLists() { $connection = $this->getMockBuilder('Doctrine\\DBAL\\Connection')->disableOriginalConstructor()->getMock(); $connection->expects($this->any())->method('getDatabasePlatform')->will($this->returnValue(new MySqlPlatform())); $this->migrationQuery->setConnection($connection); $table = $this->schema->createTable('acme_test'); $table->addColumn('id', 'integer', ['autoincrement' => true]); $table->setPrimaryKey(['id']); $table = $this->schema->createTable('oro_activity_list'); $table->addColumn('id', 'integer', ['autoincrement' => true]); $table->setPrimaryKey(['id']); $extendOptionsManager = new ExtendOptionsManager(); $entityMetadataHelper = $this->getMockBuilder('Oro\\Bundle\\EntityExtendBundle\\Migration\\EntityMetadataHelper')->disableOriginalConstructor()->getMock(); $extendExtension = new ExtendExtension($extendOptionsManager, $entityMetadataHelper); $extendExtension->setNameGenerator($this->nameGenerator); $this->activityListExtension->setExtendExtension($extendExtension); $this->provider->expects($this->once())->method('getTargetEntityClasses')->willReturn(['Acme\\TestBundle\\Entity\\Test']); $this->metadataHelper->expects($this->once())->method('getTableNameByEntityClass')->with('Acme\\TestBundle\\Entity\\Test')->willReturn('acme_test'); $entityMetadataHelper->expects($this->any())->method('getEntityClassByTableName')->willReturnCallback(function ($tableName) { if ($tableName === 'acme_test') { return 'Acme\\TestBundle\\Entity\\Test'; } return 'Oro\\Bundle\\ActivityListBundle\\Entity\\ActivityList'; }); $log = $this->migrationQuery->getDescription(); $this->assertEquals('CREATE TABLE oro_rel_c3990ba6784dd132527c89 (activitylist_id INT NOT NULL, test_id INT NOT NULL, ' . 'INDEX IDX_53682E3596EB1108 (activitylist_id), INDEX IDX_53682E351E5D0459 (test_id), ' . 'PRIMARY KEY(activitylist_id, test_id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ' . 'ENGINE = InnoDB', $log[0]); $this->assertEquals('ALTER TABLE oro_rel_c3990ba6784dd132527c89 ADD CONSTRAINT FK_53682E3596EB1108 ' . 'FOREIGN KEY (activitylist_id) REFERENCES oro_activity_list (id) ON DELETE CASCADE', $log[1]); $this->assertEquals('ALTER TABLE oro_rel_c3990ba6784dd132527c89 ADD CONSTRAINT FK_53682E351E5D0459 FOREIGN KEY (test_id) ' . 'REFERENCES acme_test (id) ON DELETE CASCADE', $log[2]); }
/** * {@inheritdoc} */ public function up(Schema $schema, QueryBag $queries) { $table = $schema->getTable('oro_reminder'); $table->addColumn('sender_id', 'integer', ['notnull' => false]); $table->addIndex(['sender_id'], 'idx_2f4f9f57f624b39d', []); $table->addForeignKeyConstraint($schema->getTable('oro_user'), ['sender_id'], ['id'], ['onUpdate' => null, 'onDelete' => 'SET NULL']); }
/** * Add origin to EmailUser * * @param Schema $schema * @throws \Doctrine\DBAL\Schema\SchemaException */ public static function updateOroEmailUserTable(Schema $schema) { $table = $schema->getTable('oro_email_user'); $table->removeForeignKey('fk_91f5cff6162cb942'); $table->dropIndex('idx_91f5cff6162cb942'); $table->addColumn('origin_id', 'integer', ['notnull' => false]); }
/** * @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())); } }
/** * @param Schema $schema */ protected function modifycOrocrmContactusRequestTable(Schema $schema) { $table = $schema->getTable('orocrm_contactus_request'); $table->addColumn('data_channel_id', 'integer', ['notnull' => false]); $table->addIndex(['data_channel_id'], 'IDX_342872E8BDC09B73', []); $table->addForeignKeyConstraint($schema->getTable('orocrm_channel'), ['data_channel_id'], ['id'], ['onDelete' => 'SET NULL', 'onUpdate' => null], 'FK_342872E8BDC09B73'); }
/** * @param Schema $schema * * @throws SkipMigrationException * @throws \Doctrine\DBAL\Schema\SchemaException */ public function preUp(Schema $schema) { $table = $schema->getTable($this->prefix . 'oauth2_accesstokens'); if ($table->hasIndex(MAUTIC_TABLE_PREFIX . 'oauth2_access_token_search')) { throw new SkipMigrationException('Schema includes this migration'); } }
/** * @param Schema $schema */ public static function addOwnerFields(Schema $schema) { $table = $schema->getTable('test_activity'); $table->addColumn('owner_id', 'integer', ['notnull' => false]); $table->addIndex(['owner_id']); $table->addForeignKeyConstraint($schema->getTable('oro_user'), ['owner_id'], ['id'], ['onDelete' => 'SET NULL', 'onUpdate' => null]); }
/** * {@inheritdoc} */ public function up(Schema $schema, QueryBag $queries) { $table = $schema->getTable('orocrm_magento_customer'); $table->addColumn('rfm_recency', 'integer', ['notnull' => false]); $table->addColumn('rfm_frequency', 'integer', ['notnull' => false]); $table->addColumn('rfm_monetary', 'integer', ['notnull' => false]); }
/** * @param Schema $schema */ public function up(Schema $schema) { $table = $schema->createTable('event_permission_readmodel'); $table->addColumn('event_id', 'guid', array('length' => 36, 'notnull' => true)); $table->addColumn('user_id', 'guid', array('length' => 36, 'notnull' => true)); $table->setPrimaryKey(['event_id', 'user_id']); }
/** * Add oro_activity_owner foreign keys. * * @param Schema $schema */ protected static function addOroActivityOwnerForeignKeys(Schema $schema) { $table = $schema->getTable('oro_activity_owner'); $table->addForeignKeyConstraint($schema->getTable('oro_user'), ['user_id'], ['id'], ['onDelete' => null, 'onUpdate' => null]); $table->addForeignKeyConstraint($schema->getTable('oro_organization'), ['organization_id'], ['id'], ['onDelete' => null, 'onUpdate' => null]); $table->addForeignKeyConstraint($schema->getTable('oro_activity_list'), ['activity_id'], ['id'], ['onDelete' => 'CASCADE', 'onUpdate' => null]); }
/** * @param Schema $schema * * @throws SkipMigrationException * @throws \Doctrine\DBAL\Schema\SchemaException */ public function preUp(Schema $schema) { $table = $schema->getTable($this->prefix . 'stages'); if ($table->hasIndex($this->generatePropertyName('stages', 'idx', ['category_id']))) { throw new SkipMigrationException('Schema includes this migration'); } }
/** * Attributes table was not used in the code anymore so can be removed * * @param Schema $schema */ public function up(Schema $schema) { $prefixedTableName = $this->getTablePrefix() . 'attribute'; if ($schema->hasTable($prefixedTableName)) { $schema->dropTable($prefixedTableName); } }
/** * @return Schema[] */ protected function prepareSchemas() { Type::addType('int', 'Doctrine\\DBAL\\Types\\IntegerType'); $fromSchema = new Schema(); $table = $fromSchema->createTable('oro_entity_extend_test_table'); $table->addColumn('id', 'integer', ['autoincrement' => true]); $table->addColumn('someExternalColumn', 'string'); $table->addColumn('relation_id', 'int'); $table->addIndex(['someExternalColumn'], 'some_external_index_name'); $table->setPrimaryKey(['id']); $tableRelation = $fromSchema->createTable('oro_entity_extend_test_relation'); $tableRelation->addColumn('id', 'integer', ['autoincrement' => true]); $tableRelation->addColumn('someExtendColumn', 'string'); $tableRelation->addIndex(['someExtendColumn'], 'oro_idx_index_name'); $tableRelation->setPrimaryKey(['id']); $table->addForeignKeyConstraint($tableRelation, ['relation_id'], ['id']); $toSchema = new Schema(); $table = $toSchema->createTable('oro_entity_extend_test_table'); $table->addColumn('id', 'integer', ['autoincrement' => true]); $table->setPrimaryKey(['id']); $tableRelation = $toSchema->createTable('oro_entity_extend_test_relation'); $tableRelation->addColumn('id', 'integer', ['autoincrement' => true]); $tableRelation->setPrimaryKey(['id']); return [$fromSchema, $toSchema]; }
/** * @param \Doctrine\DBAL\Schema\Schema $schema * @param \SimpleXMLElement $xml * @throws \DomainException */ private function loadTable($schema, $xml) { $table = null; foreach ($xml->children() as $child) { /** * @var \SimpleXMLElement $child */ switch ($child->getName()) { case 'name': $name = (string) $child; $name = str_replace('*dbprefix*', $this->DBTABLEPREFIX, $name); $name = $this->platform->quoteIdentifier($name); $table = $schema->createTable($name); $table->addOption('collate', 'utf8_bin'); break; case 'create': case 'overwrite': case 'charset': break; case 'declaration': if (is_null($table)) { throw new \DomainException('Table declaration before table name'); } $this->loadDeclaration($table, $child); break; default: throw new \DomainException('Unknown element: ' . $child->getName()); } } }
/** * Generate foreign keys for table oro_email * * @param Schema $schema */ public static function addForeignKeys(Schema $schema) { $table = $schema->getTable('oro_email'); $table->addForeignKeyConstraint($schema->getTable('oro_email_thread'), ['thread_id'], ['id'], ['onDelete' => null, 'onUpdate' => null]); $table = $schema->getTable('oro_email_thread'); $table->addForeignKeyConstraint($schema->getTable('oro_email'), ['last_unseen_email_id'], ['id'], ['onDelete' => null, 'onUpdate' => null]); }
/** * Adds organization_id field * * @param Schema $schema */ public static function addOrganization(Schema $schema) { $table = $schema->getTable('oro_calendar'); $table->addColumn('organization_id', 'integer', ['notnull' => false]); $table->addIndex(['organization_id'], 'IDX_1D1715132C8A3DE', []); $table->addForeignKeyConstraint($schema->getTable('oro_organization'), ['organization_id'], ['id'], ['onDelete' => 'SET NULL', 'onUpdate' => null]); }
public function getMonitoringTable(SchemaBuilder $builder) { $table = $builder->createTable("later_job_monitor"); # setup pk $table->addColumn('monitor_id', 'integer', array("unsigned" => true, 'autoincrement' => true)); $table->setPrimaryKey(array("monitor_id")); # date and hour $table->addColumn('monitor_dte', 'datetime', array()); # add index $table->addUniqueIndex(array('monitor_dte')); # worker stats $table->addColumn('worker_max_time', 'integer', array("unsigned" => true, 'notnull' => false)); $table->addColumn('worker_min_time', 'integer', array("unsigned" => true, 'notnull' => false)); $table->addColumn('worker_mean_time', 'integer', array("unsigned" => true, 'notnull' => false)); $table->addColumn('worker_mean_throughput', 'integer', array("unsigned" => true, 'notnull' => false)); $table->addColumn('worker_max_throughput', 'integer', array("unsigned" => true, 'notnull' => false)); $table->addColumn('worker_mean_utilization', 'float', array("unsigned" => true, 'notnull' => false)); # queue stats $table->addColumn('queue_no_waiting_jobs', 'integer', array("unsigned" => true, 'notnull' => false)); $table->addColumn('queue_no_failed_jobs', 'integer', array("unsigned" => true, 'notnull' => false)); $table->addColumn('queue_no_error_jobs', 'integer', array("unsigned" => true, 'notnull' => false)); $table->addColumn('queue_no_completed_jobs', 'integer', array("unsigned" => true, 'notnull' => false)); $table->addColumn('queue_no_processing_jobs', 'integer', array("unsigned" => true, 'notnull' => false)); $table->addColumn('queue_mean_service_time', 'integer', array("unsigned" => true, 'notnull' => false)); $table->addColumn('queue_min_service_time', 'integer', array("unsigned" => true, 'notnull' => false)); $table->addColumn('queue_max_service_time', 'integer', array("unsigned" => true, 'notnull' => false)); $table->addColumn('monitor_complete', 'boolean', array('default' => false)); }
/** * Add oro_report foreign keys. * * @param Schema $schema */ protected function addOroReportForeignKeys(Schema $schema) { $table = $schema->getTable('oro_report'); $table->addForeignKeyConstraint($schema->getTable('oro_organization'), ['organization_id'], ['id'], ['onUpdate' => null, 'onDelete' => 'SET NULL']); $table->addForeignKeyConstraint($schema->getTable('oro_report_type'), ['type'], ['name'], ['onUpdate' => null, 'onDelete' => null]); $table->addForeignKeyConstraint($schema->getTable('oro_business_unit'), ['business_unit_owner_id'], ['id'], ['onUpdate' => null, 'onDelete' => 'SET NULL']); }
/** * {@inheritdoc} */ public function up(Schema $schema, QueryBag $queries) { if (!$schema->hasTable('oro_process_trigger')) { return; } $queries->addQuery(new ParametrizedSqlMigrationQuery('DELETE FROM oro_process_trigger WHERE definition_name = :name', ['name' => 'convert_mailbox_email_to_case'])); }