private function createTable(string $tableName) : Table { $table = new Table($tableName); $table->addColumn('aggregate_id', 'guid', ['notnull' => true]); $table->addColumn('occurred_on', 'datetime', ['notnull' => true]); $table->addColumn('name', 'string', ['notnull' => true]); $table->addColumn('event_class', 'string', ['notnull' => true]); $table->addColumn('event', 'text'); $table->addIndex(['aggregate_id']); $table->addIndex(['occurred_on']); return $table; }
public function makeTableRepresentation(DBAL\Schema\Table $table) { $table->addColumn('id', 'string', ['length' => 100]); $table->addColumn('raw', 'string', ['length' => $this->length]); $table->addColumn('scheme', 'string', ['length' => 30]); $table->addColumn('domain', 'string', ['length' => 50]); $table->addColumn('port', 'integer', ['length' => 10]); $table->addColumn('path', 'string', ['length' => 200]); $table->addColumn('fragment', 'string', ['length' => 100]); $table->addColumn('last_indexed', 'integer', ['length' => 50]); $table->addIndex(['id', 'raw']); $table->addIndex(['id', 'domain']); }
/** * Adds a fulltext index to the table * * @param array $fields fields * @param string $name index name * @return $this */ public function fulltext($fields, $name) { $this->table->addIndex((array) $fields, $name); $index = $this->table->getIndex($name); $index->addFlag('fulltext'); return $this; }
public function makeTableRepresentation(DBAL\Schema\Table $table) { $table->addColumn('id', 'string', ['length' => 100]); $table->addColumn('content', 'string', ['length' => $this->length]); $table->addColumn('last_indexed', 'integer', ['length' => 50]); $table->addIndex(['id', 'content']); }
/** * @param string $schema * @param Table $table * @param string $name * @param FieldDefinition $definition */ public function map(string $schema, Table $table, string $name, FieldDefinition $definition) { $table->addColumn($name, 'float', ['notnull' => !$definition->isNullable(), 'default' => $definition->defaultValue(), 'unique' => $definition->options()['unique'] ?? false]); if ($definition->options()['index'] ?? false) { $table->addIndex([$name]); } }
public function makeTableRepresentation(DBAL\Schema\Table $table) { $table->addColumn('id', 'string', ['length' => 100]); $table->addColumn('datetime', 'datetime'); $table->addColumn('last_indexed', 'integer', ['length' => 50]); $table->addIndex(['id', 'datetime']); }
/** * @param Table $localTable * @param ForeignKeyConstraint $fkConstraint */ public function acceptForeignKey(Table $localTable, ForeignKeyConstraint $fkConstraint) { if ($this->_addExplicitIndexForForeignKey) { $columns = $fkConstraint->getColumns(); if ($localTable->columnsAreIndexed($columns)) { return; } $localTable->addIndex($columns); } }
/** * Adds the missing indexes to the table * * @param \Doctrine\DBAL\Schema\Table $table Table object * @return \Doctrine\DBAL\Schema\Table Updated table object */ protected function addIndexes(\Doctrine\DBAL\Schema\Table $table) { $indexes = array('idx_msord_sid_cdate' => array('siteid', 'cdate'), 'idx_msord_sid_cmonth' => array('siteid', 'cmonth'), 'idx_msord_sid_cweek' => array('siteid', 'cweek'), 'idx_msord_sid_hour' => array('siteid', 'chour')); foreach ($indexes as $name => $def) { if ($table->hasIndex($name) === false) { $table->addIndex($def, $name); } } return $table; }
/** * Adds the missing indexes to the table * * @param \Doctrine\DBAL\Schema\Table $table Table object * @return \Doctrine\DBAL\Schema\Table Updated table object */ protected function addIndexes(\Doctrine\DBAL\Schema\Table $table) { $indexes = array('idx_ezpus_langid' => array('langid'), 'idx_ezpus_status_ln_fn' => array('status', 'lastname', 'firstname'), 'idx_ezpus_status_ad1_ad2' => array('status', 'address1', 'address2'), 'idx_ezpus_status_postal_city' => array('status', 'postal', 'city'), 'idx_ezpus_lastname' => array('lastname'), 'idx_ezpus_address1' => array('address1'), 'idx_ezpus_postal' => array('postal'), 'idx_ezpus_city' => array('city')); foreach ($indexes as $name => $def) { if ($table->hasIndex($name) === false) { $table->addIndex($def, $name); } } return $table; }
public function testEncodedIndexNameIsTheSameAsDoctrineDefault() { $tableName = 'tbl123456789012345'; $columnName = 'clmn1234567890'; $table = new Table($tableName, [new Column($columnName, Type::getType('string'))]); $table->addIndex([$columnName]); $indices = $table->getIndexes(); $doctrineResult = array_pop($indices)->getName(); $generator = new DbIdentifierNameGenerator(); $result = $generator->generateIndexName($tableName, [$columnName]); $this->assertEquals($doctrineResult, $result); }
/** * @group DBAL-400 */ public function testAlterTableAddPrimaryKey() { $table = new Table('alter_table_add_pk'); $table->addColumn('id', 'integer'); $table->addColumn('foo', 'integer'); $table->addIndex(array('id'), 'idx_id'); $this->_sm->createTable($table); $comparator = new Comparator(); $diffTable = clone $table; $diffTable->dropIndex('idx_id'); $diffTable->setPrimaryKey(array('id')); $this->_sm->alterTable($comparator->diffTable($table, $diffTable)); $table = $this->_sm->listTableDetails("alter_table_add_pk"); $this->assertFalse($table->hasIndex('idx_id')); $this->assertTrue($table->hasPrimaryKey()); }
/** * @param \TYPO3\CMS\Core\Database\Schema\Parser\AST\CreateColumnDefinitionItem $item * @return \Doctrine\DBAL\Schema\Column * @throws \Doctrine\DBAL\Schema\SchemaException * @throws \RuntimeException */ protected function addColumn(CreateColumnDefinitionItem $item) : Column { $column = $this->table->addColumn($item->columnName->getQuotedName(), $this->getDoctrineColumnTypeName($item->dataType)); $column->setNotnull(!$item->allowNull); $column->setAutoincrement((bool) $item->autoIncrement); $column->setComment($item->comment); // Set default value (unless it's an auto increment column) if ($item->hasDefaultValue && !$column->getAutoincrement()) { $column->setDefault($item->defaultValue); } if ($item->dataType->getLength()) { $column->setLength($item->dataType->getLength()); } if ($item->dataType->getPrecision() >= 0) { $column->setPrecision($item->dataType->getPrecision()); } if ($item->dataType->getScale() >= 0) { $column->setScale($item->dataType->getScale()); } if ($item->dataType->isUnsigned()) { $column->setUnsigned(true); } // Select CHAR/VARCHAR or BINARY/VARBINARY if ($item->dataType->isFixed()) { $column->setFixed(true); } if ($item->dataType instanceof DataType\EnumDataType || $item->dataType instanceof DataType\SetDataType) { $column->setPlatformOption('unquotedValues', $item->dataType->getValues()); } if ($item->index) { $this->table->addIndex([$item->columnName->getQuotedName()]); } if ($item->unique) { $this->table->addUniqueIndex([$item->columnName->getQuotedName()]); } if ($item->primary) { $this->table->setPrimaryKey([$item->columnName->getQuotedName()]); } if ($item->reference !== null) { $this->addForeignKeyConstraint([$item->columnName->getQuotedName()], $item->reference); } return $column; }
public function initialize(array $options = []) { $tableName = $this->options[self::OPTION_TABLENAME]; if (!method_exists($this->connection, 'getSchemaManager')) { throw new \RuntimeException('The provided connection does not support query building, please choose a different connection type ' . 'that does'); } if ($this->connection->getSchemaManager()->tablesExist([$tableName])) { return; } $table = new Table($tableName); $table->addColumn('id', Type::STRING, ['length' => '36']); $table->addColumn('stream_id', Type::STRING, ['length' => '36']); $table->addColumn('sequence', Type::BIGINT); $table->addColumn('payload', Type::TEXT); $table->addColumn('emitted_at', Type::DATETIME); $table->setPrimaryKey(['id']); $table->addIndex(['stream_id']); $table->addUniqueIndex(['stream_id', 'sequence']); $this->connection->getSchemaManager()->createTable($table); }
/** * @group DBAL-224 */ public function testDropIndex() { $table = new Table("test"); $table->addColumn('id', 'integer'); $table->addIndex(array('id'), 'idx'); $this->assertTrue($table->hasIndex('idx')); $table->dropIndex('idx'); $this->assertFalse($table->hasIndex('idx')); }
/** * @param string $columnName * @param array $options * @param string $className * @param Table $table */ protected function buildIndex($columnName, $options, $className, $table) { $columnType = $this->fieldTypeHelper->getUnderlyingType($options[ExtendOptionsManager::TYPE_OPTION]); if ($this->fieldTypeHelper->isRelation($columnType) || in_array($columnType, [Type::TEXT])) { return; } $indexName = $this->nameGenerator->generateIndexNameForExtendFieldVisibleInGrid($className, $columnName); if ($this->isEnabled($options) && $this->isExtended($options) && !$table->hasIndex($indexName)) { $table->addIndex([$columnName], $indexName); } elseif (!$this->isEnabled($options) && $table->hasIndex($indexName)) { $table->dropIndex($indexName); } }
/** * @group DBAL-400 */ public function testAlterTableAddPrimaryKey() { $table = new Table('alter_table_add_pk'); $table->addColumn('id', 'integer'); $table->addColumn('foo', 'integer'); $table->addIndex(array('id'), 'idx_id'); $comparator = new Comparator(); $diffTable = clone $table; $diffTable->dropIndex('idx_id'); $diffTable->setPrimaryKey(array('id')); $this->assertEquals(array('DROP INDEX idx_id ON alter_table_add_pk', 'ALTER TABLE alter_table_add_pk ADD PRIMARY KEY (id)'), $this->_platform->getAlterTableSQL($comparator->diffTable($table, $diffTable))); }
/** * @group DBAL-831 */ public function testListTableDetailsWithDifferentIdentifierQuotingRequirements() { $primaryTableName = '"Primary_Table"'; $offlinePrimaryTable = new Schema\Table($primaryTableName); $offlinePrimaryTable->addColumn('"Id"', 'integer', array('autoincrement' => true, 'comment' => 'Explicit casing.')); $offlinePrimaryTable->addColumn('select', 'integer', array('comment' => 'Reserved keyword.')); $offlinePrimaryTable->addColumn('foo', 'integer', array('comment' => 'Implicit uppercasing.')); $offlinePrimaryTable->addColumn('BAR', 'integer'); $offlinePrimaryTable->addColumn('"BAZ"', 'integer'); $offlinePrimaryTable->addIndex(array('select'), 'from'); $offlinePrimaryTable->addIndex(array('foo'), 'foo_index'); $offlinePrimaryTable->addIndex(array('BAR'), 'BAR_INDEX'); $offlinePrimaryTable->addIndex(array('"BAZ"'), 'BAZ_INDEX'); $offlinePrimaryTable->setPrimaryKey(array('"Id"')); $foreignTableName = 'foreign'; $offlineForeignTable = new Schema\Table($foreignTableName); $offlineForeignTable->addColumn('id', 'integer', array('autoincrement' => true)); $offlineForeignTable->addColumn('"Fk"', 'integer'); $offlineForeignTable->addIndex(array('"Fk"'), '"Fk_index"'); $offlineForeignTable->addForeignKeyConstraint($primaryTableName, array('"Fk"'), array('"Id"'), array(), '"Primary_Table_Fk"'); $offlineForeignTable->setPrimaryKey(array('id')); $this->_sm->tryMethod('dropTable', $foreignTableName); $this->_sm->tryMethod('dropTable', $primaryTableName); $this->_sm->createTable($offlinePrimaryTable); $this->_sm->createTable($offlineForeignTable); $onlinePrimaryTable = $this->_sm->listTableDetails($primaryTableName); $onlineForeignTable = $this->_sm->listTableDetails($foreignTableName); $platform = $this->_sm->getDatabasePlatform(); // Primary table assertions $this->assertSame($primaryTableName, $onlinePrimaryTable->getQuotedName($platform)); $this->assertTrue($onlinePrimaryTable->hasColumn('"Id"')); $this->assertSame('"Id"', $onlinePrimaryTable->getColumn('"Id"')->getQuotedName($platform)); $this->assertTrue($onlinePrimaryTable->hasPrimaryKey()); $this->assertSame(array('"Id"'), $onlinePrimaryTable->getPrimaryKey()->getQuotedColumns($platform)); $this->assertTrue($onlinePrimaryTable->hasColumn('select')); $this->assertSame('"select"', $onlinePrimaryTable->getColumn('select')->getQuotedName($platform)); $this->assertTrue($onlinePrimaryTable->hasColumn('foo')); $this->assertSame('FOO', $onlinePrimaryTable->getColumn('foo')->getQuotedName($platform)); $this->assertTrue($onlinePrimaryTable->hasColumn('BAR')); $this->assertSame('BAR', $onlinePrimaryTable->getColumn('BAR')->getQuotedName($platform)); $this->assertTrue($onlinePrimaryTable->hasColumn('"BAZ"')); $this->assertSame('BAZ', $onlinePrimaryTable->getColumn('"BAZ"')->getQuotedName($platform)); $this->assertTrue($onlinePrimaryTable->hasIndex('from')); $this->assertTrue($onlinePrimaryTable->getIndex('from')->hasColumnAtPosition('"select"')); $this->assertSame(array('"select"'), $onlinePrimaryTable->getIndex('from')->getQuotedColumns($platform)); $this->assertTrue($onlinePrimaryTable->hasIndex('foo_index')); $this->assertTrue($onlinePrimaryTable->getIndex('foo_index')->hasColumnAtPosition('foo')); $this->assertSame(array('FOO'), $onlinePrimaryTable->getIndex('foo_index')->getQuotedColumns($platform)); $this->assertTrue($onlinePrimaryTable->hasIndex('BAR_INDEX')); $this->assertTrue($onlinePrimaryTable->getIndex('BAR_INDEX')->hasColumnAtPosition('BAR')); $this->assertSame(array('BAR'), $onlinePrimaryTable->getIndex('BAR_INDEX')->getQuotedColumns($platform)); $this->assertTrue($onlinePrimaryTable->hasIndex('BAZ_INDEX')); $this->assertTrue($onlinePrimaryTable->getIndex('BAZ_INDEX')->hasColumnAtPosition('"BAZ"')); $this->assertSame(array('BAZ'), $onlinePrimaryTable->getIndex('BAZ_INDEX')->getQuotedColumns($platform)); // Foreign table assertions $this->assertTrue($onlineForeignTable->hasColumn('id')); $this->assertSame('ID', $onlineForeignTable->getColumn('id')->getQuotedName($platform)); $this->assertTrue($onlineForeignTable->hasPrimaryKey()); $this->assertSame(array('ID'), $onlineForeignTable->getPrimaryKey()->getQuotedColumns($platform)); $this->assertTrue($onlineForeignTable->hasColumn('"Fk"')); $this->assertSame('"Fk"', $onlineForeignTable->getColumn('"Fk"')->getQuotedName($platform)); $this->assertTrue($onlineForeignTable->hasIndex('"Fk_index"')); $this->assertTrue($onlineForeignTable->getIndex('"Fk_index"')->hasColumnAtPosition('"Fk"')); $this->assertSame(array('"Fk"'), $onlineForeignTable->getIndex('"Fk_index"')->getQuotedColumns($platform)); $this->assertTrue($onlineForeignTable->hasForeignKey('"Primary_Table_Fk"')); $this->assertSame($primaryTableName, $onlineForeignTable->getForeignKey('"Primary_Table_Fk"')->getQuotedForeignTableName($platform)); $this->assertSame(array('"Fk"'), $onlineForeignTable->getForeignKey('"Primary_Table_Fk"')->getQuotedLocalColumns($platform)); $this->assertSame(array('"Id"'), $onlineForeignTable->getForeignKey('"Primary_Table_Fk"')->getQuotedForeignColumns($platform)); }
/** * @param \Doctrine\DBAL\Schema\Table $table * @param \SimpleXMLElement $xml * @throws \DomainException */ private function loadIndex($table, $xml) { $name = null; $fields = array(); foreach ($xml->children() as $child) { /** * @var \SimpleXMLElement $child */ switch ($child->getName()) { case 'name': $name = (string) $child; break; case 'primary': $primary = $this->asBool($child); break; case 'unique': $unique = $this->asBool($child); break; case 'field': foreach ($child->children() as $field) { /** * @var \SimpleXMLElement $field */ switch ($field->getName()) { case 'name': $field_name = (string) $field; $field_name = $this->platform->quoteIdentifier($field_name); $fields[] = $field_name; break; case 'sorting': break; default: throw new \DomainException('Unknown element: ' . $field->getName()); } } break; default: throw new \DomainException('Unknown element: ' . $child->getName()); } } if (!empty($fields)) { if (isset($primary) && $primary) { $table->setPrimaryKey($fields, $name); } else { if (isset($unique) && $unique) { $table->addUniqueIndex($fields, $name); } else { $table->addIndex($fields, $name); } } } else { throw new \DomainException('Empty index definition: ' . $name . ' options:' . print_r($fields, true)); } }
/** * @group DBAL-1033 */ public function testPartialIndexes() { $offlineTable = new Schema\Table('person'); $offlineTable->addColumn('id', 'integer'); $offlineTable->addColumn('name', 'string'); $offlineTable->addColumn('email', 'string'); $offlineTable->addUniqueIndex(array('id', 'name'), 'simple_partial_index', array('where' => '(id IS NULL)')); $offlineTable->addIndex(array('id', 'name'), 'complex_partial_index', array(), array('where' => '(((id IS NOT NULL) AND (name IS NULL)) AND (email IS NULL))')); $this->_sm->dropAndCreateTable($offlineTable); $onlineTable = $this->_sm->listTableDetails('person'); $comparator = new Schema\Comparator(); $this->assertFalse($comparator->diffTable($offlineTable, $onlineTable)); $this->assertTrue($onlineTable->hasIndex('simple_partial_index')); $this->assertTrue($onlineTable->hasIndex('complex_partial_index')); $this->assertTrue($onlineTable->getIndex('simple_partial_index')->hasOption('where')); $this->assertTrue($onlineTable->getIndex('complex_partial_index')->hasOption('where')); $this->assertSame('(id IS NULL)', $onlineTable->getIndex('simple_partial_index')->getOption('where')); $this->assertSame('(((id IS NOT NULL) AND (name IS NULL)) AND (email IS NULL))', $onlineTable->getIndex('complex_partial_index')->getOption('where')); }
/** * You can easily have ambiguities in the index renaming. If these * are detected no renaming should take place, instead adding and dropping * should be used exclusively. * * @group DBAL-1063 */ public function testDetectRenameIndexAmbiguous() { $table1 = new Table('foo'); $table1->addColumn('foo', 'integer'); $table2 = clone $table1; $table1->addIndex(array('foo'), 'idx_foo'); $table1->addIndex(array('foo'), 'idx_bar'); $table2->addIndex(array('foo'), 'idx_baz'); $comparator = new Comparator(); $tableDiff = $comparator->diffTable($table1, $table2); $this->assertCount(1, $tableDiff->addedIndexes); $this->assertArrayHasKey('idx_baz', $tableDiff->addedIndexes); $this->assertCount(2, $tableDiff->removedIndexes); $this->assertArrayHasKey('idx_foo', $tableDiff->removedIndexes); $this->assertArrayHasKey('idx_bar', $tableDiff->removedIndexes); $this->assertCount(0, $tableDiff->renamedIndexes); }
protected static function parseIndex(Schema $schema, Table $table, SimpleXMLElement $xIndex, AbstractPlatform $platform) { $s = (string) $xIndex['name']; $indexName = $s === '' ? null : $s; $fieldNames = array(); foreach ($xIndex->col as $col) { $fieldNames[] = (string) $col; } if (isset($xIndex->unique)) { $table->addUniqueIndex($fieldNames, $indexName); } else { $flags = array(); if (isset($xIndex->fulltext)) { $flags[] = 'FULLTEXT'; } $table->addIndex($fieldNames, $indexName, $flags); } }
/** * Specify an index for the table. * * @param string|array $columns * @param string $name * @param array $flags * @param array $options * * @return Blueprint */ public function index($columns, $name = null, $flags = [], $options = []) { $columns = is_array($columns) ? $columns : [$columns]; return $this->table->addIndex($columns, $name, $flags, $options); }
/** * @group DBAL-374 */ public function testQuotedColumnInIndexPropagation() { $this->markTestSkipped('requires big refactoring of Platforms'); $table = new Table('`quoted`'); $table->addColumn('`key`', 'string'); $table->addIndex(array('key')); $sql = $this->_platform->getCreateTableSQL($table); $this->assertEquals($this->getQuotedColumnInIndexSQL(), $sql); }
public function testGeneratesCreateTableSQLWithCommonIndexes() { $table = new Table('test'); $table->addColumn('id', 'integer'); $table->addColumn('name', 'string', array('length' => 50)); $table->setPrimaryKey(array('id')); $table->addIndex(array('name')); $table->addIndex(array('id', 'name'), 'composite_idx'); $this->assertEquals(array('CREATE TABLE test (id INT NOT NULL, name VARCHAR(50) NOT NULL, PRIMARY KEY (id))', 'CREATE INDEX IDX_D87F7E0C5E237E06 ON test (name)', 'CREATE INDEX composite_idx ON test (id, name)'), $this->_platform->getCreateTableSQL($table)); }
public function testAddIndexWithCaseSensitiveColumnProblem() { $table = new Table("foo"); $table->addColumn("id", 'integer'); $table->addIndex(array("ID"), "my_idx"); $this->assertTrue($table->hasIndex('my_idx')); $this->assertEquals(array("ID"), $table->getIndex("my_idx")->getColumns()); }
/** * Parses the index definition and adds it to the schema table. * * @param Table $table * @param string $keyName * @param string $sql */ private function parseIndexSql(Table $table, $keyName, $sql) { if ('PRIMARY' === $keyName) { if (!preg_match_all('/`([^`]+)`/', $sql, $matches)) { throw new \RuntimeException(sprintf('Primary key definition "%s" could not be parsed.', $sql)); } $table->setPrimaryKey($matches[1]); return; } if (!preg_match('/(.*) `([^`]+)` \\((.*)\\)/', $sql, $matches)) { throw new \RuntimeException(sprintf('Key definition "%s" could not be parsed.', $sql)); } $columns = []; $flags = []; foreach (explode(',', $matches[3]) as $column) { preg_match('/`([^`]+)`(\\((\\d+)\\))?/', $column, $cm); $column = $cm[1]; if (isset($cm[3])) { $column .= '(' . $cm[3] . ')'; } $columns[$cm[1]] = $column; } if (false !== strpos($matches[1], 'unique')) { $table->addUniqueIndex($columns, $matches[2]); } else { if (false !== strpos($matches[1], 'fulltext')) { $flags[] = 'fulltext'; } $table->addIndex($columns, $matches[2], $flags); } }
/** * @group DBAL-91 */ public function testAddIndexWithQuotedColumns() { $table = new Table("test"); $table->addColumn('"foo"', 'integer'); $table->addColumn('bar', 'integer'); $table->addIndex(array('"foo"', '"bar"')); }
/** * @param Metadata $metadata * @return Table */ public function metadataToTable(Metadata $metadata) { $tblName = $metadata->getDbTableName(); if (isset($this->md2tableCache[$tblName])) { return $this->md2tableCache[$tblName]; } $cols = []; foreach ($metadata->getLocalFields() as $fieldObj) { $col = $fieldObj->getDoctrineColumn(); $col->setLength($fieldObj->max_length); $col->setNotnull(!$fieldObj->null); $col->setComment($fieldObj->help_text); $col->setAutoincrement($fieldObj->auto_increment); $cols[] = $col; } $table = new Table($tblName, $cols); $this->md2tableCache[$tblName] = $table; foreach ($metadata->getLocalFields() as $fieldObj) { if ($fieldObj->unique) { $table->addUniqueIndex([$fieldObj->db_column]); } elseif ($fieldObj->db_index) { $table->addIndex([$fieldObj->db_column]); } if ($fieldObj->primary_key) { $table->setPrimaryKey([$fieldObj->db_column]); } if ($this->followRelations === true && $fieldObj instanceof ForeignKey) { $relationClass = $fieldObj->relationClass; $relationTable = $this->metadataToTable($relationClass::metadata()); $table->addForeignKeyConstraint($relationTable, [$fieldObj->db_column], [$fieldObj->to_field]); $this->generateQueue[] = $relationClass; } } if ($this->followRelations === true) { foreach ($metadata->getRelationFields() as $fieldObj) { if ($fieldObj instanceof ManyToMany) { if ($fieldObj->throughClass) { $throughClass = $fieldObj->throughClass; //$this->metadataToTable($throughClass::metadata()); $this->generateQueue[] = $throughClass; } } } } return $table; }
public function testCompareIndexBasedOnPropertiesNotName() { $tableA = new Table("foo"); $tableA->addColumn('id', 'integer'); $tableA->addIndex(array("id"), "foo_bar_idx"); $tableB = new Table("foo"); $tableB->addColumn('ID', 'integer'); $tableB->addIndex(array("id"), "bar_foo_idx"); $c = new Comparator(); $tableDiff = $c->diffTable($tableA, $tableB); $this->assertFalse($tableDiff); }
/** * @dataProvider getNormalizesAssetNames * @group DBAL-831 */ public function testNormalizesColumnNames($assetName) { $table = new Table('test'); $table->addColumn($assetName, 'integer'); $table->addIndex(array($assetName), $assetName); $table->addForeignKeyConstraint('test', array($assetName), array($assetName), array(), $assetName); $this->assertTrue($table->hasColumn($assetName)); $this->assertTrue($table->hasColumn('foo')); $this->assertInstanceOf('Doctrine\\DBAL\\Schema\\Column', $table->getColumn($assetName)); $this->assertInstanceOf('Doctrine\\DBAL\\Schema\\Column', $table->getColumn('foo')); $this->assertTrue($table->hasIndex($assetName)); $this->assertTrue($table->hasIndex('foo')); $this->assertInstanceOf('Doctrine\\DBAL\\Schema\\Index', $table->getIndex($assetName)); $this->assertInstanceOf('Doctrine\\DBAL\\Schema\\Index', $table->getIndex('foo')); $this->assertTrue($table->hasForeignKey($assetName)); $this->assertTrue($table->hasForeignKey('foo')); $this->assertInstanceOf('Doctrine\\DBAL\\Schema\\ForeignKeyConstraint', $table->getForeignKey($assetName)); $this->assertInstanceOf('Doctrine\\DBAL\\Schema\\ForeignKeyConstraint', $table->getForeignKey('foo')); $table->renameIndex($assetName, $assetName); $this->assertTrue($table->hasIndex($assetName)); $this->assertTrue($table->hasIndex('foo')); $table->renameIndex($assetName, 'foo'); $this->assertTrue($table->hasIndex($assetName)); $this->assertTrue($table->hasIndex('foo')); $table->renameIndex('foo', $assetName); $this->assertTrue($table->hasIndex($assetName)); $this->assertTrue($table->hasIndex('foo')); $table->renameIndex($assetName, 'bar'); $this->assertFalse($table->hasIndex($assetName)); $this->assertFalse($table->hasIndex('foo')); $this->assertTrue($table->hasIndex('bar')); $table->renameIndex('bar', $assetName); $table->dropColumn($assetName); $table->dropIndex($assetName); $table->removeForeignKey($assetName); $this->assertFalse($table->hasColumn($assetName)); $this->assertFalse($table->hasColumn('foo')); $this->assertFalse($table->hasIndex($assetName)); $this->assertFalse($table->hasIndex('foo')); $this->assertFalse($table->hasForeignKey($assetName)); $this->assertFalse($table->hasForeignKey('foo')); }