public function testCreateTableWithMultiPrimaryKey()
 {
     $table = new Table('test');
     $table->addColumn(new StringColumn('foo'));
     $table->addColumn(new StringColumn('bar'));
     $table->addConstraint(new PrimaryKey(array('foo', 'bar')));
     $this->getCreateTableCommand()->setTable($table)->execute();
     $this->assertTrue($this->tableExists('test'));
 }
Exemple #2
0
 public function testColumns()
 {
     $table = new Table('foo');
     $table->addColumn(new StringColumn('bar1'));
     $table->addColumn(new StringColumn('bar2'));
     $this->assertCount(2, $table->getColumns());
     $columns = $table->getColumns();
     $this->assertEquals('bar1', $columns[0]->getName());
     $this->assertEquals('bar2', $columns[1]->getName());
 }
Exemple #3
0
 /**
  * {@inheritdoc}
  */
 public function execute()
 {
     $columnTypeMapper = new ColumnTypeMapper();
     $this->preExecute();
     $columns = $this->connection->query($this->getSql());
     if (empty($columns)) {
         throw new TableNotExistsException($this->tableName);
     }
     $table = new Table($this->tableName);
     if (null === $table->getSchema()) {
         $table->setSchema($columns[0]['table_schema']);
     }
     $columnCreator = new ColumnCreator();
     foreach ($columns as $column) {
         $columnType = $columnTypeMapper->getCommon($column['data_type']);
         $options = array();
         $options['not_null'] = $column['is_nullable'] === 'NO';
         $options['default'] = $column['column_default'];
         if ($columnType === 'string') {
             preg_match("/'(.*)'::character varying/", $column['column_default'], $matches);
             $options['default'] = isset($matches[1]) ? $matches[1] : '';
             $options['limit'] = $column['character_maximum_length'];
         }
         $column = $columnCreator->create($column['column_name'], $columnType, $options);
         $table->addColumn($column);
     }
     $this->loadConstraints($table);
     $this->postExecute();
     return $table;
 }
Exemple #4
0
 protected function createTable($name, $columns = array())
 {
     $table = new Table($name);
     foreach ($columns as $column) {
         $table->addColumn($column);
     }
     $createTableCommand = new CreateTableCommand();
     $createTableCommand->setConnection($this->connection)->setEventDispatcher($this->getMock('Symfony\\Component\\EventDispatcher\\EventDispatcher'))->setTable($table)->execute();
 }
Exemple #5
0
 protected function setUp()
 {
     $table = new Table('foo');
     $table->addColumn(new IntegerColumn('bar_id'));
     $tableReferenced = new Table('bar');
     $this->foreignKey = new ForeignKey(new Table('foo'), new Table('bar'));
     $this->foreignKey->setColumns('bar_id');
     $this->foreignKey->setReferencedColumns('bar_id');
 }