/** * {@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; }
public function testSchema() { $table = new Table('foo'); $table->setSchema(new Schema('bar')); $this->assertThat(new Schema('bar'), $this->logicalAnd($this->equalTo($table->getSchema()))); }