protected function createTestTable($name = 'test_table', $data = array())
 {
     $options = array();
     if (isset($data['options'])) {
         $options = $data['options'];
     }
     $table = $this->getTestTable($name, $options);
     $this->_sm->dropAndCreateTable($table);
 }
Esempio n. 2
0
 public function testCreateYamlWithForeignKeyFromDatabase()
 {
     if (!$this->_em->getConnection()->getDatabasePlatform()->supportsForeignKeyConstraints()) {
         $this->markTestSkipped('Platform does not support foreign keys.');
     }
     $tableB = new \Doctrine\DBAL\Schema\Table("dbdriver_bar");
     $tableB->addColumn('id', 'integer');
     $tableB->setPrimaryKey(array('id'));
     $this->_sm->dropAndCreateTable($tableB);
     $tableA = new \Doctrine\DBAL\Schema\Table("dbdriver_baz");
     $tableA->addColumn('id', 'integer');
     $tableA->setPrimaryKey(array('id'));
     $tableA->addColumn('bar_id', 'integer');
     $tableA->addForeignKeyConstraint('dbdriver_bar', array('bar_id'), array('id'));
     $this->_sm->dropAndCreateTable($tableA);
     $metadata = $this->extractClassMetadata("DbdriverBaz");
     $this->assertArrayNotHasKey('bar', $metadata->fieldMappings);
     $this->assertArrayHasKey('id', $metadata->fieldMappings);
     $metadata->associationMappings = \array_change_key_case($metadata->associationMappings, \CASE_LOWER);
     $this->assertArrayHasKey('bar', $metadata->associationMappings);
     $this->assertType('Doctrine\\ORM\\Mapping\\OneToOneMapping', $metadata->associationMappings['bar']);
 }
 public function testLoadMetadataWithForeignKeyFromDatabase()
 {
     if (!$this->_em->getConnection()->getDatabasePlatform()->supportsForeignKeyConstraints()) {
         $this->markTestSkipped('Platform does not support foreign keys.');
     }
     $tableB = new \Doctrine\DBAL\Schema\Table("dbdriver_bar");
     $tableB->addColumn('id', 'integer');
     $tableB->setPrimaryKey(array('id'));
     $this->_sm->dropAndCreateTable($tableB);
     $tableA = new \Doctrine\DBAL\Schema\Table("dbdriver_baz");
     $tableA->addColumn('id', 'integer');
     $tableA->setPrimaryKey(array('id'));
     $tableA->addColumn('bar_id', 'integer');
     $tableA->addForeignKeyConstraint('dbdriver_bar', array('bar_id'), array('id'));
     $this->_sm->dropAndCreateTable($tableA);
     $metadatas = $this->extractClassMetadata(array("DbdriverBar", "DbdriverBaz"));
     $this->assertArrayHasKey('DbdriverBaz', $metadatas);
     $bazMetadata = $metadatas['DbdriverBaz'];
     $this->assertArrayNotHasKey('barId', $bazMetadata->fieldMappings, "The foreign Key field should not be inflected as 'barId' field, its an association.");
     $this->assertArrayHasKey('id', $bazMetadata->fieldMappings);
     $bazMetadata->associationMappings = \array_change_key_case($bazMetadata->associationMappings, \CASE_LOWER);
     $this->assertArrayHasKey('bar', $bazMetadata->associationMappings);
     $this->assertEquals(ClassMetadataInfo::MANY_TO_ONE, $bazMetadata->associationMappings['bar']['type']);
 }
Esempio n. 4
0
 public function testLoadMetadataFromDatabaseDetail()
 {
     if (!$this->_em->getConnection()->getDatabasePlatform()->supportsForeignKeyConstraints()) {
         $this->markTestSkipped('Platform does not support foreign keys.');
     }
     $table = new \Doctrine\DBAL\Schema\Table("dbdriver_foo");
     $table->addColumn('id', 'integer', array('unsigned' => true));
     $table->setPrimaryKey(array('id'));
     $table->addColumn('column_unsigned', 'integer', array('unsigned' => true));
     $table->addColumn('column_comment', 'string', array('comment' => 'test_comment'));
     $table->addColumn('column_default', 'string', array('default' => 'test_default'));
     $table->addColumn('column_decimal', 'decimal', array('precision' => 4, 'scale' => 3));
     $table->addColumn('column_index1', 'string');
     $table->addColumn('column_index2', 'string');
     $table->addIndex(array('column_index1', 'column_index2'), 'index1');
     $table->addColumn('column_unique_index1', 'string');
     $table->addColumn('column_unique_index2', 'string');
     $table->addUniqueIndex(array('column_unique_index1', 'column_unique_index2'), 'unique_index1');
     $this->_sm->dropAndCreateTable($table);
     $metadatas = $this->extractClassMetadata(array("DbdriverFoo"));
     $this->assertArrayHasKey('DbdriverFoo', $metadatas);
     $metadata = $metadatas['DbdriverFoo'];
     $this->assertArrayHasKey('id', $metadata->fieldMappings);
     $this->assertEquals('id', $metadata->fieldMappings['id']['fieldName']);
     $this->assertEquals('id', strtolower($metadata->fieldMappings['id']['columnName']));
     $this->assertEquals('integer', (string) $metadata->fieldMappings['id']['type']);
     // FIXME: Condition here is fugly.
     // NOTE: PostgreSQL and SQL SERVER do not support UNSIGNED integer
     if (!$this->_em->getConnection()->getDatabasePlatform() instanceof PostgreSqlPlatform and !$this->_em->getConnection()->getDatabasePlatform() instanceof SQLServerPlatform) {
         $this->assertArrayHasKey('columnUnsigned', $metadata->fieldMappings);
         $this->assertTrue($metadata->fieldMappings['columnUnsigned']['options']['unsigned']);
     }
     $this->assertArrayHasKey('columnComment', $metadata->fieldMappings);
     $this->assertEquals('test_comment', $metadata->fieldMappings['columnComment']['options']['comment']);
     $this->assertArrayHasKey('columnDefault', $metadata->fieldMappings);
     $this->assertEquals('test_default', $metadata->fieldMappings['columnDefault']['options']['default']);
     $this->assertArrayHasKey('columnDecimal', $metadata->fieldMappings);
     $this->assertEquals(4, $metadata->fieldMappings['columnDecimal']['precision']);
     $this->assertEquals(3, $metadata->fieldMappings['columnDecimal']['scale']);
     $this->assertTrue(!empty($metadata->table['indexes']['index1']['columns']));
     $this->assertEquals(array('column_index1', 'column_index2'), $metadata->table['indexes']['index1']['columns']);
     $this->assertTrue(!empty($metadata->table['uniqueConstraints']['unique_index1']['columns']));
     $this->assertEquals(array('column_unique_index1', 'column_unique_index2'), $metadata->table['uniqueConstraints']['unique_index1']['columns']);
 }
 /**
  * @group DBAL-1095
  */
 public function testDoesNotListIndexesImplicitlyCreatedByForeignKeys()
 {
     if (!$this->_sm->getDatabasePlatform()->supportsForeignKeyConstraints()) {
         $this->markTestSkipped('This test is only supported on platforms that have foreign keys.');
     }
     $primaryTable = new Table('test_list_index_implicit_primary');
     $primaryTable->addColumn('id', 'integer');
     $primaryTable->setPrimaryKey(array('id'));
     $foreignTable = new Table('test_list_index_implicit_foreign');
     $foreignTable->addColumn('fk1', 'integer');
     $foreignTable->addColumn('fk2', 'integer');
     $foreignTable->addIndex(array('fk1'), 'explicit_fk1_idx');
     $foreignTable->addForeignKeyConstraint('test_list_index_implicit_primary', array('fk1'), array('id'));
     $foreignTable->addForeignKeyConstraint('test_list_index_implicit_primary', array('fk2'), array('id'));
     $this->_sm->dropAndCreateTable($primaryTable);
     $this->_sm->dropAndCreateTable($foreignTable);
     $indexes = $this->_sm->listTableIndexes('test_list_index_implicit_foreign');
     $this->assertCount(2, $indexes);
     $this->assertArrayHasKey('explicit_fk1_idx', $indexes);
     $this->assertArrayHasKey('idx_6d88c7b4fdc58d6c', $indexes);
 }
 /**
  * @group DBAL-44
  */
 public function testColumnDefaultLifecycle()
 {
     $table = new Table("col_def_lifecycle");
     $table->addColumn('id', 'integer', array('primary' => true, 'autoincrement' => true));
     $table->addColumn('column1', 'string', array('default' => null));
     $table->addColumn('column2', 'string', array('default' => false));
     $table->addColumn('column3', 'string', array('default' => true));
     $table->addColumn('column4', 'string', array('default' => 0));
     $table->addColumn('column5', 'string', array('default' => ''));
     $table->addColumn('column6', 'string', array('default' => 'def'));
     $table->setPrimaryKey(array('id'));
     $this->_sm->dropAndCreateTable($table);
     $columns = $this->_sm->listTableColumns('col_def_lifecycle');
     $this->assertNull($columns['id']->getDefault());
     $this->assertNull($columns['column1']->getDefault());
     $this->assertSame('', $columns['column2']->getDefault());
     $this->assertSame('1', $columns['column3']->getDefault());
     $this->assertSame('0', $columns['column4']->getDefault());
     $this->assertSame('', $columns['column5']->getDefault());
     $this->assertSame('def', $columns['column6']->getDefault());
     $diffTable = clone $table;
     $diffTable->changeColumn('column1', array('default' => false));
     $diffTable->changeColumn('column2', array('default' => null));
     $diffTable->changeColumn('column3', array('default' => false));
     $diffTable->changeColumn('column4', array('default' => null));
     $diffTable->changeColumn('column5', array('default' => false));
     $diffTable->changeColumn('column6', array('default' => 666));
     $comparator = new Comparator();
     $this->_sm->alterTable($comparator->diffTable($table, $diffTable));
     $columns = $this->_sm->listTableColumns('col_def_lifecycle');
     $this->assertSame('', $columns['column1']->getDefault());
     $this->assertNull($columns['column2']->getDefault());
     $this->assertSame('', $columns['column3']->getDefault());
     $this->assertNull($columns['column4']->getDefault());
     $this->assertSame('', $columns['column5']->getDefault());
     $this->assertSame('666', $columns['column6']->getDefault());
 }
Esempio n. 7
0
 /**
  * {@see AbstractSchemaManager::dropAndCreateTable}
  */
 public function dropAndCreateTable(Table $table)
 {
     $this->manager->dropAndCreateTable($this->replacePrefix($table));
 }
Esempio n. 8
0
 /**
  * {@see AbstractSchemaManager::dropAndCreateTable}
  */
 public function dropAndCreateTable($table)
 {
     $this->manager->dropAndCreateTable($table);
 }