Пример #1
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;
 }
Пример #2
0
 public function testCreate()
 {
     $columnCreator = new ColumnCreator();
     $this->assertInstanceOf('Rentgen\\Database\\Column\\StringColumn', $columnCreator->create('foo', 'string'));
     $this->assertInstanceOf('Rentgen\\Database\\Column\\TextColumn', $columnCreator->create('foo', 'text'));
     $this->assertInstanceOf('Rentgen\\Database\\Column\\IntegerColumn', $columnCreator->create('foo', 'integer'));
     $this->assertInstanceOf('Rentgen\\Database\\Column\\BigIntegerColumn', $columnCreator->create('foo', 'biginteger'));
     $this->assertInstanceOf('Rentgen\\Database\\Column\\SmallIntegerColumn', $columnCreator->create('foo', 'smallinteger'));
     $this->assertInstanceOf('Rentgen\\Database\\Column\\FloatColumn', $columnCreator->create('foo', 'float'));
     $this->assertInstanceOf('Rentgen\\Database\\Column\\DecimalColumn', $columnCreator->create('foo', 'decimal'));
     $this->assertInstanceOf('Rentgen\\Database\\Column\\BooleanColumn', $columnCreator->create('foo', 'boolean'));
     $this->assertInstanceOf('Rentgen\\Database\\Column\\DateColumn', $columnCreator->create('foo', 'date'));
     $this->assertInstanceOf('Rentgen\\Database\\Column\\TimeColumn', $columnCreator->create('foo', 'time'));
     $this->assertInstanceOf('Rentgen\\Database\\Column\\DateTimeColumn', $columnCreator->create('foo', 'datetime'));
     $this->assertInstanceOf('Rentgen\\Database\\Column\\BinaryColumn', $columnCreator->create('foo', 'binary'));
 }