/** * Convert field description results into schema fields. * * @param TableSchema $table The table object to append fields to. * @param array $row The row data from `describeColumnSql`. * @return void */ public function convertColumnDescription(TableSchema $table, $row) { $field = $this->_convertColumn($row['type'], $row['char_length'], $row['precision'], $row['scale']); if (!empty($row['default'])) { $row['default'] = trim($row['default'], '()'); } if (!empty($row['autoincrement'])) { $field['autoIncrement'] = true; } if ($field['type'] === 'boolean') { $row['default'] = (int) $row['default']; } $field += ['null' => $row['null'] === '1' ? true : false, 'default' => $row['default']]; $table->addColumn($row['name'], $field); }
/** * Convert field description results into schema fields. * * @param TableSchema $table The table object to append fields to. * @param array $row The row data from `describeColumnSql`. * @return void */ public function convertColumnDescription(TableSchema $table, $row) { $field = $this->_convertColumn($row['type']); if ($field['type'] === 'boolean') { if ($row['default'] === 'true') { $row['default'] = 1; } if ($row['default'] === 'false') { $row['default'] = 0; } } if (!empty($row['has_serial'])) { $field['autoIncrement'] = true; } $field += ['default' => $this->_defaultValue($row['default']), 'null' => $row['null'] === 'YES' ? true : false, 'comment' => $row['comment']]; $field['length'] = $row['char_length'] ?: $field['length']; $table->addColumn($row['name'], $field); }
/** * Convert field description results into schema fields. * * @param TableSchema $table The table object to append fields to. * @param array $row The row data from `describeColumnSql`. * @return void */ public function convertColumnDescription(TableSchema $table, $row) { $field = $this->_convertColumn($row['Type']); $field += ['null' => $row['Null'] === 'YES' ? true : false, 'default' => $row['Default'], 'collate' => $row['Collation'], 'comment' => $row['Comment']]; if (isset($row['Extra']) && $row['Extra'] === 'auto_increment') { $field['autoIncrement'] = true; } $table->addColumn($row['Field'], $field); }
/** * Convert field description results into schema fields. * * @param TableSchema $table The table object to append fields to. * @param array $row The row data from `describeColumnSql`. * @return void */ public function convertColumnDescription(TableSchema $table, $row) { $field = $this->_convertColumn($row['type']); $field += ['null' => !$row['notnull'], 'default' => $row['dflt_value'] === null ? null : trim($row['dflt_value'], "'")]; $primary = $table->constraint('primary'); if ($row['pk'] && empty($primary)) { $field['null'] = false; $field['autoIncrement'] = true; } // SQLite does not support autoincrement on composite keys. if ($row['pk'] && !empty($primary)) { $existingColumn = $primary['columns'][0]; $table->addColumn($existingColumn, ['autoIncrement' => null] + $table->column($existingColumn)); } $table->addColumn($row['name'], $field); if ($row['pk']) { $constraint = (array) $table->constraint('primary') + ['type' => TableSchema::CONSTRAINT_PRIMARY, 'columns' => []]; $constraint['columns'] = array_merge($constraint['columns'], [$row['name']]); $table->addConstraint('primary', $constraint); } }