Skip to content

Commit

Permalink
Render all attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
msmakouz committed Jan 24, 2024
1 parent 04cc037 commit 876ad43
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 11 deletions.
15 changes: 4 additions & 11 deletions src/Atomizer/Renderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ final class Renderer implements RendererInterface
*/
public const NEW_STATE = 0;
public const ORIGINAL_STATE = 1;
private const ALLOWED_ATTRIBUTES = ['scale', 'precision', 'unsigned', 'zerofill'];

public function createTable(Method $method, AbstractTable $table): void
{
Expand Down Expand Up @@ -245,26 +244,20 @@ private function columnOptions(AbstractColumn $column): array
{
$options = [
'nullable' => $column->isNullable(),
'default' => $column->getDefaultValue(),
'defaultValue' => $column->getDefaultValue(),
];

if ($column->getAbstractType() === 'enum') {
$options['values'] = $column->getEnumValues();
}

if ($column->getAbstractType() === 'string' || $column->getSize() > 0) {
$options['size'] = $column->getSize();
}

foreach ($column->getAttributes() as $attribute => $value) {
if (\in_array($attribute, self::ALLOWED_ATTRIBUTES, true)) {
$options[$attribute] = $value;
}
$options[$attribute] = $value;
}

$default = $options['default'];
$default = $options['defaultValue'];
if ($column::DATETIME_NOW === ($default instanceof \Stringable ? (string)$default : $default)) {
$options['default'] = AbstractColumn::DATETIME_NOW;
$options['defaultValue'] = AbstractColumn::DATETIME_NOW;
}

return $options;
Expand Down
5 changes: 5 additions & 0 deletions src/Operation/Column/Column.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,11 @@ protected function declareColumn(AbstractTable $schema): AbstractColumn
$column->nullable($this->getOption('nullable', false));
$column->setAttributes($this->options + $column->getAttributes());

if ($this->hasOption('defaultValue')) {
$column->defaultValue($this->getOption('defaultValue', null));
}

// @deprecated since v4.3
if ($this->hasOption('default')) {
$column->defaultValue($this->getOption('default', null));
}
Expand Down

0 comments on commit 876ad43

Please sign in to comment.